DBIx-Custom / t / common.t /
Newer Older
4656 lines | 152.123kb
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 DBIx::Cus...
Yuki Kimoto authored on 2012-01-25
248
test 'DBIx::Custom::Pool';
249
use DBIx::Custom::Pool;
250
$dbi = DBIx::Custom->connect;
251
eval { $dbi->execute("drop table $table1") };
252
$dbi->execute($create_table1);
253
$pool = DBIx::Custom::Pool->new;
254
$pool->count(3);
255
$pool->prepare(sub {
256
  DBIx::Custom->connect;
257
});
258
$dbi1 = $pool->get;
259
ok($dbi1);
260
$dbi2 = $pool->get;
261
ok($dbi1);
262
$dbi3 = $pool->get;
263
ok($dbi1);
264
eval {$pool->get};
265
like($@, qr/empty/);
266
$pool->back($dbi1);
267
undef $dbi1;
268
$dbi1 = $pool->get;
269
ok($dbi1);
270
$pool->back($dbi1);
271
eval { $pool->back($dbi1) };
272
like($@, qr/already/);
273

            
274

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
275
test 'execute reuse option';
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
276
eval { $dbi->execute("drop table $table1") };
277
$dbi->execute($create_table1);
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
278
$reuse = {};
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
279
for my $i (1 .. 2) {
cleanup
Yuki Kimoto authored on 2012-01-20
280
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, reuse => $reuse);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
281
}
282
$rows = $dbi->select(table => $table1)->all;
283
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-11-18
284
ok(keys %$reuse);
285
ok((keys %$reuse)[0] !~ /\?/);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
286

            
added test
Yuki Kimoto authored on 2011-08-16
287
# Get user table info
288
$dbi = DBIx::Custom->connect;
289
eval { $dbi->execute("drop table $table1") };
290
eval { $dbi->execute("drop table $table2") };
291
eval { $dbi->execute("drop table $table3") };
292
$dbi->execute($create_table1);
293
$dbi->execute($create_table2);
294
$dbi->execute($create_table3);
295
$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table);
296

            
cleanup test
Yuki Kimoto authored on 2011-08-15
297
# Create table
test cleanup
Yuki Kimoto authored on 2011-08-10
298
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
299
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
300
$dbi->execute($create_table1);
301
$model = $dbi->create_model(table => $table1);
302
$model->insert({$key1 => 1, $key2 => 2});
303
is_deeply($model->select->all, [{$key1 => 1, $key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-08-15
304

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
305
eval { $dbi->execute("drop table $table1") };
306
$dbi->execute($create_table1);
307
$model = $dbi->create_model(table => $table1);
308
$model->insert({$key1 => 1, $key2 => 2});
309
is_deeply($model->select($key1)->all, [{$key1 => 1}]);
310

            
cleanup test
Yuki Kimoto authored on 2011-08-15
311
test 'DBIx::Custom::Result test';
312
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
313
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
314
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
315
$source = "select $key1, $key2 from $table1";
316
$query = $dbi->create_query($source);
317
$result = $dbi->execute($query);
cleanup
Yuki Kimoto authored on 2011-08-15
318

            
cleanup test
Yuki Kimoto authored on 2011-08-15
319
@rows = ();
320
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
321
  push @rows, [@$row];
cleanup test
Yuki Kimoto authored on 2011-08-15
322
}
323
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
cleanup
Yuki Kimoto authored on 2011-08-15
324

            
cleanup test
Yuki Kimoto authored on 2011-08-15
325
$result = $dbi->execute($query);
326
@rows = ();
327
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
328
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
329
}
330
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
331

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
345
test 'Insert query return value';
346
$source = "insert into $table1 {insert_param $key1 $key2}";
347
$query = $dbi->execute($source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
348
$ret_val = $dbi->execute($query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
349
ok($ret_val);
test cleanup
Yuki Kimoto authored on 2011-08-10
350

            
cleanup test
Yuki Kimoto authored on 2011-08-15
351
test 'Direct query';
352
$dbi->delete_all(table => $table1);
353
$insert_source = "insert into $table1 {insert_param $key1 $key2}";
test cleanup
Yuki Kimoto authored on 2011-11-01
354
$dbi->execute($insert_source, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
355
$result = $dbi->execute("select * from $table1");
356
$rows = $result->all;
357
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
358

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
364
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
365
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
366
$insert_query->filter({$key1 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
367
$dbi->execute($insert_query, {$key1 => 1, $key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
368
$result = $dbi->execute("select * from $table1");
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
369
$rows = $result->filter({$key2 => 'three_times'})->all;
370
is_deeply($rows, [{$key1 => 2, $key2 => 6}], "filter fetch_filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
371

            
372
test 'Filter in';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
373
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
374
$insert_source  = "insert into $table1 {insert_param $key1 $key2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
375
$insert_query = $dbi->execute($insert_source, {}, query => 1);
test cleanup
Yuki Kimoto authored on 2011-11-01
376
$dbi->execute($insert_query, {$key1 => 2, $key2 => 4});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
377
$select_source = "select * from $table1 where {in $table1.$key1 2} and {in $table1.$key2 2}";
cleanup test
Yuki Kimoto authored on 2011-08-08
378
$select_query = $dbi->execute($select_source,{}, query => 1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
379
$select_query->filter({"$table1.$key1" => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
380
$result = $dbi->execute($select_query, {"$table1.$key1" => [1,5], "$table1.$key2" => [2,4]});
cleanup test
Yuki Kimoto authored on 2011-08-08
381
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
382
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-08
383

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
396
$source = "select * from $table1 where $key1 = :$key1 and {<> $key2} and {< $key3} and {> $key4} and {>= $key5}";
cleanup test
Yuki Kimoto authored on 2011-08-08
397
$query = $dbi->execute($source, {}, query => 1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
398
$result = $dbi->execute($query, {$key1 => 1, $key2 => 3, $key3 => 4, $key4 => 3, $key5 => 5});
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 tag1");
cleanup test
Yuki Kimoto authored on 2011-08-08
401

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
464
$source = "select * from $table1 where $key1 = :$table1.$key1 and $key2 = :$table1.$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
465
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
466
  $source,
467
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
468
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
cleanup test
Yuki Kimoto authored on 2011-08-08
469
);
470
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
471
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
472

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
473
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-08
474
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
475
$dbi->insert({$key1 => '2011-10-14 12:19:18', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
476
$source = "select * from $table1 where $key1 = '2011-10-14 12:19:18' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
477
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
478
  $source,
479
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
480
);
481

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
486
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
487
$dbi->insert({$key1 => 'a:b c:d', $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
488
$source = "select * from $table1 where $key1 = 'a\\:b c\\:d' and $key2 = :$key2";
cleanup test
Yuki Kimoto authored on 2011-08-08
489
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
490
  $source,
491
  {$key2 => 2},
cleanup test
Yuki Kimoto authored on 2011-08-08
492
);
493
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
494
is_deeply($rows, [{$key1 => 'a:b c:d', $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-08
495

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
503
test 'insert';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
504
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
505
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
506
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
507
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
508
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
509
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
510
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
511

            
added tests
Yuki Kimoto authored on 2011-11-01
512
eval { $dbi->execute("drop table $table1") };
513
$dbi->execute($create_table1);
514
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
515
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
516
$result = $dbi->execute("select * from $table1");
517
$rows   = $result->all;
518
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
519

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
520
$dbi->execute("delete from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
521
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
522
  twice       => sub { $_[0] * 2 },
523
  three_times => sub { $_[0] * 3 }
cleanup test
Yuki Kimoto authored on 2011-08-10
524
);
525
$dbi->default_bind_filter('twice');
test cleanup
Yuki Kimoto authored on 2011-11-01
526
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
cleanup test
Yuki Kimoto authored on 2011-08-15
527
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
528
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
529
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
530
$dbi->delete_all(table => $table1);
531
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
532
$result = $dbi->execute("select * from $table1");
533
$rows   = $result->all;
534
is_deeply($rows, [{$key1 => 2, $key2 => 4}], "filter");
cleanup test
Yuki Kimoto authored on 2011-08-10
535
$dbi->default_bind_filter(undef);
536

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
547
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
548
$dbi->execute($create_table_reserved);
cleanup test
Yuki Kimoto authored on 2011-08-10
549
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
test cleanup
Yuki Kimoto authored on 2011-11-01
550
$dbi->insert({select => 1}, table => 'table');
cleanup test
Yuki Kimoto authored on 2011-08-10
551
$result = $dbi->execute("select * from ${q}table$p");
cleanup test
Yuki Kimoto authored on 2011-08-10
552
$rows   = $result->all;
test cleanup
Yuki Kimoto authored on 2011-08-10
553
is_deeply($rows, [{select => 2, update => undef}], "reserved word");
cleanup test
Yuki Kimoto authored on 2011-08-10
554

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
555
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
556
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
557
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
558
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
559
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
560
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
561
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
562

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
563
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
564
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
565
$dbi->insert({$key1 => \"'1'", $key2 => 2}, table => $table1);
566
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
567
$result = $dbi->execute("select * from $table1");
cleanup test
Yuki Kimoto authored on 2011-08-10
568
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
569
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
cleanup test
Yuki Kimoto authored on 2011-08-10
570

            
updated pod
Yuki Kimoto authored on 2011-09-02
571
eval { $dbi->execute("drop table $table1") };
572
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
573
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
574
wrap => {$key1 => sub { "$_[0] - 1" }});
test cleanup
Yuki Kimoto authored on 2011-11-01
575
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
updated pod
Yuki Kimoto authored on 2011-09-02
576
$result = $dbi->execute("select * from $table1");
577
$rows   = $result->all;
578
is_deeply($rows, [{$key1 => 0, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
579

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
580
eval { $dbi->execute("drop table $table1") };
581
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
582
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
583
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
584
);
test cleanup
Yuki Kimoto authored on 2011-11-01
585
$dbi->insert({$key2 => 2}, table => $table1, timestamp => 1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
586
$result = $dbi->execute("select * from $table1");
587
$rows   = $result->all;
588
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
589

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
590
eval { $dbi->execute("drop table $table1") };
591
$dbi->execute($create_table1);
592
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
593
  [$key1, $key2] => sub { 5 }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
594
);
595
$dbi->insert(table => $table1, timestamp => 1);
596
$result = $dbi->execute("select * from $table1");
597
$rows   = $result->all;
598
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
599

            
600
eval { $dbi->execute("drop table $table1") };
601
$dbi->execute($create_table1);
602
$dbi->insert_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
603
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
604
);
605
$dbi->insert(table => $table1, timestamp => 1);
606
$result = $dbi->execute("select * from $table1");
607
$rows   = $result->all;
608
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
609

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
642
eval { $dbi->execute("drop table $table1") };
643
$dbi->execute($create_table1_2);
644
$model = $dbi->create_model(table => $table1, created_at => $key2);
645
$param = {$key1 => 1};
646
$model->insert($param);
647
$result = $dbi->select(table => $table1);
648
is_deeply($param, {$key1 => 1});
649
$row   = $result->one;
650
is($row->{$key1}, 1);
651
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
652

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

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

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
677
eval { $dbi->execute("drop table $table1") };
678
$dbi->execute($create_table1);
679
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
680
$result = $dbi->execute("select * from $table1");
681
$rows   = $result->all;
682
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
683

            
684
eval { $dbi->execute("drop table $table1") };
685
$dbi->execute($create_table1_2);
686
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
687
table => $table1,
688
updated_at => $key2,
689
created_at => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
690
);
691
$result = $dbi->execute("select * from $table1");
692
$rows   = $result->all;
693
is($rows->[0]->{$key1}, 1);
694
is($rows->[1]->{$key1}, 3);
695
like($rows->[0]->{$key2}, qr/\d{2}:/);
696
like($rows->[1]->{$key2}, qr/\d{2}:/);
697
like($rows->[0]->{$key3}, qr/\d{2}:/);
698
like($rows->[1]->{$key3}, qr/\d{2}:/);
699

            
700
eval { $dbi->execute("drop table $table1") };
701
$dbi->execute($create_table1);
702
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
703
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
704
$result = $dbi->execute("select * from $table1");
705
$rows   = $result->all;
706
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
707

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
708
test 'update_or_insert';
709
eval { $dbi->execute("drop table $table1") };
710
$dbi->execute($create_table1);
711
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
712
  {$key2 => 2},
713
  table => $table1,
714
  primary_key => $key1,
715
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
716
);
717
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
718
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
719

            
720
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
721
  {$key2 => 3},
722
  table => $table1,
723
  primary_key => $key1,
724
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
725
);
726
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
727
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
728

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
729
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
730
  $dbi->update_or_insert(
731
    {$key2 => 3},
732
    table => $table1,
733
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
734
};
735

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
738
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
739
  $dbi->insert({$key1 => 1}, table => $table1);
740
  $dbi->update_or_insert(
741
    {$key2 => 3},
742
    table => $table1,
743
    primary_key => $key1,
744
    id => 1
745
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
746
};
747
like($@, qr/one/);
748

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
749
eval { $dbi->execute("drop table $table1") };
750
$dbi->execute($create_table1);
751
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
752
  {},
753
  table => $table1,
754
  primary_key => $key1,
755
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
756
);
757
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
758
is($row->{$key1}, 1);
759

            
760
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
761
  $affected = $dbi->update_or_insert(
762
    {},
763
    table => $table1,
764
    primary_key => $key1,
765
    id => 1
766
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
767
};
768
is($affected, 0);
769

            
micro optimization
Yuki Kimoto authored on 2011-10-31
770
test 'model update_or_insert';
771
eval { $dbi->execute("drop table $table1") };
772
$dbi->execute($create_table1);
773
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
774
  table => $table1,
775
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
776
);
777
$model->update_or_insert({$key2 => 2}, id => 1);
778
$row = $model->select(id => 1)->one;
779
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
780

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
781
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
782
  $model->insert({$key1 => 1});
783
  $model->update_or_insert(
784
    {$key2 => 3},
785
    id => 1
786
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
787
};
788
like($@, qr/one/);
789

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
790
test 'default_bind_filter';
791
$dbi->execute("delete from $table1");
792
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
793
  twice       => sub { $_[0] * 2 },
794
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
795
);
796
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
797
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
798
$result = $dbi->execute("select * from $table1");
799
$rows   = $result->all;
800
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
801
$dbi->default_bind_filter(undef);
802

            
test cleanup
Yuki Kimoto authored on 2011-08-10
803
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
804
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
805
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
806
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
807
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
808
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
809
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
810
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
811
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
812
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
813
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
814

            
815
eval { $dbi->execute("drop table $table1") };
816
$dbi->execute($create_table1_2);
817
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
818
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
819
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
820
$result = $dbi->execute("select * from $table1 order by $key1");
821
$rows   = $result->all;
822
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
823
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
824
  "basic");
825
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
826
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
827
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
828
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
829
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
830
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
831
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
832
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
833
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
834
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
835

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
843
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
844
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
845
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
846
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
847
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
848
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
849
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
850
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
851
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
852
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
853
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
854

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
860
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
861
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
862
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
863
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
864
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
865
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
866
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
867
$result = $dbi->select(table => $table1);
868
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
869

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
870
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
871
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
872
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
873
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
874
  {$key1 => 3},
875
  table => $table1,
876
  where => [
877
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
878
    {$key1 => 1, $key2 => 2}
879
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
880
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
881
$result = $dbi->select(table => $table1);
882
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
883

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
884
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
885
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
886
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
887
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
888
$where->clause(['and', "$key2 = :$key2"]);
889
$where->param({$key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
890
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
891
$result = $dbi->select(table => $table1);
892
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
893

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
900
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
901
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
902
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
903
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
904
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
905
$dbi->insert({select => 1}, table => 'table');
906
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
907
$result = $dbi->execute("select * from ${q}table$p");
908
$rows   = $result->all;
909
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
910

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

            
914
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
915
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
916
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
917
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
918
$dbi->insert({select => 1}, table => 'table');
919
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
920
$result = $dbi->execute("select * from ${q}table$p");
921
$rows   = $result->all;
922
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
923

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
924
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
925
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
926
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
927
$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
928
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
929
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
930
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
931
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
932
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
933
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
934

            
updated pod
Yuki Kimoto authored on 2011-09-02
935
eval { $dbi->execute("drop table $table1") };
936
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
937
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
938
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
939
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
940
wrap => {$key2 => sub { "$_[0] - 1" }});
941
$result = $dbi->execute("select * from $table1 order by $key1");
942
$rows   = $result->all;
943
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
944
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
945
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
946

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
947
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
948
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
949
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
950
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
951
$dbi->update({$key2 => \"'11'"}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
952
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
953
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
954
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
955
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
956
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
957

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
958
eval { $dbi->execute("drop table $table1") };
959
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
960
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
961
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
962
);
test cleanup
Yuki Kimoto authored on 2011-11-01
963
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
964
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
965
$result = $dbi->execute("select * from $table1");
966
$rows   = $result->all;
967
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
968

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
969
eval { $dbi->execute("drop table $table1") };
970
$dbi->execute($create_table1);
971
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
972
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
973
);
test cleanup
Yuki Kimoto authored on 2011-11-01
974
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
975
$dbi->update_all(table => $table1, timestamp => 1);
976
$result = $dbi->execute("select * from $table1");
977
$rows   = $result->all;
978
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
979

            
980
eval { $dbi->execute("drop table $table1") };
981
$dbi->execute($create_table1);
982
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
983
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
984
);
test cleanup
Yuki Kimoto authored on 2011-11-01
985
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
986
$dbi->update_all(table => $table1, timestamp => 1);
987
$result = $dbi->execute("select * from $table1");
988
$rows   = $result->all;
989
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
990

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
991
eval { $dbi->execute("drop table $table1") };
992
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
993
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
994
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
995
$param = {$key2 => 11};
996
$dbi->update($param, table => $table1, where => {$key1 => 1});
997
is_deeply($param, {$key2 => 11});
998
$result = $dbi->execute("select * from $table1 order by $key1");
999
$rows   = $result->all;
1000
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1001
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1002
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1003

            
1004
eval { $dbi->execute("drop table $table1") };
1005
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1006
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1007
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
1008
$param = {$key2 => 11};
1009
$dbi->update($param, table => $table1, where => {$key2 => 2});
1010
is_deeply($param, {$key2 => 11});
1011
$result = $dbi->execute("select * from $table1 order by $key1");
1012
$rows   = $result->all;
1013
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1014
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
1015
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
1016

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1017
eval { $dbi->execute("drop table $table1") };
1018
$dbi->execute($create_table1_2);
1019
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1020
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1021
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1022
$result = $dbi->select(table => $table1);
1023
is_deeply($param, {$key3 => 4});
1024
$row   = $result->one;
1025
is($row->{$key3}, 4);
1026
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1027

            
1028
eval { $dbi->execute("drop table $table1") };
1029
$dbi->execute($create_table1_2);
1030
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1031
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1032
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1033
$result = $dbi->select(table => $table1);
1034
is_deeply($param, {$key3 => 4});
1035
$row   = $result->one;
1036
is($row->{$key3}, 4);
1037
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1038

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1039
eval { $dbi->execute("drop table $table1") };
1040
$dbi->execute($create_table1_2);
1041
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1042
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1043
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1044
$model->update($param, where => {$key1 => 1});
1045
$result = $dbi->select(table => $table1);
1046
is_deeply($param, {$key3 => 4});
1047
$row   = $result->one;
1048
is($row->{$key3}, 4);
1049
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1050

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1051
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1052
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1053
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1054
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1055
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1056
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1057
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1058
$result = $dbi->execute("select * from $table1");
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 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1061
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1062
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1063

            
1064
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1065
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1066
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1067
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1068
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1069
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1070
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1071
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1072
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1073

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1074
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1075
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1076
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1077
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1078
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1079
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1080
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1081
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1082

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1085
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1086
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1087
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1088
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1089
$rows = $dbi->select(table => $table1)->all;
1090
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1091

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1092
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1093
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1094
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1095
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1096
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1097
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1098
$where->param({ke1 => 1, $key2 => 2});
1099
$dbi->delete(table => $table1, where => $where);
1100
$result = $dbi->select(table => $table1);
1101
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1102

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1103
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1104
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1105
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1106
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1107
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
1108
  table => $table1,
1109
  where => [
1110
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1111
    {ke1 => 1, $key2 => 2}
1112
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1113
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1114
$result = $dbi->select(table => $table1);
1115
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1116

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1117
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1118
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1119
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1120
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1121
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1122
$rows   = $result->all;
1123
is_deeply($rows, [], "basic");
1124

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1134
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1135
$dbi = DBIx::Custom->connect;
1136
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1137
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1138
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1139
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1140
$dbi->delete(table => 'table', where => {select => 1});
1141
$result = $dbi->execute("select * from ${q}table$p");
1142
$rows   = $result->all;
1143
is_deeply($rows, [], "reserved word");
1144

            
1145
test 'delete_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1146
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1147
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1148
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1149
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1150
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1151
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1152
$rows   = $result->all;
1153
is_deeply($rows, [], "basic");
1154

            
1155
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1156
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1157
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1158
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1159
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1160
$rows = $dbi->select(table => $table1)->all;
1161
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1162
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1163

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1178
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1179
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1180
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1181
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1182
  table => [$table1, $table2],
1183
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1184
  where   => {"$table1.$key2" => 2},
1185
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1186
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1187
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
1188

            
1189
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1190
  table => [$table1, $table2],
1191
  column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1192
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1193
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1194
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
1195

            
1196
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1197
eval { $dbi->execute("drop table ${q}table$p") };
1198
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1199
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1200
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1201
$result = $dbi->select(table => 'table', where => {select => 1});
1202
$rows   = $result->all;
1203
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1204

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1205
eval { $dbi->execute("drop table $table1") };
1206
$dbi->execute($create_table1);
1207
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1208
$row = $dbi->select($key1, table => $table1)->one;
1209
is_deeply($row, {$key1 => 1});
1210

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1211
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1212
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1214
  twice       => sub { $_[0] * 2 },
1215
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1216
);
1217
$dbi->default_fetch_filter('twice');
1218
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1219
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1220
$result = $dbi->select(table => $table1);
1221
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1222
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1223
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1224

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1225
$dbi->default_fetch_filter('twice');
1226
eval { $dbi->execute("drop table $table1") };
1227
$dbi->execute($create_table1);
1228
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1229
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1230
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1231
$row = $result->fetch_one;
1232
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1233

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1240
test 'filters';
1241
$dbi = DBIx::Custom->new;
1242

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1249
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1250
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1251
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1252
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1253
$dbi->begin_work;
1254
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1255
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1256
$dbi->rollback;
1257
$dbi->dbh->{AutoCommit} = 1;
1258

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

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

            
1263
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1264
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1265
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1266
$dbi->begin_work;
1267
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1268
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1269
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1270
$dbi->commit;
1271
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1272
$result = $dbi->select(table => $table1);
1273
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1274
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1275

            
1276
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1277
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
$dbi->execute($create_table1);
1279
{
cleanup
Yuki Kimoto authored on 2012-01-20
1280
  local $Carp::Verbose = 0;
1281
  eval{$dbi->execute("select * frm $table1")};
1282
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1283
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
}
1285
{
cleanup
Yuki Kimoto authored on 2012-01-20
1286
  local $Carp::Verbose = 1;
1287
  eval{$dbi->execute("select * frm $table1")};
1288
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1289
}
1290

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

            
1296
{
cleanup
Yuki Kimoto authored on 2012-01-20
1297
  local $Carp::Verbose = 0;
1298
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1299
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1300
}
1301
{
cleanup
Yuki Kimoto authored on 2012-01-20
1302
  local $Carp::Verbose = 1;
1303
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1304
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1305
}
1306

            
1307

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1308
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1309
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1310
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1311
$dbi->execute($create_table1);
1312

            
1313
$dbi->begin_work;
1314

            
1315
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1316
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1317
  die "Error";
1318
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1319
};
1320

            
1321
$dbi->rollback if $@;
1322

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

            
1327
$dbi->begin_work;
1328

            
1329
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1330
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1331
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
};
1333

            
1334
$dbi->commit unless $@;
1335

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

            
1340
$dbi->dbh->{AutoCommit} = 0;
1341
eval{ $dbi->begin_work };
1342
ok($@, "exception");
1343
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1344

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1345
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1346
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
$dbi->cache(1);
1348
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1349
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1350
$dbi->execute($source, {}, query => 1);
1351
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1352
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1353

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1354
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1355
$dbi->execute($create_table1);
1356
$dbi->{_cached} = {};
1357
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1358
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1359
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1360

            
1361
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1362
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1363
$dbi->execute($create_table1);
1364
{
cleanup
Yuki Kimoto authored on 2012-01-20
1365
  local $Carp::Verbose = 0;
1366
  eval{$dbi->execute("select * frm $table1")};
1367
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1368
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1369
}
1370
{
cleanup
Yuki Kimoto authored on 2012-01-20
1371
  local $Carp::Verbose = 1;
1372
  eval{$dbi->execute("select * frm $table1")};
1373
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1374
}
1375

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

            
1381
{
cleanup
Yuki Kimoto authored on 2012-01-20
1382
  local $Carp::Verbose = 0;
1383
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1384
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1385
}
1386
{
cleanup
Yuki Kimoto authored on 2012-01-20
1387
  local $Carp::Verbose = 1;
1388
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1389
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1390
}
1391

            
1392
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1393
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1394
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1395
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1396
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1397
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1398
);
1399
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1400
  twice => sub {
1401
    my $self = shift;
1402
    return $_[0] * 2;
1403
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1404
});
1405

            
1406
is($dbi->one, 1, "first");
1407
is($dbi->two, 2, "second");
1408
is($dbi->twice(5), 10 , "second");
1409

            
1410
eval {$dbi->XXXXXX};
1411
ok($@, "not exists");
1412

            
1413
test 'out filter';
1414
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1415
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1416
$dbi->execute($create_table1);
1417
$dbi->register_filter(twice => sub { $_[0] * 2 });
1418
$dbi->register_filter(three_times => sub { $_[0] * 3});
1419
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1420
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1421
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1422
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1423
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1424
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1425
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1426
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1427
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1428
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1429

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1435
$dbi = DBIx::Custom->connect;
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
$dbi->register_filter(twice => sub { $_[0] * 2 });
1439
$dbi->register_filter(three_times => sub { $_[0] * 3});
1440
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1441
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1442
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1444
  $table1, $key1 => {out => undef}
test cleanup
Yuki Kimoto authored on 2011-08-10
1445
); 
test cleanup
Yuki Kimoto authored on 2011-11-01
1446
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1447
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1448
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1449
is_deeply($row, {$key1 => 1, $key2 => 6}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1450

            
1451
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1452
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1453
$dbi->execute($create_table1);
1454
$dbi->register_filter(twice => sub { $_[0] * 2 });
1455
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1456
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1457
);
cleanup
Yuki Kimoto authored on 2011-11-01
1458
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1459
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1460
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1461
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1462
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1463

            
1464
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1465
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1466
$dbi->execute($create_table1);
1467
$dbi->register_filter(twice => sub { $_[0] * 2 });
1468
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1469
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1470
);
cleanup
Yuki Kimoto authored on 2011-11-01
1471
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1472
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1473
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1474
$rows   = $result->all;
1475
is_deeply($rows, [], "delete");
1476

            
1477
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1478
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1479
$dbi->execute($create_table1);
1480
$dbi->register_filter(twice => sub { $_[0] * 2 });
1481
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1482
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1483
);
cleanup
Yuki Kimoto authored on 2011-11-01
1484
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1485
$result = $dbi->select(table => $table1, where => {$key1 => 1});
1486
$result->filter({$key2 => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1487
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1488
is_deeply($rows, [{$key1 => 4, $key2 => 4}], "select");
test cleanup
Yuki Kimoto authored on 2011-08-10
1489

            
1490
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1491
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1492
$dbi->execute($create_table1);
1493
$dbi->register_filter(twice => sub { $_[0] * 2 });
1494
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1495
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1496
);
cleanup
Yuki Kimoto authored on 2011-11-01
1497
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1498
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1499
  {$key1 => 1, $key2 => 2},
1500
  table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1501
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1502
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
1503

            
1504
$dbi = DBIx::Custom->connect;
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->execute($create_table1);
1507
$dbi->register_filter(twice => sub { $_[0] * 2 });
1508
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1509
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1510
);
cleanup
Yuki Kimoto authored on 2011-11-01
1511
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1512
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1513
  {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1514
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1515
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute table tag");
test cleanup
Yuki Kimoto authored on 2011-08-10
1516

            
1517
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1518
eval { $dbi->execute("drop table $table1") };
1519
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1520
$dbi->execute($create_table1);
1521
$dbi->execute($create_table2);
1522
$dbi->register_filter(twice => sub { $_[0] * 2 });
1523
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1524
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1525
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1526
);
1527
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1528
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1529
);
cleanup
Yuki Kimoto authored on 2011-11-01
1530
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1531
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1532
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1533
  table => [$table1, $table2],
1534
  column => [$key2, $key3],
1535
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1536

            
1537
$result->filter({$key2 => 'twice'});
1538
$rows   = $result->all;
1539
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1540

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

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

            
1550
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1551
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1552
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1553
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1554
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1555
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1556

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1557
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1558
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1559
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1560
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1561
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1562
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1563

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

            
1570
test 'end_filter';
1571
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1572
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1573
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1574
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1575
$result = $dbi->select(table => $table1);
1576
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1577
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1578
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1579
is_deeply($row, [6, 40]);
1580

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1581
$dbi = DBIx::Custom->connect;
1582
eval { $dbi->execute("drop table $table1") };
1583
$dbi->execute($create_table1);
1584
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1585
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1586
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1587
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1588
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1589
is_deeply($row, [6, 6, 40]);
1590

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1591
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1592
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1593
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1594
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1595
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1596
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1597
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1598
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1599
is_deeply($row, [6, 12]);
1600

            
1601
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1602
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1603
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1604
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1606
$result->filter([[$key1, $key2] => sub { $_[0] * 2 }]);
1607
$result->end_filter([$key1, $key2] => sub { $_[0] * 3 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1608
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1609
is_deeply($row, [6, 12]);
1610

            
1611
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1612
$result = $dbi->select(table => $table1);
1613
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1614
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1615
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1616
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1617

            
1618
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1619
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1620
  $key1 => {end => sub { $_[0] * 3 } },
1621
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1622
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1623
$result = $dbi->select(table => $table1);
1624
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1625
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1626
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1627

            
1628
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1629
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1630
  $key1 => {end => sub { $_[0] * 3 } },
1631
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1632
);
1633
$result = $dbi->select(table => $table1);
1634
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1635
$result->filter($key1 => undef);
1636
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1638
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1639

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1640
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1641
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1642
$result->filter($key1 => undef);
1643
$result->end_filter($key1 => undef);
1644
$row = $result->fetch;
1645
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1646

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

            
1661
test 'empty where select';
1662
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1663
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1664
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1665
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1666
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1667
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1668
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1669

            
1670
test 'select query option';
1671
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1672
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1673
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1674
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1675
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1676
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1677
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1678
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1679
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1680
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1681
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1682

            
1683
test 'where';
1684
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1685
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1686
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1687
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1688
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1689
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1690
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1691

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

            
1696
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1697
  table => $table1,
1698
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1699
);
1700
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1701
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1702

            
1703
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1704
  table => $table1,
1705
  where => [
1706
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1707
    {$key1 => 1}
1708
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
);
1710
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1711
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1712

            
1713
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1714
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1715
  ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1716
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1717
  table => $table1,
1718
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1719
);
1720
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1721
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1722

            
1723
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1724
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1725
  ->param({});
test cleanup
Yuki Kimoto authored on 2011-08-10
1726
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1727
  table => $table1,
1728
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1729
);
1730
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1731
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1732

            
1733
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1734
  ->clause(['and', ['or', "$key1 > :$key1", "$key1 < :$key1"], "$key2 = :$key2"])
1735
  ->param({$key1 => [0, 3], $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1736
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1737
  table => $table1,
1738
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
); 
1740
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1741
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1742

            
1743
$where = $dbi->where;
1744
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1745
  table => $table1,
1746
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1747
);
1748
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1749
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1750

            
1751
eval {
1752
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1753
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1754
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1755
  table => $table1,
1756
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1757
);
1758
};
1759
ok($@);
1760

            
1761
$where = $dbi->where;
1762
is("$where", '');
1763

            
1764
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1765
  ->clause(['or', ("$key1 = :$key1") x 2])
1766
  ->param({$key1 => [1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1767
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1768
  table => $table1,
1769
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1770
);
1771
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1772
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1773

            
1774
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1775
   ->clause(['or', ("$key1 = :$key1") x 2])
1776
   ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1777
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1778
  table => $table1,
1779
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1780
);
1781
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1782
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1783

            
1784
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1785
  ->clause(['or', ("$key1 = :$key1") x 2])
1786
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1787
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1788
  table => $table1,
1789
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1790
);
1791
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1792
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1793

            
1794
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1795
  ->clause("$key1 = :$key1")
1796
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1797
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1798
  table => $table1,
1799
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1800
);
1801
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1802
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1803

            
1804
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1805
  ->clause(['or', ("$key1 = :$key1") x 3])
1806
  ->param({$key1 => [$dbi->not_exists, 1, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1807
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1808
  table => $table1,
1809
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1810
);
1811
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1812
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1813

            
1814
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1815
  ->clause(['or', ("$key1 = :$key1") x 3])
1816
  ->param({$key1 => [1, $dbi->not_exists, 3]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1817
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1818
  table => $table1,
1819
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1820
);
1821
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1822
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1823

            
1824
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1825
  ->clause(['or', ("$key1 = :$key1") x 3])
1826
  ->param({$key1 => [1, 3, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1828
  table => $table1,
1829
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1830
);
1831
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1832
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1833

            
1834
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1835
  ->clause(['or', ("$key1 = :$key1") x 3])
1836
  ->param({$key1 => [1, $dbi->not_exists, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1837
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1838
  table => $table1,
1839
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1840
);
1841
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1842
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1843

            
1844
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1845
  ->clause(['or', ("$key1 = :$key1") x 3])
1846
  ->param({$key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1847
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1848
  table => $table1,
1849
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1850
);
1851
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1852
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1853

            
1854
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1855
  ->clause(['or', ("$key1 = :$key1") x 3])
1856
  ->param({$key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1857
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1858
  table => $table1,
1859
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1860
);
1861
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1862
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1863

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

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

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

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

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

            
1914
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1915
  ->clause(['and', "{> $key1}", "{< $key1}" ])
1916
  ->param({$key1 => [0, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1917
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1918
  table => $table1,
1919
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1920
);
1921
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1922
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1923

            
1924
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1925
  ->clause(['and',"$key1 is not null", "$key2 is not null" ]);
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}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
1932

            
1933
eval {$dbi->where(ppp => 1) };
1934
like($@, qr/invalid/);
1935

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

            
1947

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

            
1959
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1960
$where->clause(['and', ":${key1}{=}"]);
1961
$where->param({$key1 => undef});
1962
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1963
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1964
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1965

            
1966
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1967
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
1968
$where->param({$key1 => [undef, undef]});
1969
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1970
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1971
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
1972
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1973
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1974
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1975

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

            
1977
$dbi = DBIx::Custom->connect;
1978
eval { $dbi->execute("drop table $table1") };
1979
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1980
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1981
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1982
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1983
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1984
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1985

            
1986
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1987
  table => $table1,
1988
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1989
);
1990
$row = $result->all;
1991
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1992

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1993
test 'register_tag_processor';
1994
$dbi = DBIx::Custom->connect;
1995
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
1996
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1997
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1998
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1999

            
2000
test 'register_tag';
2001
$dbi = DBIx::Custom->connect;
2002
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2003
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2004
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2005
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2006

            
2007
test 'table not specify exception';
2008
$dbi = DBIx::Custom->connect;
2009
eval {$dbi->select};
2010
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
2011

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2012
test 'more tests';
2013
$dbi = DBIx::Custom->connect;
2014
eval{$dbi->apply_filter('table', 'column', [])};
2015
like($@, qr/apply_filter/);
2016

            
2017
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2018
like($@, qr/apply_filter/);
2019

            
2020
$dbi->apply_filter(
2021

            
2022
);
2023
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2024
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2025
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2026
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2027
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2028
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2029
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2030
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2031
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2032

            
2033
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2034
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2035
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2036
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2037
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2038
$dbi->apply_filter($table1, $key2, {});
2039
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2040
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2041

            
2042
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2043
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2044
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2046
like($@, qr/not registered/);
2047
$dbi->method({one => sub { 1 }});
2048
is($dbi->one, 1);
2049

            
2050
eval{DBIx::Custom->connect(dsn => undef)};
2051
like($@, qr/_connect/);
2052

            
2053
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2054
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2055
$dbi->execute($create_table1);
2056
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2057
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2058
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2059
$row = $dbi->select(table => $table1)->one;
2060
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2061
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2062
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2063
like($@, qr//);
2064

            
2065
$dbi->register_filter(one => sub { });
2066
$dbi->default_fetch_filter('one');
2067
ok($dbi->default_fetch_filter);
2068
$dbi->default_bind_filter('one');
2069
ok($dbi->default_bind_filter);
2070
eval{$dbi->default_fetch_filter('no')};
2071
like($@, qr/not registered/);
2072
eval{$dbi->default_bind_filter('no')};
2073
like($@, qr/not registered/);
2074
$dbi->default_bind_filter(undef);
2075
ok(!defined $dbi->default_bind_filter);
2076
$dbi->default_fetch_filter(undef);
2077
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2078
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2079
like($@, qr/Tag not finished/);
2080

            
2081
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2082
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2083
$dbi->execute($create_table1);
2084
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2085
$result = $dbi->select(table => $table1);
2086
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2087
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2088
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2089
like($@, qr/not registered/);
2090
$result->default_filter(undef);
2091
ok(!defined $result->default_filter);
2092
$result->default_filter('one');
2093
is($result->default_filter->(), 1);
2094

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2095
test 'option';
2096
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2097
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2098
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2099
ok($dbi->dbh->{PrintError});
2100
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2101
ok($dbi->dbh->{PrintError});
2102

            
2103
test 'DBIx::Custom::Result stash()';
2104
$result = DBIx::Custom::Result->new;
2105
is_deeply($result->stash, {}, 'default');
2106
$result->stash->{foo} = 1;
2107
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2108

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2109
test 'delete_at';
2110
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2111
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2112
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2113
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2114
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2115
  table => $table1,
2116
  primary_key => [$key1, $key2],
2117
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2118
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2119
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2120

            
cleanup
Yuki Kimoto authored on 2011-11-01
2121
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2122
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2123
  table => $table1,
2124
  primary_key => $key1,
2125
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2126
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2127
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2128

            
2129
test 'insert_at';
2130
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2131
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2132
$dbi->execute($create_table1_2);
2133
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2134
  {$key3 => 3},
2135
  primary_key => [$key1, $key2], 
2136
  table => $table1,
2137
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2138
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2139
is($dbi->select(table => $table1)->one->{$key1}, 1);
2140
is($dbi->select(table => $table1)->one->{$key2}, 2);
2141
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2142

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2143
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2144
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2146
  {$key2 => 2, $key3 => 3},
2147
  primary_key => $key1, 
2148
  table => $table1,
2149
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2150
);
2151

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

            
2156
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2157
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2158
$dbi->execute($create_table1_2);
2159
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2160
  {$key3 => 3},
2161
  primary_key => [$key1, $key2], 
2162
  table => $table1,
2163
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2164
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2165
is($dbi->select(table => $table1)->one->{$key1}, 1);
2166
is($dbi->select(table => $table1)->one->{$key2}, 2);
2167
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2168

            
2169
test 'update_at';
2170
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2171
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2172
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2173
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2174
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2175
  {$key3 => 4},
2176
  table => $table1,
2177
  primary_key => [$key1, $key2],
2178
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2179
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2180
is($dbi->select(table => $table1)->one->{$key1}, 1);
2181
is($dbi->select(table => $table1)->one->{$key2}, 2);
2182
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2183

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2184
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2185
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2186
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2187
  {$key3 => 4},
2188
  table => $table1,
2189
  primary_key => $key1,
2190
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2191
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2192
is($dbi->select(table => $table1)->one->{$key1}, 1);
2193
is($dbi->select(table => $table1)->one->{$key2}, 2);
2194
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2195

            
2196
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2197
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2198
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2199
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2200
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2201
  {$key3 => 4},
2202
  table => $table1,
2203
  primary_key => [$key1, $key2],
2204
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2205
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2206
is($dbi->select(table => $table1)->one->{$key1}, 1);
2207
is($dbi->select(table => $table1)->one->{$key2}, 2);
2208
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2209

            
2210
test 'select_at';
2211
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2212
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2213
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2214
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2215
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2216
  table => $table1,
2217
  primary_key => [$key1, $key2],
2218
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2219
);
2220
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2221
is($row->{$key1}, 1);
2222
is($row->{$key2}, 2);
2223
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2224

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2225
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2226
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2227
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2228
  table => $table1,
2229
  primary_key => $key1,
2230
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2231
);
2232
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2233
is($row->{$key1}, 1);
2234
is($row->{$key2}, 2);
2235
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2236

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2237
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2238
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2239
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2240
  table => $table1,
2241
  primary_key => [$key1, $key2],
2242
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
);
2244
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2245
is($row->{$key1}, 1);
2246
is($row->{$key2}, 2);
2247
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2248

            
2249
test 'model delete_at';
2250
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2251
eval { $dbi->execute("drop table $table1") };
2252
eval { $dbi->execute("drop table $table2") };
2253
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2254
$dbi->execute($create_table1_2);
2255
$dbi->execute($create_table2_2);
2256
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2257
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2258
$dbi->model($table1)->delete_at(where => [1, 2]);
2259
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2260
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2261
$dbi->model($table1)->delete_at(where => [1, 2]);
2262
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2263
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2264
$dbi->model($table3)->delete_at(where => [1, 2]);
2265
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2266

            
2267
test 'model insert_at';
2268
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2269
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2270
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2271
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2272
  {$key3 => 3},
2273
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2274
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2275
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2276
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2277
is($row->{$key1}, 1);
2278
is($row->{$key2}, 2);
2279
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2280

            
2281
test 'model update_at';
2282
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2283
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2284
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2285
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2287
  {$key3 => 4},
2288
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2289
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2290
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2291
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2292
is($row->{$key1}, 1);
2293
is($row->{$key2}, 2);
2294
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2295

            
2296
test 'model select_at';
2297
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2298
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2299
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2300
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2301
$result = $dbi->model($table1)->select_at(where => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2302
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2303
is($row->{$key1}, 1);
2304
is($row->{$key2}, 2);
2305
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2306

            
2307

            
2308
test 'mycolumn and column';
2309
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2310
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2311
eval { $dbi->execute("drop table $table1") };
2312
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2313
$dbi->execute($create_table1);
2314
$dbi->execute($create_table2);
2315
$dbi->separator('__');
2316
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2317
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2318
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2319
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2320
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2321
  column => [$model->mycolumn, $model->column($table2)],
2322
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2323
);
2324
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2325
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2326

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2327
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2328
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2329
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2330
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2331
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2332
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2333
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2334
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2335
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2336
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2337
is($dbi->select(table => $table1)->one->{$key1}, 1);
2338
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2339

            
2340
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2341
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2342
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2343
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2344
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2345
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2346
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2347
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2348
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
is($dbi->select(table => $table1)->one->{$key1}, 1);
2350
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2351

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2352
test 'mycolumn';
2353
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2354
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2355
eval { $dbi->execute("drop table $table1") };
2356
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2357
$dbi->execute($create_table1);
2358
$dbi->execute($create_table2);
2359
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2360
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2361
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2362
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2363
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2364
  column => [
2365
    $model->mycolumn,
2366
    $model->column($table2)
2367
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2368
);
2369
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2370
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2371

            
2372
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2373
  column => [
2374
    $model->mycolumn([$key1]),
2375
    $model->column($table2 => [$key1])
2376
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2377
);
2378
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2379
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2381
  column => [
2382
    $model->mycolumn([$key1]),
2383
    {$table2 => [$key1]}
2384
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2385
);
2386
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2387
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2388

            
2389
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2390
  column => [
2391
    $model->mycolumn([$key1]),
2392
    ["$table2.$key1", as => "$table2.$key1"]
2393
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2394
);
2395
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2396
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2397

            
2398
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2399
  column => [
2400
    $model->mycolumn([$key1]),
2401
    ["$table2.$key1" => "$table2.$key1"]
2402
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2403
);
2404
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2405
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2406

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2407
test 'merge_param';
2408
$dbi = DBIx::Custom->new;
2409
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2410
  {$key1 => 1, $key2 => 2, $key3 => 3},
2411
  {$key1 => 1, $key2 => 2},
2412
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2413
];
2414
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2416

            
2417
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2418
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2419
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2420
];
2421
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2422
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
2423

            
2424
test 'select() param option';
2425
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2426
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2428
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2429
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2430
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2431
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2432
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2433
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2434
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2435
  table => $table1,
2436
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2437
  where   => {"$table1.$key2" => 3},
2438
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2439
            " $table2 on $table1.$key1 = $table2.$key1"],
2440
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2441
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2442
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2443

            
cleanup
Yuki Kimoto authored on 2011-10-21
2444
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2445
  table => $table1,
2446
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2447
  where   => {"$table1.$key2" => 3},
2448
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2449
           " $table2 on $table1.$key1 = $table2.$key1",
2450
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2451
)->all;
2452
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2453

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2454
test 'select() string where';
2455
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2456
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2457
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2458
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2459
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2460
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2461
  table => $table1,
2462
  where => "$key1 = :$key1 and $key2 = :$key2",
2463
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2464
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2465
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2466

            
2467
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2468
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2469
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2470
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2471
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2472
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2473
  table => $table1,
2474
  where => [
2475
    "$key1 = :$key1 and $key2 = :$key2",
2476
    {$key1 => 1, $key2 => 2}
2477
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2478
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2479
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2480

            
cleanup
Yuki Kimoto authored on 2011-10-21
2481
$dbi = DBIx::Custom->connect;
2482
eval { $dbi->execute("drop table $table1") };
2483
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2484
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2485
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-10-21
2486
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2487
  table => $table1,
2488
  where => [
2489
    "$key1 = :$key1 and $key2 = :$key2",
2490
    {$key1 => 1, $key2 => 2}
2491
  ]
cleanup
Yuki Kimoto authored on 2011-10-21
2492
)->all;
2493
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
2494

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
test 'delete() string where';
2496
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2497
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2498
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2499
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2500
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2501
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2502
  table => $table1,
2503
  where => "$key1 = :$key1 and $key2 = :$key2",
2504
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2505
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2506
$rows = $dbi->select(table => $table1)->all;
2507
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2508

            
2509
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2510
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2512
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2513
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2514
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2515
  table => $table1,
2516
  where => [
2517
    "$key1 = :$key1 and $key2 = :$key2",
2518
     {$key1 => 1, $key2 => 2}
2519
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2521
$rows = $dbi->select(table => $table1)->all;
2522
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2523

            
2524

            
2525
test 'update() string where';
2526
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2527
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2529
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2530
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2531
  {$key1 => 5},
2532
  table => $table1,
2533
  where => "$key1 = :$key1 and $key2 = :$key2",
2534
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2535
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2536
$rows = $dbi->select(table => $table1)->all;
2537
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2538

            
2539
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2540
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2541
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2542
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2543
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2544
  {$key1 => 5},
2545
  table => $table1,
2546
  where => [
2547
    "$key1 = :$key1 and $key2 = :$key2",
2548
    {$key1 => 1, $key2 => 2}
2549
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2551
$rows = $dbi->select(table => $table1)->all;
2552
is_deeply($rows, [{$key1 => 5, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2553

            
2554
test 'insert id and primary_key option';
2555
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2556
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2557
$dbi->execute($create_table1_2);
2558
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2559
  {$key3 => 3},
2560
  primary_key => [$key1, $key2], 
2561
  table => $table1,
2562
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2563
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2564
is($dbi->select(table => $table1)->one->{$key1}, 1);
2565
is($dbi->select(table => $table1)->one->{$key2}, 2);
2566
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2567

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2568
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2569
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2570
  {$key2 => 2, $key3 => 3},
2571
  primary_key => $key1, 
2572
  table => $table1,
2573
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
);
2575

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2580
$dbi = DBIx::Custom->connect;
2581
eval { $dbi->execute("drop table $table1") };
2582
$dbi->execute($create_table1_2);
2583
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2584
  {$key3 => 3},
2585
  primary_key => [$key1, $key2], 
2586
  table => $table1,
2587
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2588
);
2589
is($dbi->select(table => $table1)->one->{$key1}, 1);
2590
ok(!$dbi->select(table => $table1)->one->{$key2});
2591
is($dbi->select(table => $table1)->one->{$key3}, 3);
2592

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2593
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2594
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2595
$dbi->execute($create_table1_2);
2596
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2597
  {$key3 => 3},
2598
  primary_key => [$key1, $key2], 
2599
  table => $table1,
2600
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2601
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2602
is($dbi->select(table => $table1)->one->{$key1}, 1);
2603
is($dbi->select(table => $table1)->one->{$key2}, 2);
2604
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2605

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2606
$dbi = DBIx::Custom->connect;
2607
eval { $dbi->execute("drop table $table1") };
2608
$dbi->execute($create_table1_2);
2609
$param = {$key3 => 3, $key2 => 4};
2610
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2611
  $param,
2612
  primary_key => [$key1, $key2], 
2613
  table => $table1,
2614
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2615
);
2616
is($dbi->select(table => $table1)->one->{$key1}, 1);
2617
is($dbi->select(table => $table1)->one->{$key2}, 4);
2618
is($dbi->select(table => $table1)->one->{$key3}, 3);
2619
is_deeply($param, {$key3 => 3, $key2 => 4});
2620

            
added test
Yuki Kimoto authored on 2011-10-25
2621
$dbi = DBIx::Custom->connect;
2622
eval { $dbi->execute("drop table $table1") };
2623
$dbi->execute($create_table1_2);
2624
$param = {$key3 => 3, $key2 => 4};
2625
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2626
  $param,
2627
  primary_key => [$key1, $key2], 
2628
  table => $table1,
2629
  id => [1, 2],
2630
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2631
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2632
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2633
is_deeply($param, {$key3 => 3, $key2 => 4});
2634

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2635
test 'model insert id and primary_key option';
2636
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2637
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2639
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2640
  {$key3 => 3},
2641
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2642
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2643
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2644
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2645
is($row->{$key1}, 1);
2646
is($row->{$key2}, 2);
2647
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2648

            
2649
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2650
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2651
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2652
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2653
  {$key3 => 3},
2654
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2655
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2656
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2657
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
is($row->{$key1}, 1);
2659
is($row->{$key2}, 2);
2660
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2661

            
2662
test 'update and id option';
2663
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2664
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2665
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2666
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2667
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2668
  {$key3 => 4},
2669
  table => $table1,
2670
  primary_key => [$key1, $key2],
2671
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2672
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2673
is($dbi->select(table => $table1)->one->{$key1}, 1);
2674
is($dbi->select(table => $table1)->one->{$key2}, 2);
2675
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2676

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2677
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2678
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2679
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2680
  {$key3 => 4},
2681
  table => $table1,
2682
  primary_key => $key1,
2683
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2684
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2685
is($dbi->select(table => $table1)->one->{$key1}, 0);
2686
is($dbi->select(table => $table1)->one->{$key2}, 2);
2687
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2688

            
2689
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2690
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2691
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2692
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2693
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2694
  {$key3 => 4},
2695
  table => $table1,
2696
  primary_key => [$key1, $key2],
2697
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2698
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2699
is($dbi->select(table => $table1)->one->{$key1}, 1);
2700
is($dbi->select(table => $table1)->one->{$key2}, 2);
2701
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2702

            
2703

            
2704
test 'model update and id option';
2705
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2706
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2707
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2708
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2709
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2710
  {$key3 => 4},
2711
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2713
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2714
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2715
is($row->{$key1}, 1);
2716
is($row->{$key2}, 2);
2717
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2718

            
2719

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2732
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2733
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2734
  table => $table1,
2735
  primary_key => $key1,
2736
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2737
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2738
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2739

            
2740

            
2741
test 'model delete and id option';
2742
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2743
eval { $dbi->execute("drop table $table1") };
2744
eval { $dbi->execute("drop table $table2") };
2745
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2746
$dbi->execute($create_table1_2);
2747
$dbi->execute($create_table2_2);
2748
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2749
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2750
$dbi->model($table1)->delete(id => [1, 2]);
2751
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2752
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2753
$dbi->model($table1)->delete(id => [1, 2]);
2754
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2755
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2756
$dbi->model($table3)->delete(id => [1, 2]);
2757
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2758

            
2759

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2775
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2776
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2777
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2778
  table => $table1,
2779
  primary_key => $key1,
2780
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2781
);
2782
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2783
is($row->{$key1}, 0);
2784
is($row->{$key2}, 2);
2785
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2786

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2787
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2788
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2790
  table => $table1,
2791
  primary_key => [$key1, $key2],
2792
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2793
);
2794
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2795
is($row->{$key1}, 1);
2796
is($row->{$key2}, 2);
2797
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2798

            
2799

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

            
2811
test 'column separator is default .';
2812
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2813
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2814
eval { $dbi->execute("drop table $table1") };
2815
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2816
$dbi->execute($create_table1);
2817
$dbi->execute($create_table2);
2818
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2819
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2820
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2821
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2823
  column => [$model->column($table2)],
2824
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2825
);
2826
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2827
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2828

            
2829
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2830
  column => [$model->column($table2 => [$key1, $key3])],
2831
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2832
);
2833
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2834
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2835

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2836
test 'separator';
2837
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2838
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2839
eval { $dbi->execute("drop table $table1") };
2840
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2841
$dbi->execute($create_table1);
2842
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2843

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2844
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2845
  table => $table1,
2846
  join => [
2847
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2848
  ],
2849
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2850
);
2851
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2852
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2853
);
2854
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2855
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2856
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2857
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2858
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2859
  column => [
2860
    $model->mycolumn,
2861
    {$table2 => [$key1, $key3]}
2862
  ],
2863
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2864
);
2865
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2866
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2867
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2868

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2869
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2870
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2871
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2872
  column => [
2873
    $model->mycolumn,
2874
    {$table2 => [$key1, $key3]}
2875
  ],
2876
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2877
);
2878
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2879
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2880
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2881

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2882
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2883
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2884
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2885
  column => [
2886
    $model->mycolumn,
2887
    {$table2 => [$key1, $key3]}
2888
  ],
2889
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2890
);
2891
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2892
  {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2893
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2894

            
2895

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2896
test 'filter_off';
2897
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2898
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2899
eval { $dbi->execute("drop table $table1") };
2900
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2901
$dbi->execute($create_table1);
2902
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2903

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2904
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2905
  table => $table1,
2906
  join => [
2907
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2908
  ],
2909
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2910
);
2911
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2912
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2913
$model = $dbi->model($table1);
2914
$result = $model->select(column => $key1);
2915
$result->filter($key1 => sub { $_[0] * 2 });
2916
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2917

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2918
test 'available_datetype';
2919
$dbi = DBIx::Custom->connect;
2920
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2921

            
2922

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2923
test 'select prefix option';
2924
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2925
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2926
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2927
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2928
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2929
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2930

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2932
test 'mapper';
2933
$dbi = DBIx::Custom->connect;
2934
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2935
  id => {key => "$table1.id"},
2936
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2937
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2938
);
2939
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2940
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
2941

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2942
$dbi = DBIx::Custom->connect;
2943
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2944
  id => {key => "$table1.id"},
2945
  author => ["$table1.author" => $dbi->like_value],
2946
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2947
);
2948
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2949
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2950

            
added tests
Yuki Kimoto authored on 2011-08-26
2951
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2952
  id => {key => "$table1.id"},
2953
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2954
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2955
);
2956
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2957

            
2958
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2959
  id => {key => "$table1.id"},
2960
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2961
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2962
);
2963
is_deeply($param, {});
2964

            
2965
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2966
  id => {key => "$table1.id"},
2967
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2968
);
2969
is_deeply($param, {"$table1.price" => undef});
2970

            
2971
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2972
  id => {key => "$table1.id", condition => 'exists'},
2973
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2974
);
2975
is_deeply($param, {"$table1.price" => '%a'});
2976

            
2977
$param = $dbi->mapper(param => {price => 'a'}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2978
  id => {key => "$table1.id"},
2979
  price => ["$table1.price", sub { '%' . $_[0] }]
added tests
Yuki Kimoto authored on 2011-08-26
2980
);
2981
is_deeply($param, {"$table1.price" => '%a'});
2982

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2983
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2984
  price => sub { '%' . $_[0] },
2985
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2986
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2987
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2988

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

            
2994
$where = $dbi->where;
2995
$where->clause(['and', ":${key1}{=}"]);
2996
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2997
$where->param($param);
2998
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2999
$row = $result->all;
3000
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3001

            
3002
$where = $dbi->where;
3003
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3004
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3005
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3006
$row = $result->all;
3007
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3008
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3009
$row = $result->all;
3010
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3011

            
3012
$where = $dbi->where;
3013
$where->clause(['and', ":${key1}{=}"]);
3014
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
3015
$where->param($param);
3016
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3017
$row = $result->all;
3018
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3019
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3020
$row = $result->all;
3021
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3022

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3024
$where = $dbi->where;
3025
$where->clause(['and', ":${key1}{=}"]);
3026
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3027
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3028
$where->param($param);
3029
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3030
$row = $result->all;
3031
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3032

            
3033
$where = $dbi->where;
3034
$where->clause(['and', ":${key1}{=}"]);
3035
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3036
$where->param($param);
3037
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3038
$row = $result->all;
3039
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3040

            
3041
$where = $dbi->where;
3042
$where->clause(['and', ":${key1}{=}"]);
3043
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3044
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3045
$where->param($param);
3046
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3047
$row = $result->all;
3048
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3049

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3051
$where = $dbi->where;
3052
$where->clause(['and', ":${key1}{=}"]);
3053
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3054
$where->param($param);
3055
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3056
$row = $result->all;
3057
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3058

            
3059
$where = $dbi->where;
3060
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3061
  id => {key => "$table1.id"},
3062
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3063
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3064
);
3065
$where->param($param);
3066
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3067
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3068

            
3069
$where = $dbi->where;
3070
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3071
  id => {key => "$table1.id"},
3072
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3073
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3074
);
3075
$where->param($param);
3076
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3077

            
3078
$where = $dbi->where;
3079
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3080
  id => {key => "$table1.id"},
3081
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3082
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3083
);
3084
$where->param($param);
3085
is_deeply($where->param, {});
3086

            
3087
$where = $dbi->where;
3088
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3089
  id => {key => "$table1.id"},
3090
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3091
);
3092
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3093

            
3094
$where = $dbi->where;
3095
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3096
  id => {key => "$table1.id", condition => 'exists'},
3097
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3098
);
3099
is_deeply($param, {"$table1.price" => '%a'});
3100

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

            
3110
$where = $dbi->where;
3111
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3112
  id => {key => "$table1.id"},
3113
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3114
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3115
);
3116
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3117
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3118

            
3119
$where = $dbi->where;
3120
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3121
  id => {key => "$table1.id", condition => 'length'},
3122
  author => ["$table1.author", sub { '%' . $_[0] . '%' }, 'defined'],
3123
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3124
);
3125
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3126
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3127

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3133
test 'order';
3134
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3135
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3136
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3137
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3138
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3139
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3140
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3141
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3142
$order->prepend($key1, "$key2 desc");
3143
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3144
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3145
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3146
$order->prepend("$key1 desc");
3147
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3148
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3149
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3150

            
3151
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3152
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3153
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3154
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3155
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3156
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3157
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3158
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3159
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3160

            
3161
test 'tag_parse';
3162
$dbi = DBIx::Custom->connect;
3163
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3164
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3165
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3166
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3167
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3168
ok($@);
3169

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3170
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3171
{
cleanup
Yuki Kimoto authored on 2012-01-20
3172
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3173
  $dbi = DBIx::Custom->connect;
3174
  eval { $dbi->execute("drop table $table1") };
3175
  $dbi->execute($create_table1);
3176
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3177
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3178
  ok($@);
3179
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3180
  ok($@);
3181
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3182
}
3183

            
3184
{
cleanup
Yuki Kimoto authored on 2012-01-20
3185
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3186
  $dbi = DBIx::Custom->connect;
3187
  eval { $dbi->execute("drop table $table1") };
3188
  $dbi->execute($create_table1);
3189
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3190
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3191
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3192
}
3193

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3194
test 'last_sql';
3195
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3196
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3197
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3198
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3199
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3200

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3232
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3233
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3234
  $source,
3235
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3236
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3237
);
3238
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3239
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3240

            
3241
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3242
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3243
$dbi->execute($create_table1_highperformance);
3244
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3245
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3246
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3247
];
3248
{
cleanup
Yuki Kimoto authored on 2012-01-20
3249
  my $query;
3250
  for my $row (@$rows) {
3251
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3252
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3253
  }
3254
  is_deeply($dbi->select(table => $table1)->all,
3255
    [
3256
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3257
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3258
    ]
3259
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3260
}
3261

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3262
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3263
$dbi->execute($create_table1_highperformance);
3264
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3265
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3266
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3267
];
3268
{
cleanup
Yuki Kimoto authored on 2012-01-20
3269
  my $query;
3270
  my $sth;
3271
  for my $row (@$rows) {
3272
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3273
    $sth ||= $query->{sth};
3274
    $sth->execute(map { $row->{$_} } sort keys %$row);
3275
  }
3276
  is_deeply($dbi->select(table => $table1)->all,
3277
    [
3278
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3279
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3280
    ]
3281
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3282
}
3283

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3284
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3285
$dbi->execute($create_table1_highperformance);
3286
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3287
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3288
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3289
];
3290
{
cleanup
Yuki Kimoto authored on 2012-01-20
3291
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3292
  my $query;
3293
  for my $row (@$rows) {
3294
    $query ||= $model->insert($row, query => 1);
3295
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3296
  }
3297
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3298
    [
3299
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3300
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3301
    ]
3302
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3303
}
3304

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3305
eval { $dbi->execute("drop table $table1") };
3306
$dbi->execute($create_table1);
3307
{
cleanup
Yuki Kimoto authored on 2012-01-20
3308
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3309
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3310
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3311
  like($@, qr/primary_key/);
3312
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3313
}
3314

            
3315
{
cleanup
Yuki Kimoto authored on 2012-01-20
3316
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3317
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3318
  $model->insert({$key1 => 1});
3319
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3320
    table => $table1, primary_key => $key1);
3321
  is($result->one->{$key1}, 1);
3322
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3323
}
3324

            
3325
eval { $dbi->execute("drop table $table1") };
3326
$dbi->execute($create_table1);
3327
{
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3329
  $model->insert({$key1 => 1});
3330
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3331
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3332
}
3333

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3334
test 'id option more';
3335
eval { $dbi->execute("drop table $table1") };
3336
$dbi->execute($create_table1_highperformance);
3337
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3338
  $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
3339
};
3340
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3341
$model->insert($row);
3342
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3343
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3344
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3345
  {$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
3346
);
3347

            
3348
eval { $dbi->execute("drop table $table1") };
3349
eval { $dbi->execute("drop table $table2") };
3350
$dbi->execute($create_table1);
3351
$dbi->execute($create_table2);
3352
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3353
$model->insert({$key1 => 1, $key2 => 2});
3354
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3355
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3356
$model->insert({$key1 => 1, $key3 => 3});
3357
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3358
  column => {$table1 => ["$key2"]},
3359
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3360
);
3361
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3362

            
3363
eval { $dbi->execute("drop table $table1") };
3364
$dbi->execute($create_table1_highperformance);
3365
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3366
  $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
3367
};
3368
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3369
$model->insert($row);
3370
$query = $model->delete(id => 1, query => 1);
3371
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3372
is_deeply($dbi->select(table => $table1)->all, []);
3373

            
3374
eval { $dbi->execute("drop table $table1") };
3375
eval { $dbi->execute($create_table1_highperformance) };
3376
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3377
  $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
3378
};
3379
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3380
$model->insert($row);
3381
$query = $model->select(id => 1, query => 1);
3382
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3383
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3384
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3385
  {$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
3386
);
3387

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3388
test 'result';
3389
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3390
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3391
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3392
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3393
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3394

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3395
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3396
@rows = ();
3397
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3398
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3399
}
3400
is_deeply(\@rows, [[1, 2], [3, 4]]);
3401

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3402
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3403
@rows = ();
3404
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3405
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3406
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3407
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3408

            
3409
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3410
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3411
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3412
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3413
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3414

            
3415
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3416
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3417
$rows = $result->fetch_all;
3418
is_deeply($rows, [[1, 2], [3, 4]]);
3419

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3424
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3425
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3426
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3427
$rows = $result->fetch_all;
3428
is_deeply($rows, [[3, 2], [9, 4]], "array");
3429

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3442
test 'DBIx::Custom::Result fetch_multi';
3443
eval { $dbi->execute("drop table $table1") };
3444
$dbi->execute($create_table1);
3445
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3446
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3447
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3448
$result = $dbi->select(table => $table1);
3449
$rows = $result->fetch_multi(2);
3450
is_deeply($rows, [[1, 2], [3, 4]]);
3451
$rows = $result->fetch_multi(2);
3452
is_deeply($rows, [[5, 6]]);
3453
$rows = $result->fetch_multi(2);
3454
ok(!$rows);
3455

            
3456
test 'DBIx::Custom::Result fetch_hash_multi';
3457
eval { $dbi->execute("drop table $table1") };
3458
$dbi->execute($create_table1);
3459
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3460
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3461
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3462
$result = $dbi->select(table => $table1);
3463
$rows = $result->fetch_hash_multi(2);
3464
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3465
$rows = $result->fetch_hash_multi(2);
3466
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3467
$rows = $result->fetch_hash_multi(2);
3468
ok(!$rows);
3469

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3470
test "query_builder";
3471
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3472
  # Basic tests
3473
  {   name            => 'placeholder basic',
3474
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3475
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3476
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3477
  },
3478
  {
3479
    name            => 'placeholder in',
3480
    source            => "{in k1 3}",
3481
    sql_expected    => "k1 in (?, ?, ?)",
3482
    columns_expected   => [qw/k1 k1 k1/]
3483
  },
3484
  
3485
  # Table name
3486
  {
3487
    name            => 'placeholder with table name',
3488
    source            => "{= a.k1} {= a.k2}",
3489
    sql_expected    => "a.k1 = ? a.k2 = ?",
3490
    columns_expected  => [qw/a.k1 a.k2/]
3491
  },
3492
  {   
3493
    name            => 'placeholder in with table name',
3494
    source            => "{in a.k1 2} {in b.k2 2}",
3495
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3496
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3497
  },
3498
  {
3499
    name            => 'not contain tag',
3500
    source            => "aaa",
3501
    sql_expected    => "aaa",
3502
    columns_expected  => [],
3503
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3504
];
3505

            
3506
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3507
  my $data = $datas->[$i];
3508
  my $dbi = DBIx::Custom->new;
3509
  my $builder = $dbi->query_builder;
3510
  my $query = $builder->build_query($data->{source});
3511
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3512
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3513
}
3514

            
cleanup
Yuki Kimoto authored on 2011-08-13
3515
$dbi = DBIx::Custom->new;
3516
$builder = $dbi->query_builder;
3517
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3518
  p => sub {
3519
    my @args = @_;
3520
    
3521
    my $expand    = "? $args[0] $args[1]";
3522
    my $columns = [2];
3523
    return [$expand, $columns];
3524
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3525
);
3526

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3537
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3538
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3539
});
3540

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3544
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3545
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3546
});
3547

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

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

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

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

            
3562

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

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

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

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

            
3578
test 'variouse source';
3579
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3580
$query = $builder->build_query($source);
3581
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3582

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

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

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

            
3595
$source = "a {= b} }";
3596
eval{$builder->build_query($source)};
3597
like($@, qr/unexpected "}"/, "error : 1");
3598

            
3599
$source = "a {= {}";
3600
eval{$builder->build_query($source)};
3601
like($@, qr/unexpected "{"/, "error : 2");
3602

            
3603
test 'select() sqlfilter option';
3604
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3605
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3606
eval { $dbi->execute("drop table $table1") };
3607
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3608
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3609
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3610
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3611
  table => $table1,
3612
  column => $key1,
3613
  sqlfilter => sub {
3614
    my $sql = shift;
3615
    $sql = "select * from ( $sql ) t where $key1 = 1";
3616
    return $sql;
3617
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3618
)->all;
3619
is_deeply($rows, [{$key1 => 1}]);
3620

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3621
test 'select() after_build_sql option';
3622
$dbi = DBIx::Custom->connect;
3623
$dbi->user_table_info($user_table_info);
3624
eval { $dbi->execute("drop table $table1") };
3625
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3626
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3627
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3628
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3629
  table => $table1,
3630
  column => $key1,
3631
  after_build_sql => sub {
3632
    my $sql = shift;
3633
    $sql = "select * from ( $sql ) t where $key1 = 1";
3634
    return $sql;
3635
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3636
)->all;
3637
is_deeply($rows, [{$key1 => 1}]);
3638

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3639
test 'dbi method from model';
3640
$dbi = MyDBI9->connect;
3641
eval { $dbi->execute("drop table $table1") };
3642
$dbi->execute($create_table1);
3643
$dbi->setup_model;
3644
$model = $dbi->model($table1);
3645
eval{$model->execute("select * from $table1")};
3646
ok(!$@);
3647

            
3648
test 'column table option';
3649
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3650
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3651
eval { $dbi->execute("drop table $table1") };
3652
$dbi->execute($create_table1);
3653
eval { $dbi->execute("drop table $table2") };
3654
$dbi->execute($create_table2);
3655
$dbi->setup_model;
3656
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3657
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3658
$model = $dbi->model($table1);
3659
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3660
  column => [
3661
    $model->column($table2, {alias => $table2_alias})
3662
  ],
3663
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3664
);
3665
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3666
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3667

            
3668
$dbi->separator('__');
3669
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3670
  column => [
3671
    $model->column($table2, {alias => $table2_alias})
3672
  ],
3673
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3674
);
3675
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3676
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3677

            
3678
$dbi->separator('-');
3679
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3680
  column => [
3681
      $model->column($table2, {alias => $table2_alias})
3682
  ],
3683
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
);
3685
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3686
  {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3687

            
3688
test 'create_model';
3689
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3690
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3691
eval { $dbi->execute("drop table $table1") };
3692
eval { $dbi->execute("drop table $table2") };
3693
$dbi->execute($create_table1);
3694
$dbi->execute($create_table2);
3695

            
3696
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3697
  table => $table1,
3698
  join => [
3699
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3700
  ],
3701
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3702
);
3703
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3704
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3705
);
3706
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3707
  table => $table3,
3708
  filter => [
3709
    $key1 => {in => sub { uc $_[0] }}
3710
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3711
);
3712
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3713
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3714
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3715
$model = $dbi->model($table1);
3716
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3717
  column => [$model->mycolumn, $model->column($table2)],
3718
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3719
);
3720
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3721
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3722
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3723

            
3724
test 'model method';
3725
$dbi = DBIx::Custom->connect;
3726
eval { $dbi->execute("drop table $table2") };
3727
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3728
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3729
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3730
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3731
);
3732
$model->method(foo => sub { shift->select(@_) });
3733
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3734

            
3735
test 'model helper';
3736
$dbi = DBIx::Custom->connect;
3737
eval { $dbi->execute("drop table $table2") };
3738
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3739
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3740
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3741
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3742
);
3743
$model->helper(foo => sub { shift->select(@_) });
3744
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3745

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

            
3753
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3754
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3755
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3756
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3757
where $key1 = 1
3758
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3759
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3760
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3761
$rows   = $result->all;
3762
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3763
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3764
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3765

            
3766

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

            
3773
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3774
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3775
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3776
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3777
where $key1 = 1
3778
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3779
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3780
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3781
$rows   = $result->all;
3782
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3783
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3784
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3785

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

            
3792
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3793
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3794
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3795
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3796
where $key1 = 1
3797
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3798
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3799
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3800
$rows   = $result->all;
3801
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3802
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3803
  "update param no_set");
cleanup test
Yuki Kimoto authored on 2011-08-15
3804

            
cleanup
Yuki Kimoto authored on 2012-01-20
3805
          
cleanup test
Yuki Kimoto authored on 2011-08-15
3806
$dbi = DBIx::Custom->connect;
3807
eval { $dbi->execute("drop table $table1") };
3808
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3809
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3810
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3811

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3812
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3813
$assign_clause = $dbi->assign_param($param);
3814
$sql = <<"EOS";
3815
update $table1 set $assign_clause
3816
where $key1 = 1
3817
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3818
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3819
$result = $dbi->execute("select * from $table1 order by $key1");
3820
$rows   = $result->all;
3821
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3822
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3823
  "basic");
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3824

            
3825
$param = {$key2 => 11};
3826
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3827
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3828
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3829
where $key1 = 1
3830
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3831
$dbi->execute($sql, $param, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3832
$result = $dbi->execute("select * from $table1 order by $key1");
3833
$rows   = $result->all;
3834
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3835
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3836
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
3837

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3838
test 'Model class';
3839
$dbi = MyDBI1->connect;
3840
eval { $dbi->execute("drop table $table1") };
3841
$dbi->execute($create_table1);
3842
$model = $dbi->model($table1);
3843
$model->insert({$key1 => 'a', $key2 => 'b'});
3844
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3845
eval { $dbi->execute("drop table $table2") };
3846
$dbi->execute($create_table2);
3847
$model = $dbi->model($table2);
3848
$model->insert({$key1 => 'a'});
3849
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3850
is($dbi->models->{$table1}, $dbi->model($table1));
3851
is($dbi->models->{$table2}, $dbi->model($table2));
3852

            
3853
$dbi = MyDBI4->connect;
3854
eval { $dbi->execute("drop table $table1") };
3855
$dbi->execute($create_table1);
3856
$model = $dbi->model($table1);
3857
$model->insert({$key1 => 'a', $key2 => 'b'});
3858
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3859
eval { $dbi->execute("drop table $table2") };
3860
$dbi->execute($create_table2);
3861
$model = $dbi->model($table2);
3862
$model->insert({$key1 => 'a'});
3863
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3864

            
3865
$dbi = MyDBI5->connect;
3866
eval { $dbi->execute("drop table $table1") };
3867
eval { $dbi->execute("drop table $table2") };
3868
$dbi->execute($create_table1);
3869
$dbi->execute($create_table2);
3870
$model = $dbi->model($table2);
3871
$model->insert({$key1 => 'a'});
3872
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3873
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3874
$model = $dbi->model($table1);
3875
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3876

            
3877
test 'primary_key';
3878
$dbi = MyDBI1->connect;
3879
$model = $dbi->model($table1);
3880
$model->primary_key([$key1, $key2]);
3881
is_deeply($model->primary_key, [$key1, $key2]);
3882

            
3883
test 'columns';
3884
$dbi = MyDBI1->connect;
3885
$model = $dbi->model($table1);
3886
$model->columns([$key1, $key2]);
3887
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3888

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3889
test 'setup_model';
3890
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3891
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3892
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3893
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3894

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3895
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3896
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3897
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3898
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3899
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3900

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3901
test 'each_column';
3902
$dbi = DBIx::Custom->connect;
3903
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3904
eval { $dbi->execute("drop table $table1") };
3905
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3906
eval { $dbi->execute("drop table $table3") };
3907
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3908
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3909

            
3910
$infos = [];
3911
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3912
  my ($self, $table, $column, $cinfo) = @_;
3913
  
3914
  if ($table =~ /^table\d/i) {
3915
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3916
     push @$infos, $info;
3917
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3918
});
3919
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3920
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3921
  [
3922
    [$table1, $key1, $key1],
3923
    [$table1, $key2, $key2],
3924
    [$table2, $key1, $key1],
3925
    [$table2, $key3, $key3]
3926
  ]
3927
  
cleanup test
Yuki Kimoto authored on 2011-08-10
3928
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3929

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3930
test 'each_table';
3931
$dbi = DBIx::Custom->connect;
3932
eval { $dbi->execute("drop table $table1") };
3933
eval { $dbi->execute("drop table $table2") };
3934
$dbi->execute($create_table2);
3935
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3936

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3937
$infos = [];
3938
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3939
  my ($self, $table, $table_info) = @_;
3940
  
3941
  if ($table =~ /^table\d/i) {
3942
    my $info = [$table, $table_info->{TABLE_NAME}];
3943
    push @$infos, $info;
3944
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3945
});
3946
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3947
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3948
  [
3949
    [$table1, $table1],
3950
    [$table2, $table2],
3951
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3952
);
3953

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3954
$dbi = DBIx::Custom->connect;
3955
eval { $dbi->execute("drop table $table1") };
3956
eval { $dbi->execute("drop table $table2") };
3957
$dbi->execute($create_table2);
3958
$dbi->execute($create_table1_type);
3959

            
3960
$infos = [];
3961
$dbi->user_table_info($user_table_info);
3962
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3963
  my ($self, $table, $table_info) = @_;
3964
  
3965
  if ($table =~ /^table\d/i) {
3966
     my $info = [$table, $table_info->{TABLE_NAME}];
3967
     push @$infos, $info;
3968
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
3969
});
3970
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3971
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3972
  [
3973
    [$table1, $table1],
3974
    [$table2, $table2],
3975
    [$table3, $table3],
3976
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
3977
);
3978

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3979
test 'type_rule into';
3980
eval { $dbi->execute("drop table $table1") };
3981
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3982
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3983

            
3984

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3985
$dbi = DBIx::Custom->connect;
3986
eval { $dbi->execute("drop table $table1") };
3987
$dbi->execute($create_table1_type);
3988

            
cleanup
Yuki Kimoto authored on 2011-08-16
3989
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3990
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3991
  into1 => {
3992
    $date_typename => sub { '2010-' . $_[0] }
3993
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
3994
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3995
$dbi->insert({$key1 => '01-01'}, table => $table1);
3996
$result = $dbi->select(table => $table1);
3997
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3998

            
3999
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4000
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4001
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4002
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4003
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4004
  into1 => [
4005
     [$date_typename, $datetime_typename] => sub {
4006
        my $value = shift;
4007
        $value =~ s/02/03/g;
4008
        return $value;
4009
     }
4010
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4011
);
4012
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4013
$result = $dbi->select(table => $table1);
4014
$row = $result->one;
4015
like($row->{$key1}, qr/^2010-01-03/);
4016
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
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_type);
4021
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4022
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4023
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4024
  into1 => [
4025
    [$date_typename, $datetime_typename] => sub {
4026
      my $value = shift;
4027
      $value =~ s/02/03/g;
4028
      return $value;
4029
    }
4030
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4031
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4032
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4033
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4034
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4035
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4036
$row = $result->one;
4037
like($row->{$key1}, qr/^2010-01-03/);
4038
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4039

            
4040
$dbi = DBIx::Custom->connect;
4041
eval { $dbi->execute("drop table $table1") };
4042
$dbi->execute($create_table1_type);
4043
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4044
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4045
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4046
  into1 => [
4047
    [$date_typename, $datetime_typename] => sub {
4048
      my $value = shift;
4049
      $value =~ s/02/03/g;
4050
      return $value;
4051
    }
4052
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4053
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4054
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4055
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4056
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4057
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4058
);
4059
$row = $result->one;
4060
like($row->{$key1}, qr/^2010-01-03/);
4061
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4062

            
4063
$dbi = DBIx::Custom->connect;
4064
eval { $dbi->execute("drop table $table1") };
4065
$dbi->execute($create_table1_type);
4066
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4067
  my $value = shift || '';
4068
  $value =~ s/02/03/;
4069
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4070
});
cleanup
Yuki Kimoto authored on 2011-08-16
4071
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4072
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4073
  from1 => {
4074
    $date_datatype => 'convert',
4075
  },
4076
  into1 => {
4077
      $date_typename => 'convert',
4078
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4079
);
4080
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4081
$result = $dbi->select(table => $table1);
4082
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4083
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4084
$row = $result->fetch;
4085
like($row->[0], qr/^2010-03-03/);
4086
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4087

            
4088
test 'type_rule and filter order';
4089
$dbi = DBIx::Custom->connect;
4090
eval { $dbi->execute("drop table $table1") };
4091
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4092
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4093
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4094
  into1 => {
4095
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4096
  },
4097
  into2 => {
4098
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4099
  },
4100
  from1 => {
4101
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4102
  },
4103
  from2 => {
4104
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4105
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4106
);
4107
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4108
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4109
$result = $dbi->select(table => $table1);
4110
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4111
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4112

            
4113

            
4114
$dbi = DBIx::Custom->connect;
4115
eval { $dbi->execute("drop table $table1") };
4116
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4117
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4118
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4119
  from1 => {
4120
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4121
  },
4122
  from2 => {
4123
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4124
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4125
);
4126
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4127
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4128
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4129
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4130
  from1 => {
4131
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4132
  },
4133
  from2 => {
4134
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4135
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4136
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4137
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4138
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4139

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4140
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4141
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4142
eval { $dbi->execute("drop table $table1") };
4143
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4144
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4145
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4146
  from1 => {
4147
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4148
  },
4149
  into1 => {
4150
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4151
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4152
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4153
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4154
$result = $dbi->select(table => $table1, type_rule_off => 1);
4155
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4156

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4157
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4158
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4159
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4160
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4161
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4162
  from1 => {
4163
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4164
  },
4165
  into1 => {
4166
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4167
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4168
);
4169
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4170
$result = $dbi->select(table => $table1, type_rule_off => 1);
4171
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4172

            
4173
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4174
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4175
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4176
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4177
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4178
  from1 => {
4179
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4180
  },
4181
  into1 => {
4182
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4183
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4184
);
4185
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4186
$result = $dbi->select(table => $table1);
4187
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4188

            
4189
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4190
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4191
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4192
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4193
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4194
  from1 => {
4195
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4196
  },
4197
  into1 => {
4198
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4199
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4200
);
4201
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4202
$result = $dbi->select(table => $table1);
4203
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4204

            
4205
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4206
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4207
$dbi->execute($create_table1_type);
4208
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
cleanup
Yuki Kimoto authored on 2011-08-16
4209
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4210
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4211
  into1 => {
4212
    $date_typename => 'ppp'
4213
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4214
);
4215
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4216
$result = $dbi->select(table => $table1);
4217
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4218

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4219
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4220
  into1 => {
4221
    $date_typename => 'pp'
4222
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4223
)};
4224
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4225

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4226
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4227
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4228
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4229
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4230
  $dbi->type_rule(
4231
    from1 => {
4232
      Date => sub { $_[0] * 2 },
4233
    }
4234
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4235
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4236
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4237

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4238
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4239
  $dbi->type_rule(
4240
    into1 => {
4241
      Date => sub { $_[0] * 2 },
4242
    }
4243
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4244
};
4245
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4246

            
4247
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4248
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4249
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4250
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4251
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4252
  from1 => {
4253
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4254
  },
4255
  into1 => {
4256
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4257
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4258
);
4259
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4260
$result = $dbi->select(table => $table1);
4261
$result->type_rule_off;
4262
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4263

            
4264
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4265
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4266
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4267
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4268
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4269
  from1 => {
4270
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4271
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4272
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4273
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4274
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4275
$result = $dbi->select(table => $table1);
4276
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4277
  from1 => {
4278
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4279
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4280
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4281
$row = $result->one;
4282
like($row->{$key1}, qr/^2010-01-05/);
4283
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4284

            
4285
$result = $dbi->select(table => $table1);
4286
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4287
  from1 => {
4288
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4289
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4290
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4291
$row = $result->one;
4292
like($row->{$key1}, qr/2010-01-05/);
4293
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4294

            
4295
$result = $dbi->select(table => $table1);
4296
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4297
  from1 => {
4298
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4299
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4300
);
4301
$row = $result->one;
4302
like($row->{$key1}, qr/2010-01-05/);
4303
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4304

            
4305
$result = $dbi->select(table => $table1);
4306
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4307
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4308
);
4309
$row = $result->one;
4310
like($row->{$key1}, qr/2010-01-05/);
4311
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4312

            
4313
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4314
$result = $dbi->select(table => $table1);
4315
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4316
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4317
);
4318
$row = $result->one;
4319
like($row->{$key1}, qr/^2010-01-05/);
4320
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4321

            
4322
$result = $dbi->select(table => $table1);
4323
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4324
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4325
);
4326
$row = $result->one;
4327
like($row->{$key1}, qr/^2010-01-03/);
4328
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4329

            
4330
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4331
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4332
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4333
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4334
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4335
  from1 => {
4336
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4337
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4338
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4339
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4340
$result = $dbi->select(table => $table1);
4341
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4342
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4343

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4344
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4345
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4346
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4347
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4348
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4349
  from1 => {
4350
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4351
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4352
);
4353
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4354
$result = $dbi->select(table => $table1);
4355
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4356
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4357

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4406
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4407
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4408
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4409
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4410
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4411
  into1 => {
4412
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4413
  },
4414
  into2 => {
4415
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4416
  },
4417
  from1 => {
4418
    $date_datatype => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4419
  },
4420
  from2 => {
4421
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4422
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4423
);
4424
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule2_off => 1);
4425
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4426
like($result->type_rule2_off->fetch_one->[0], qr/^2010-01-06/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4427
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4428
like($result->type_rule2_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4429

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4430
test 'join';
4431
$dbi = DBIx::Custom->connect;
4432
eval { $dbi->execute("drop table $table1") };
4433
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4434
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4435
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4436
eval { $dbi->execute("drop table $table2") };
4437
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4438
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4439
eval { $dbi->execute("drop table $table3") };
4440
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4441
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4442
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4443
  table => $table1,
4444
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4445
  where   => {"$table1.$key2" => 2},
4446
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4447
)->all;
4448
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4449

            
4450
$dbi = DBIx::Custom->connect;
4451
eval { $dbi->execute("drop table $table1") };
4452
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4453
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4454
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4455
eval { $dbi->execute("drop table $table2") };
4456
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4457
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4458
eval { $dbi->execute("drop table $table3") };
4459
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4460
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4461
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4462
  table => $table1,
4463
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4464
  where   => {"$table1.$key2" => 2},
4465
  join  => {
4466
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4467
    table => [$table1, $table2]
4468
  }
added test
Yuki Kimoto authored on 2011-10-27
4469
)->all;
4470
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
4471

            
4472
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4473
  table => $table1,
4474
  where   => {$key1 => 1},
4475
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4476
)->all;
4477
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4478

            
4479
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4480
  table => $table1,
4481
  where   => {$key1 => 1},
4482
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4483
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4484
)->all;
4485
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4486

            
4487
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4488
  column => "$table3.$key4 as ${table3}__$key4",
4489
  table => $table1,
4490
  where   => {"$table1.$key1" => 1},
4491
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4492
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4493
)->all;
4494
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4495

            
4496
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4497
  column => "$table1.$key1 as ${table1}__$key1",
4498
  table => $table1,
4499
  where   => {"$table3.$key4" => 4},
4500
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4501
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4502
)->all;
4503
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4504

            
4505
$dbi = DBIx::Custom->connect;
4506
eval { $dbi->execute("drop table $table1") };
4507
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4508
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4509
eval { $dbi->execute("drop table $table2") };
4510
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4511
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4512
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4513
  table => $table1,
4514
  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",
4515
  where   => {"$table1.$key2" => 2},
4516
  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
4517
)->all;
4518
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4519
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4520

            
4521

            
4522
$dbi = DBIx::Custom->connect;
4523
eval { $dbi->execute("drop table $table1") };
4524
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4525
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4526
$sql = <<"EOS";
4527
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4528
select * from $table1 t1
4529
where t1.$key2 = (
4530
  select max(t2.$key2) from $table1 t2
4531
  where t1.$key1 = t2.$key1
4532
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4533
) $table3 on $table1.$key1 = $table3.$key1
4534
EOS
4535
$join = [$sql];
4536
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4537
  table => $table1,
4538
  column => "$table3.$key1 as ${table3}__$key1",
4539
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4540
)->all;
4541
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4542

            
4543
$dbi = DBIx::Custom->connect;
4544
eval { $dbi->execute("drop table $table1") };
4545
eval { $dbi->execute("drop table $table2") };
4546
$dbi->execute($create_table1);
4547
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4548
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4549
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4550
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4551
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4552
  table => $table1,
4553
  join => [
4554
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4555
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4556
);
4557
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4558
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4559
  table => $table1,
4560
  column => [{$table2 => [$key3]}],
4561
  join => [
4562
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4563
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4564
);
4565
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4566
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4567
  table => $table1,
4568
  column => [{$table2 => [$key3]}],
4569
  join => [
4570
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4571
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4572
);
4573
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4574

            
4575
$dbi = DBIx::Custom->connect;
4576
eval { $dbi->execute("drop table $table1") };
4577
eval { $dbi->execute("drop table $table2") };
4578
$dbi->execute($create_table1);
4579
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4580
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4581
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4582
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4583
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4584
  table => $table1,
4585
  column => [{$table2 => [$key3]}],
4586
  join => [
4587
    {
4588
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4589
      table => [$table1, $table2]
4590
    }
4591
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4592
);
4593
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4594

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4595
$dbi = DBIx::Custom->connect;
4596
eval { $dbi->execute("drop table $table1") };
4597
eval { $dbi->execute("drop table $table2") };
4598
$dbi->execute($create_table1);
4599
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4600
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4601
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4602
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4603
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4604
  table => $table1,
4605
  column => [{$table2 => [$key3]}],
4606
  join => [
4607
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4608
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4609
);
4610
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4611

            
4612
$dbi = DBIx::Custom->connect;
4613
eval { $dbi->execute("drop table $table1") };
4614
eval { $dbi->execute("drop table $table2") };
4615
$dbi->execute($create_table1);
4616
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4617
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4618
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4619
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4620
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4621
  table => $table1,
4622
  column => [{$table2 => [$key3]}],
4623
  join => [
4624
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4625
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4626
);
4627
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4628

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4629
test 'columns';
4630
$dbi = MyDBI1->connect;
4631
$model = $dbi->model($table1);
4632

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4633
test 'count';
4634
$dbi = DBIx::Custom->connect;
4635
eval { $dbi->execute("drop table $table1") };
4636
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4637
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4638
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4639
is($dbi->count(table => $table1), 2);
4640
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4641
$model = $dbi->create_model(table => $table1);
4642
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4643

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4644
eval { $dbi->execute("drop table $table1") };
4645
eval { $dbi->execute("drop table $table2") };
4646
$dbi->execute($create_table1);
4647
$dbi->execute($create_table2);
4648
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4649
$model->insert({$key1 => 1, $key2 => 2});
4650
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4651
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4652
$model->insert({$key1 => 1, $key3 => 3});
4653
is($model->count(id => 1), 1);
4654
is($model->count(where => {"$table2.$key3" => 3}), 1);
4655

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