DBIx-Custom / t / common.t /
Newer Older
4629 lines | 151.594kb
added common test executing ...
Yuki Kimoto authored on 2011-08-07
1
use Test::More;
2
use strict;
3
use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
4
use Encode qw/encode_utf8/;
cleanup test
Yuki Kimoto authored on 2011-08-10
5
use FindBin;
cleanup
Yuki Kimoto authored on 2011-08-13
6
use Scalar::Util 'isweak';
cleanup test
Yuki Kimoto authored on 2011-08-10
7

            
added common test executing ...
Yuki Kimoto authored on 2011-08-07
8
my $dbi;
9

            
10
plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
11
  unless $ENV{DBIX_CUSTOM_TEST_RUN}
12
    && eval { $dbi = DBIx::Custom->connect; 1 };
13

            
14
plan 'no_plan';
15

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
16
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
finished oracle test
Yuki Kimoto authored on 2011-08-15
17
sub test { print "# $_[0]\n" }
18

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
119
  package MyModel2::table1;
test cleanup
Yuki Kimoto authored on 2011-08-10
120

            
cleanup
Yuki Kimoto authored on 2012-01-20
121
  use strict;
122
  use warnings;
test cleanup
Yuki Kimoto authored on 2011-08-10
123

            
cleanup
Yuki Kimoto authored on 2012-01-20
124
  use base 'MyModel2::Base1';
test cleanup
Yuki Kimoto authored on 2011-08-10
125

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
169
  use base 'MyModel2::Base1';
170

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
298
$result = $dbi->execute($query);
299
@rows = ();
300
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
301
  push @rows, {%$row};
cleanup test
Yuki Kimoto authored on 2011-08-15
302
}
303
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_hash");
test cleanup
Yuki Kimoto authored on 2011-08-10
304

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
593
eval { $dbi->execute("drop table $table1") };
594
$dbi->execute($create_table1_2);
595
$param = {$key1 => 1};
test cleanup
Yuki Kimoto authored on 2011-11-01
596
$dbi->insert($param, table => $table1, updated_at => $key3);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
597
$result = $dbi->select(table => $table1);
598
is_deeply($param, {$key1 => 1});
599
$row   = $result->one;
600
is($row->{$key1}, 1);
601
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
602

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
615
eval { $dbi->execute("drop table $table1") };
616
$dbi->execute($create_table1_2);
617
$model = $dbi->create_model(table => $table1, created_at => $key2);
618
$param = {$key1 => 1};
619
$model->insert($param);
620
$result = $dbi->select(table => $table1);
621
is_deeply($param, {$key1 => 1});
622
$row   = $result->one;
623
is($row->{$key1}, 1);
624
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
625

            
626
eval { $dbi->execute("drop table $table1") };
627
$dbi->execute($create_table1_2);
628
$param = {$key1 => 1};
629
$model = $dbi->create_model(table => $table1, updated_at => $key3);
630
$model->insert($param);
631
$result = $dbi->select(table => $table1);
632
is_deeply($param, {$key1 => 1});
633
$row   = $result->one;
634
is($row->{$key1}, 1);
635
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
636

            
637
eval { $dbi->execute("drop table $table1") };
638
$dbi->execute($create_table1_2);
639
$param = {$key1 => 1};
640
$model = $dbi->create_model(table => $table1, created_at => $key2, updated_at => $key3);
641
$model->insert($param);
642
$result = $dbi->select(table => $table1);
643
is_deeply($param, {$key1 => 1});
644
$row   = $result->one;
645
is($row->{$key1}, 1);
646
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
647
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
648
is($row->{$key2}, $row->{$key3});
649

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
650
eval { $dbi->execute("drop table $table1") };
651
$dbi->execute($create_table1);
652
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
653
$result = $dbi->execute("select * from $table1");
654
$rows   = $result->all;
655
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
656

            
657
eval { $dbi->execute("drop table $table1") };
658
$dbi->execute($create_table1_2);
659
$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
660
table => $table1,
661
updated_at => $key2,
662
created_at => $key3
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
663
);
664
$result = $dbi->execute("select * from $table1");
665
$rows   = $result->all;
666
is($rows->[0]->{$key1}, 1);
667
is($rows->[1]->{$key1}, 3);
668
like($rows->[0]->{$key2}, qr/\d{2}:/);
669
like($rows->[1]->{$key2}, qr/\d{2}:/);
670
like($rows->[0]->{$key3}, qr/\d{2}:/);
671
like($rows->[1]->{$key3}, qr/\d{2}:/);
672

            
673
eval { $dbi->execute("drop table $table1") };
674
$dbi->execute($create_table1);
675
$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
cleanup
Yuki Kimoto authored on 2012-01-20
676
table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
677
$result = $dbi->execute("select * from $table1");
678
$rows   = $result->all;
679
is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
680

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
681
test 'update_or_insert';
682
eval { $dbi->execute("drop table $table1") };
683
$dbi->execute($create_table1);
684
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
685
  {$key2 => 2},
686
  table => $table1,
687
  primary_key => $key1,
688
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
689
);
690
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
691
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
692

            
693
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
694
  {$key2 => 3},
695
  table => $table1,
696
  primary_key => $key1,
697
  id => 1
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
698
);
699
$rows = $dbi->select(id => 1, table => $table1, primary_key => $key1)->all;
700
is_deeply($rows, [{$key1 => 1, $key2 => 3}], "basic");
701

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
702
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
703
  $dbi->update_or_insert(
704
    {$key2 => 3},
705
    table => $table1,
706
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
707
};
708

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
711
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
712
  $dbi->insert({$key1 => 1}, table => $table1);
713
  $dbi->update_or_insert(
714
    {$key2 => 3},
715
    table => $table1,
716
    primary_key => $key1,
717
    id => 1
718
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
719
};
720
like($@, qr/one/);
721

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
722
eval { $dbi->execute("drop table $table1") };
723
$dbi->execute($create_table1);
724
$dbi->update_or_insert(
cleanup
Yuki Kimoto authored on 2012-01-20
725
  {},
726
  table => $table1,
727
  primary_key => $key1,
728
  id => 1
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
729
);
730
$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
731
is($row->{$key1}, 1);
732

            
733
eval { 
cleanup
Yuki Kimoto authored on 2012-01-20
734
  $affected = $dbi->update_or_insert(
735
    {},
736
    table => $table1,
737
    primary_key => $key1,
738
    id => 1
739
  );
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
740
};
741
is($affected, 0);
742

            
micro optimization
Yuki Kimoto authored on 2011-10-31
743
test 'model update_or_insert';
744
eval { $dbi->execute("drop table $table1") };
745
$dbi->execute($create_table1);
746
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
747
  table => $table1,
748
  primary_key => $key1
micro optimization
Yuki Kimoto authored on 2011-10-31
749
);
750
$model->update_or_insert({$key2 => 2}, id => 1);
751
$row = $model->select(id => 1)->one;
752
is_deeply($row, {$key1 => 1, $key2 => 2}, "basic");
753

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
754
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
755
  $model->insert({$key1 => 1});
756
  $model->update_or_insert(
757
    {$key2 => 3},
758
    id => 1
759
  );
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
760
};
761
like($@, qr/one/);
762

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
763
test 'default_bind_filter';
764
$dbi->execute("delete from $table1");
765
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
766
  twice       => sub { $_[0] * 2 },
767
  three_times => sub { $_[0] * 3 }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
768
);
769
$dbi->default_bind_filter('twice');
cleanup
Yuki Kimoto authored on 2011-11-01
770
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, filter => {$key1 => 'three_times'});
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
771
$result = $dbi->execute("select * from $table1");
772
$rows   = $result->all;
773
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
774
$dbi->default_bind_filter(undef);
775

            
test cleanup
Yuki Kimoto authored on 2011-08-10
776
test 'update';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
777
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
778
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
779
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
780
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
781
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
782
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
783
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
784
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
785
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
786
  "basic");
added tests
Yuki Kimoto authored on 2011-11-01
787

            
788
eval { $dbi->execute("drop table $table1") };
789
$dbi->execute($create_table1_2);
790
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
791
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
792
$dbi->update(param => {$key2 => 11}, table => $table1, where => {$key1 => 1});
793
$result = $dbi->execute("select * from $table1 order by $key1");
794
$rows   = $result->all;
795
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
796
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
797
  "basic");
798
                
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
799
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
800
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
801
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
802
$dbi->update({$key2 => 12}, table => $table1, where => {$key2 => 2, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
803
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
804
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
805
is_deeply($rows, [{$key1 => 1, $key2 => 12, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
806
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
807
  "update key same as search key");
test cleanup
Yuki Kimoto authored on 2011-08-10
808

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
816
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
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);
test cleanup
Yuki Kimoto authored on 2011-08-10
819
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
820
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
821
            filter => {$key2 => sub { $_[0] * 2 }});
cleanup test
Yuki Kimoto authored on 2011-08-15
822
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
823
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
824
is_deeply($rows, [{$key1 => 1, $key2 => 22, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
825
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
826
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
827

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
833
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
834
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
835
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
836
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
837
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
838
$where->param({$key1 => 1, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
839
$dbi->update({$key1 => 3}, table => $table1, where => $where);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
840
$result = $dbi->select(table => $table1);
841
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
842

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
843
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
844
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
845
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
846
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
847
  {$key1 => 3},
848
  table => $table1,
849
  where => [
850
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
851
    {$key1 => 1, $key2 => 2}
852
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
853
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
854
$result = $dbi->select(table => $table1);
855
is_deeply($result->all, [{$key1 => 3, $key2 => 2}], 'update() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
856

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

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

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

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
873
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
874
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
875
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
876
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
877
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
878
$dbi->insert({select => 1}, table => 'table');
879
$dbi->update({update => 2}, table => 'table', where => {select => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
880
$result = $dbi->execute("select * from ${q}table$p");
881
$rows   = $result->all;
882
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
883

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

            
887
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
888
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
889
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
890
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
cleanup
Yuki Kimoto authored on 2011-11-01
891
$dbi->insert({select => 1}, table => 'table');
892
$dbi->update({update => 2}, table => 'table', where => {'table.select' => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
893
$result = $dbi->execute("select * from ${q}table$p");
894
$rows   = $result->all;
895
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
896

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
897
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
898
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
899
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
900
$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
901
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
902
$result = $dbi->execute("select * from $table1 order by $key1");
test cleanup
Yuki Kimoto authored on 2011-08-10
903
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
904
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
905
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
906
  "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
907

            
updated pod
Yuki Kimoto authored on 2011-09-02
908
eval { $dbi->execute("drop table $table1") };
909
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
910
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
911
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
912
$dbi->update({$key2 => 11}, table => $table1, where => {$key1 => 1},
updated pod
Yuki Kimoto authored on 2011-09-02
913
wrap => {$key2 => sub { "$_[0] - 1" }});
914
$result = $dbi->execute("select * from $table1 order by $key1");
915
$rows   = $result->all;
916
is_deeply($rows, [{$key1 => 1, $key2 => 10, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
917
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
918
  "basic");
updated pod
Yuki Kimoto authored on 2011-09-02
919

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

            
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
931
eval { $dbi->execute("drop table $table1") };
932
$dbi->execute($create_table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
933
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
934
  $key1 => '5'
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
935
);
test cleanup
Yuki Kimoto authored on 2011-11-01
936
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
937
$dbi->update(table => $table1, timestamp => 1, where => {$key2 => 2});
938
$result = $dbi->execute("select * from $table1");
939
$rows   = $result->all;
940
is_deeply($rows, [{$key1 => 5, $key2 => 2}], "basic");
941

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
942
eval { $dbi->execute("drop table $table1") };
943
$dbi->execute($create_table1);
944
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
945
  [$key1, $key2] => sub { '5' }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
946
);
test cleanup
Yuki Kimoto authored on 2011-11-01
947
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
948
$dbi->update_all(table => $table1, timestamp => 1);
949
$result = $dbi->execute("select * from $table1");
950
$rows   = $result->all;
951
is_deeply($rows, [{$key1 => 5, $key2 => 5}], "basic");
952

            
953
eval { $dbi->execute("drop table $table1") };
954
$dbi->execute($create_table1);
955
$dbi->update_timestamp(
cleanup
Yuki Kimoto authored on 2012-01-20
956
  [$key1, $key2] => sub { "" . DBIx::Custom->new }
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
957
);
test cleanup
Yuki Kimoto authored on 2011-11-01
958
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
959
$dbi->update_all(table => $table1, timestamp => 1);
960
$result = $dbi->execute("select * from $table1");
961
$rows   = $result->all;
962
is($rows->[0]->{$key1}, $rows->[0]->{$key2});
963

            
micro optimization and
Yuki Kimoto authored on 2011-10-25
964
eval { $dbi->execute("drop table $table1") };
965
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
966
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
967
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
968
$param = {$key2 => 11};
969
$dbi->update($param, table => $table1, where => {$key1 => 1});
970
is_deeply($param, {$key2 => 11});
971
$result = $dbi->execute("select * from $table1 order by $key1");
972
$rows   = $result->all;
973
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
974
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
975
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
976

            
977
eval { $dbi->execute("drop table $table1") };
978
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
979
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
980
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
micro optimization and
Yuki Kimoto authored on 2011-10-25
981
$param = {$key2 => 11};
982
$dbi->update($param, table => $table1, where => {$key2 => 2});
983
is_deeply($param, {$key2 => 11});
984
$result = $dbi->execute("select * from $table1 order by $key1");
985
$rows   = $result->all;
986
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
987
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
988
  "basic");
micro optimization and
Yuki Kimoto authored on 2011-10-25
989

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
990
eval { $dbi->execute("drop table $table1") };
991
$dbi->execute($create_table1_2);
992
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
993
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
994
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key1 => 1});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
995
$result = $dbi->select(table => $table1);
996
is_deeply($param, {$key3 => 4});
997
$row   = $result->one;
998
is($row->{$key3}, 4);
999
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1000

            
1001
eval { $dbi->execute("drop table $table1") };
1002
$dbi->execute($create_table1_2);
1003
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1004
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
1005
$dbi->update($param, table => $table1, updated_at => $key2, where => {$key3 => 3});
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1006
$result = $dbi->select(table => $table1);
1007
is_deeply($param, {$key3 => 4});
1008
$row   = $result->one;
1009
is($row->{$key3}, 4);
1010
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1011

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1012
eval { $dbi->execute("drop table $table1") };
1013
$dbi->execute($create_table1_2);
1014
$model = $dbi->create_model(table => $table1, updated_at => $key2);
1015
$param = {$key3 => 4};
cleanup
Yuki Kimoto authored on 2011-11-01
1016
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
1017
$model->update($param, where => {$key1 => 1});
1018
$result = $dbi->select(table => $table1);
1019
is_deeply($param, {$key3 => 4});
1020
$row   = $result->one;
1021
is($row->{$key3}, 4);
1022
like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
1023

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1024
test 'update_all';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1025
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1026
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
1027
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
1028
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1029
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
1030
$dbi->update_all({$key2 => 10}, table => $table1, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1031
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1032
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1033
is_deeply($rows, [{$key1 => 1, $key2 => 20, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
1034
  {$key1 => 6, $key2 => 20, $key3 => 8, $key4 => 9, $key5 => 10}],
1035
  "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1036

            
1037
test 'delete';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1038
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1039
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1040
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1041
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1042
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1043
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1044
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1045
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "basic");
test cleanup
Yuki Kimoto authored on 2011-08-10
1046

            
cleanup test
Yuki Kimoto authored on 2011-08-15
1047
$dbi->execute("delete from $table1");
test cleanup
Yuki Kimoto authored on 2011-11-01
1048
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1049
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1050
$dbi->register_filter(twice => sub { $_[0] * 2 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1051
$dbi->delete(table => $table1, where => {$key2 => 1}, filter => {$key2 => 'twice'});
cleanup test
Yuki Kimoto authored on 2011-08-15
1052
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1053
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1054
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1055

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1058
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1059
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1060
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1061
$dbi->delete(table => $table1, where => {$key1 => 1, $key2 => 2});
1062
$rows = $dbi->select(table => $table1)->all;
1063
is_deeply($rows, [{$key1 => 3, $key2 => 4}], "delete multi key");
test cleanup
Yuki Kimoto authored on 2011-08-10
1064

            
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
Yuki Kimoto authored on 2011-08-10
1069
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1070
$where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1071
$where->param({ke1 => 1, $key2 => 2});
1072
$dbi->delete(table => $table1, where => $where);
1073
$result = $dbi->select(table => $table1);
1074
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1075

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1076
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1077
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1078
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1079
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1080
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
1081
  table => $table1,
1082
  where => [
1083
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1084
    {ke1 => 1, $key2 => 2}
1085
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1086
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1087
$result = $dbi->select(table => $table1);
1088
is_deeply($result->all, [{$key1 => 3, $key2 => 4}], 'delete() where');
test cleanup
Yuki Kimoto authored on 2011-08-10
1089

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1090
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1091
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1092
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1093
$dbi->delete(table => $table1, where => {$key1 => 1}, prefix => '    ');
cleanup test
Yuki Kimoto authored on 2011-08-15
1094
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1095
$rows   = $result->all;
1096
is_deeply($rows, [], "basic");
1097

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1107
$dbi = undef;
test cleanup
Yuki Kimoto authored on 2011-08-10
1108
$dbi = DBIx::Custom->connect;
1109
eval { $dbi->execute("drop table ${q}table$p") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1110
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1111
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1112
$dbi->insert({select => 1}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1113
$dbi->delete(table => 'table', where => {select => 1});
1114
$result = $dbi->execute("select * from ${q}table$p");
1115
$rows   = $result->all;
1116
is_deeply($rows, [], "reserved word");
1117

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

            
1128
test 'select';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1129
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1130
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1131
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1132
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1133
$rows = $dbi->select(table => $table1)->all;
1134
is_deeply($rows, [{$key1 => 1, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
1135
  {$key1 => 3, $key2 => 4}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
1136

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1151
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1152
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
1153
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1154
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1155
  table => [$table1, $table2],
1156
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
1157
  where   => {"$table1.$key2" => 2},
1158
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1159
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1160
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
1161

            
1162
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1163
  table => [$table1, $table2],
1164
  column => ["$table1.$key1 as ${table1}_$key1", "${table2}.$key1 as ${table2}_$key1", $key2, $key3],
1165
  relation  => {"$table1.$key1" => "$table2.$key1"}
test cleanup
Yuki Kimoto authored on 2011-08-10
1166
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1167
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
1168

            
1169
$dbi = DBIx::Custom->connect;
test cleanup
Yuki Kimoto authored on 2011-08-10
1170
eval { $dbi->execute("drop table ${q}table$p") };
1171
$dbi->execute($create_table_reserved);
test cleanup
Yuki Kimoto authored on 2011-08-10
1172
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
cleanup
Yuki Kimoto authored on 2011-11-01
1173
$dbi->insert({select => 1, update => 2}, table => 'table');
test cleanup
Yuki Kimoto authored on 2011-08-10
1174
$result = $dbi->select(table => 'table', where => {select => 1});
1175
$rows   = $result->all;
1176
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
1177

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
1178
eval { $dbi->execute("drop table $table1") };
1179
$dbi->execute($create_table1);
1180
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1181
$row = $dbi->select($key1, table => $table1)->one;
1182
is_deeply($row, {$key1 => 1});
1183

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1184
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1185
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1186
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1187
  twice       => sub { $_[0] * 2 },
1188
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1189
);
1190
$dbi->default_fetch_filter('twice');
1191
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1192
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1193
$result = $dbi->select(table => $table1);
1194
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1195
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1196
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1197

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1198
$dbi->default_fetch_filter('twice');
1199
eval { $dbi->execute("drop table $table1") };
1200
$dbi->execute($create_table1);
1201
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1202
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1203
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1204
$row = $result->fetch_one;
1205
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1206

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1213
test 'filters';
1214
$dbi = DBIx::Custom->new;
1215

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1222
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1223
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1224
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1225
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1226
$dbi->begin_work;
1227
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1228
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1229
$dbi->rollback;
1230
$dbi->dbh->{AutoCommit} = 1;
1231

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

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

            
1236
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1237
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1238
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1239
$dbi->begin_work;
1240
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1241
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1242
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1243
$dbi->commit;
1244
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1245
$result = $dbi->select(table => $table1);
1246
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1247
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1248

            
1249
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1250
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1251
$dbi->execute($create_table1);
1252
{
cleanup
Yuki Kimoto authored on 2012-01-20
1253
  local $Carp::Verbose = 0;
1254
  eval{$dbi->execute("select * frm $table1")};
1255
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1256
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1257
}
1258
{
cleanup
Yuki Kimoto authored on 2012-01-20
1259
  local $Carp::Verbose = 1;
1260
  eval{$dbi->execute("select * frm $table1")};
1261
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1262
}
1263

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

            
1269
{
cleanup
Yuki Kimoto authored on 2012-01-20
1270
  local $Carp::Verbose = 0;
1271
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1272
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1273
}
1274
{
cleanup
Yuki Kimoto authored on 2012-01-20
1275
  local $Carp::Verbose = 1;
1276
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1277
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1278
}
1279

            
1280

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1281
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1282
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1283
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1284
$dbi->execute($create_table1);
1285

            
1286
$dbi->begin_work;
1287

            
1288
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1289
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1290
  die "Error";
1291
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1292
};
1293

            
1294
$dbi->rollback if $@;
1295

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

            
1300
$dbi->begin_work;
1301

            
1302
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1303
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1304
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1305
};
1306

            
1307
$dbi->commit unless $@;
1308

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

            
1313
$dbi->dbh->{AutoCommit} = 0;
1314
eval{ $dbi->begin_work };
1315
ok($@, "exception");
1316
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1317

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1318
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1319
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1320
$dbi->cache(1);
1321
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1322
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1323
$dbi->execute($source, {}, query => 1);
1324
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1325
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1326

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1327
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1328
$dbi->execute($create_table1);
1329
$dbi->{_cached} = {};
1330
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1331
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1332
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1333

            
1334
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1335
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1336
$dbi->execute($create_table1);
1337
{
cleanup
Yuki Kimoto authored on 2012-01-20
1338
  local $Carp::Verbose = 0;
1339
  eval{$dbi->execute("select * frm $table1")};
1340
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1341
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1342
}
1343
{
cleanup
Yuki Kimoto authored on 2012-01-20
1344
  local $Carp::Verbose = 1;
1345
  eval{$dbi->execute("select * frm $table1")};
1346
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1347
}
1348

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

            
1354
{
cleanup
Yuki Kimoto authored on 2012-01-20
1355
  local $Carp::Verbose = 0;
1356
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1357
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1358
}
1359
{
cleanup
Yuki Kimoto authored on 2012-01-20
1360
  local $Carp::Verbose = 1;
1361
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1362
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1363
}
1364

            
1365
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1366
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1367
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1368
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1369
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1370
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1371
);
1372
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1373
  twice => sub {
1374
    my $self = shift;
1375
    return $_[0] * 2;
1376
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1377
});
1378

            
1379
is($dbi->one, 1, "first");
1380
is($dbi->two, 2, "second");
1381
is($dbi->twice(5), 10 , "second");
1382

            
1383
eval {$dbi->XXXXXX};
1384
ok($@, "not exists");
1385

            
1386
test 'out filter';
1387
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1388
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1389
$dbi->execute($create_table1);
1390
$dbi->register_filter(twice => sub { $_[0] * 2 });
1391
$dbi->register_filter(three_times => sub { $_[0] * 3});
1392
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1393
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1394
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1395
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1396
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1397
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1398
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1399
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1400
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1401
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1402

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

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

            
1424
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1425
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1426
$dbi->execute($create_table1);
1427
$dbi->register_filter(twice => sub { $_[0] * 2 });
1428
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1429
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1430
);
cleanup
Yuki Kimoto authored on 2011-11-01
1431
$dbi->insert({$key1 => 1, $key2 => 2},table => $table1, filter => {$key1 => undef});
1432
$dbi->update({$key1 => 2}, table => $table1, where => {$key2 => 2});
cleanup test
Yuki Kimoto authored on 2011-08-15
1433
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1434
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1435
is_deeply($row, {$key1 => 4, $key2 => 2}, "update");
test cleanup
Yuki Kimoto authored on 2011-08-10
1436

            
1437
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1438
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1439
$dbi->execute($create_table1);
1440
$dbi->register_filter(twice => sub { $_[0] * 2 });
1441
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1442
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
);
cleanup
Yuki Kimoto authored on 2011-11-01
1444
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1=> undef});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1445
$dbi->delete(table => $table1, where => {$key1 => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
1446
$result = $dbi->execute("select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
1447
$rows   = $result->all;
1448
is_deeply($rows, [], "delete");
1449

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

            
1463
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1464
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1465
$dbi->execute($create_table1);
1466
$dbi->register_filter(twice => sub { $_[0] * 2 });
1467
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1468
  $table1, $key1 => {out => 'twice', in => 'twice'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1469
);
cleanup
Yuki Kimoto authored on 2011-11-01
1470
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1, filter => {$key1 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1471
$result = $dbi->execute("select * from $table1 where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1472
  {$key1 => 1, $key2 => 2},
1473
  table => [$table1]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1474
$rows   = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1475
is_deeply($rows, [{$key1 => 4, $key2 => 2}], "execute");
test cleanup
Yuki Kimoto authored on 2011-08-10
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});
cleanup test
Yuki Kimoto authored on 2011-08-15
1485
$result = $dbi->execute("select * from {table $table1} where $key1 = :$key1 and $key2 = :$key2",
cleanup
Yuki Kimoto authored on 2012-01-20
1486
  {$key1 => 1, $key2 => 2});
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 => 2}], "execute table tag");
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") };
1492
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1493
$dbi->execute($create_table1);
1494
$dbi->execute($create_table2);
1495
$dbi->register_filter(twice => sub { $_[0] * 2 });
1496
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1497
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1498
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1499
);
1500
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1501
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
);
cleanup
Yuki Kimoto authored on 2011-11-01
1503
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1504
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1505
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1506
  table => [$table1, $table2],
1507
  column => [$key2, $key3],
1508
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1509

            
1510
$result->filter({$key2 => 'twice'});
1511
$rows   = $result->all;
1512
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1513

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

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

            
1523
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1524
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1525
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1526
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1527
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1528
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1529

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1530
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1531
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1532
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1534
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1535
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1536

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

            
1543
test 'end_filter';
1544
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1545
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1546
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1547
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1548
$result = $dbi->select(table => $table1);
1549
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1550
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1551
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1552
is_deeply($row, [6, 40]);
1553

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1554
$dbi = DBIx::Custom->connect;
1555
eval { $dbi->execute("drop table $table1") };
1556
$dbi->execute($create_table1);
1557
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1558
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1559
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1560
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1561
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1562
is_deeply($row, [6, 6, 40]);
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
$result = $dbi->select(table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1569
$result->filter([$key1, $key2] => sub { $_[0] * 2 });
1570
$result->end_filter([[$key1, $key2] => sub { $_[0] * 3 }]);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1571
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1572
is_deeply($row, [6, 12]);
1573

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

            
1584
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1585
$result = $dbi->select(table => $table1);
1586
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1587
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1588
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1589
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1590

            
1591
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1592
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1593
  $key1 => {end => sub { $_[0] * 3 } },
1594
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1595
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1596
$result = $dbi->select(table => $table1);
1597
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1598
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1599
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1600

            
1601
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1602
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1603
  $key1 => {end => sub { $_[0] * 3 } },
1604
  $key2 => {end => 'five_times'}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1605
);
1606
$result = $dbi->select(table => $table1);
1607
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1608
$result->filter($key1 => undef);
1609
$result->end_filter($key1 => undef);
test cleanup
Yuki Kimoto authored on 2011-08-10
1610
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1611
is_deeply($row, {$key1 => 1, $key2 => 40}, 'apply_filter overwrite');
test cleanup
Yuki Kimoto authored on 2011-08-10
1612

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1613
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1614
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1615
$result->filter($key1 => undef);
1616
$result->end_filter($key1 => undef);
1617
$row = $result->fetch;
1618
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1619

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1620
test 'remove_end_filter and remove_filter';
1621
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1622
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1623
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1624
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1625
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1626
$row = $result
cleanup
Yuki Kimoto authored on 2012-01-20
1627
  ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
1628
  ->remove_filter
1629
  ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
1630
  ->remove_end_filter
1631
  ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1632
is_deeply($row, [1, 2]);
1633

            
1634
test 'empty where select';
1635
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1636
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1637
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1638
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1639
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1640
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1641
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1642

            
1643
test 'select query option';
1644
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1645
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1646
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1647
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1648
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1649
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1650
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1651
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1652
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1653
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1654
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1655

            
1656
test 'where';
1657
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1658
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1659
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1660
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1661
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1662
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1663
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1664

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

            
1669
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1670
  table => $table1,
1671
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
);
1673
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1674
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1675

            
1676
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1677
  table => $table1,
1678
  where => [
1679
    ['and', "$key1 = :$key1", "$key2 = :$key2"],
1680
    {$key1 => 1}
1681
  ]
test cleanup
Yuki Kimoto authored on 2011-08-10
1682
);
1683
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1684
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1685

            
1686
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1687
  ->clause(['and', "$key1 = :$key1", "$key2 = :$key2"])
1688
  ->param({$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1689
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1690
  table => $table1,
1691
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1692
);
1693
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1694
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1695

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

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

            
1716
$where = $dbi->where;
1717
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1718
  table => $table1,
1719
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1720
);
1721
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1722
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1723

            
1724
eval {
1725
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1726
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1727
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1728
  table => $table1,
1729
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1730
);
1731
};
1732
ok($@);
1733

            
1734
$where = $dbi->where;
1735
is("$where", '');
1736

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

            
1747
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1748
   ->clause(['or', ("$key1 = :$key1") x 2])
1749
   ->param({$key1 => [1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
1750
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1751
  table => $table1,
1752
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1753
);
1754
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1755
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1756

            
1757
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1758
  ->clause(['or', ("$key1 = :$key1") x 2])
1759
  ->param({$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1760
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1761
  table => $table1,
1762
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
1763
);
1764
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1765
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1766

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1906
eval {$dbi->where(ppp => 1) };
1907
like($@, qr/invalid/);
1908

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

            
1920

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

            
1932
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1933
$where->clause(['and', ":${key1}{=}"]);
1934
$where->param({$key1 => undef});
1935
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
1936
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1937
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1938

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

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

            
1950
$dbi = DBIx::Custom->connect;
1951
eval { $dbi->execute("drop table $table1") };
1952
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1953
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
1954
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1955
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1956
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
1957
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1958

            
1959
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1960
  table => $table1,
1961
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
1962
);
1963
$row = $result->all;
1964
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
1965

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1966
test 'register_tag_processor';
1967
$dbi = DBIx::Custom->connect;
1968
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
1969
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1970
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1971
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1972

            
1973
test 'register_tag';
1974
$dbi = DBIx::Custom->connect;
1975
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
1976
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1977
);
test cleanup
Yuki Kimoto authored on 2011-08-10
1978
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
1979

            
1980
test 'table not specify exception';
1981
$dbi = DBIx::Custom->connect;
1982
eval {$dbi->select};
1983
like($@, qr/table/);
test cleanup
Yuki Kimoto authored on 2011-08-10
1984

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1985
test 'more tests';
1986
$dbi = DBIx::Custom->connect;
1987
eval{$dbi->apply_filter('table', 'column', [])};
1988
like($@, qr/apply_filter/);
1989

            
1990
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1991
like($@, qr/apply_filter/);
1992

            
1993
$dbi->apply_filter(
1994

            
1995
);
1996
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1997
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1998
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1999
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2000
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2001
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2002
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2003
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2004
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2005

            
2006
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2007
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2008
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2009
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2010
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2011
$dbi->apply_filter($table1, $key2, {});
2012
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2013
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2014

            
2015
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2016
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2017
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2018
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2019
like($@, qr/not registered/);
2020
$dbi->method({one => sub { 1 }});
2021
is($dbi->one, 1);
2022

            
2023
eval{DBIx::Custom->connect(dsn => undef)};
2024
like($@, qr/_connect/);
2025

            
2026
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2027
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2028
$dbi->execute($create_table1);
2029
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2030
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2031
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2032
$row = $dbi->select(table => $table1)->one;
2033
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2034
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2035
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2036
like($@, qr//);
2037

            
2038
$dbi->register_filter(one => sub { });
2039
$dbi->default_fetch_filter('one');
2040
ok($dbi->default_fetch_filter);
2041
$dbi->default_bind_filter('one');
2042
ok($dbi->default_bind_filter);
2043
eval{$dbi->default_fetch_filter('no')};
2044
like($@, qr/not registered/);
2045
eval{$dbi->default_bind_filter('no')};
2046
like($@, qr/not registered/);
2047
$dbi->default_bind_filter(undef);
2048
ok(!defined $dbi->default_bind_filter);
2049
$dbi->default_fetch_filter(undef);
2050
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2051
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2052
like($@, qr/Tag not finished/);
2053

            
2054
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2055
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2056
$dbi->execute($create_table1);
2057
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2058
$result = $dbi->select(table => $table1);
2059
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2060
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2061
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2062
like($@, qr/not registered/);
2063
$result->default_filter(undef);
2064
ok(!defined $result->default_filter);
2065
$result->default_filter('one');
2066
is($result->default_filter->(), 1);
2067

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2068
test 'option';
2069
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2070
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2071
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2072
ok($dbi->dbh->{PrintError});
2073
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2074
ok($dbi->dbh->{PrintError});
2075

            
2076
test 'DBIx::Custom::Result stash()';
2077
$result = DBIx::Custom::Result->new;
2078
is_deeply($result->stash, {}, 'default');
2079
$result->stash->{foo} = 1;
2080
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2081

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2082
test 'delete_at';
2083
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2084
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2085
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2086
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2087
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2088
  table => $table1,
2089
  primary_key => [$key1, $key2],
2090
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2091
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2092
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2093

            
cleanup
Yuki Kimoto authored on 2011-11-01
2094
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2095
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2096
  table => $table1,
2097
  primary_key => $key1,
2098
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2099
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2100
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2101

            
2102
test 'insert_at';
2103
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2104
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
$dbi->execute($create_table1_2);
2106
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2107
  {$key3 => 3},
2108
  primary_key => [$key1, $key2], 
2109
  table => $table1,
2110
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2111
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2112
is($dbi->select(table => $table1)->one->{$key1}, 1);
2113
is($dbi->select(table => $table1)->one->{$key2}, 2);
2114
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2115

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2116
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2117
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2118
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2119
  {$key2 => 2, $key3 => 3},
2120
  primary_key => $key1, 
2121
  table => $table1,
2122
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2123
);
2124

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

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

            
2142
test 'update_at';
2143
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2144
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2145
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2146
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2147
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2148
  {$key3 => 4},
2149
  table => $table1,
2150
  primary_key => [$key1, $key2],
2151
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2152
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2153
is($dbi->select(table => $table1)->one->{$key1}, 1);
2154
is($dbi->select(table => $table1)->one->{$key2}, 2);
2155
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2156

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2157
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2158
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2159
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2160
  {$key3 => 4},
2161
  table => $table1,
2162
  primary_key => $key1,
2163
  where => 1,
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}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2168

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

            
2183
test 'select_at';
2184
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2185
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2186
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2187
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2188
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2189
  table => $table1,
2190
  primary_key => [$key1, $key2],
2191
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2192
);
2193
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2194
is($row->{$key1}, 1);
2195
is($row->{$key2}, 2);
2196
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2197

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2198
$dbi->delete_all(table => $table1);
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
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2201
  table => $table1,
2202
  primary_key => $key1,
2203
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2204
);
2205
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2206
is($row->{$key1}, 1);
2207
is($row->{$key2}, 2);
2208
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2209

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2210
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2211
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2212
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2213
  table => $table1,
2214
  primary_key => [$key1, $key2],
2215
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2216
);
2217
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2218
is($row->{$key1}, 1);
2219
is($row->{$key2}, 2);
2220
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2221

            
2222
test 'model delete_at';
2223
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2224
eval { $dbi->execute("drop table $table1") };
2225
eval { $dbi->execute("drop table $table2") };
2226
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2227
$dbi->execute($create_table1_2);
2228
$dbi->execute($create_table2_2);
2229
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2230
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
$dbi->model($table1)->delete_at(where => [1, 2]);
2232
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2233
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2234
$dbi->model($table1)->delete_at(where => [1, 2]);
2235
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2236
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2237
$dbi->model($table3)->delete_at(where => [1, 2]);
2238
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2239

            
2240
test 'model insert_at';
2241
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2242
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2243
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2244
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2245
  {$key3 => 3},
2246
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2247
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2248
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2249
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2250
is($row->{$key1}, 1);
2251
is($row->{$key2}, 2);
2252
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2253

            
2254
test 'model update_at';
2255
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2256
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2258
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2259
$dbi->model($table1)->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2260
  {$key3 => 4},
2261
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2262
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2263
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2264
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2265
is($row->{$key1}, 1);
2266
is($row->{$key2}, 2);
2267
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2268

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

            
2280

            
2281
test 'mycolumn and column';
2282
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2283
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2284
eval { $dbi->execute("drop table $table1") };
2285
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2286
$dbi->execute($create_table1);
2287
$dbi->execute($create_table2);
2288
$dbi->separator('__');
2289
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2290
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2291
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2292
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2293
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2294
  column => [$model->mycolumn, $model->column($table2)],
2295
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2296
);
2297
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2298
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2299

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2300
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2301
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2302
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2303
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2304
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2305
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2306
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2307
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2308
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2309
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2310
is($dbi->select(table => $table1)->one->{$key1}, 1);
2311
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2312

            
2313
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2314
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2315
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2316
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2317
$values_clause = $dbi->insert_param($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2318
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2319
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2320
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2321
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2322
is($dbi->select(table => $table1)->one->{$key1}, 1);
2323
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2324

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2325
test 'mycolumn';
2326
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2327
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2328
eval { $dbi->execute("drop table $table1") };
2329
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2330
$dbi->execute($create_table1);
2331
$dbi->execute($create_table2);
2332
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2333
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2334
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2335
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2336
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2337
  column => [
2338
    $model->mycolumn,
2339
    $model->column($table2)
2340
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2341
);
2342
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2343
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2344

            
2345
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2346
  column => [
2347
    $model->mycolumn([$key1]),
2348
    $model->column($table2 => [$key1])
2349
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2350
);
2351
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2352
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2353
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2354
  column => [
2355
    $model->mycolumn([$key1]),
2356
    {$table2 => [$key1]}
2357
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2358
);
2359
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2360
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2361

            
2362
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2363
  column => [
2364
    $model->mycolumn([$key1]),
2365
    ["$table2.$key1", as => "$table2.$key1"]
2366
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2367
);
2368
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2369
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2370

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2380
test 'merge_param';
2381
$dbi = DBIx::Custom->new;
2382
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2383
  {$key1 => 1, $key2 => 2, $key3 => 3},
2384
  {$key1 => 1, $key2 => 2},
2385
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2386
];
2387
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2388
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2389

            
2390
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2391
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2392
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2393
];
2394
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2395
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
2396

            
2397
test 'select() param option';
2398
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2399
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2400
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2401
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2402
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2403
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2404
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2405
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2406
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2407
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2408
  table => $table1,
2409
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2410
  where   => {"$table1.$key2" => 3},
2411
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2412
            " $table2 on $table1.$key1 = $table2.$key1"],
2413
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2414
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2415
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2416

            
cleanup
Yuki Kimoto authored on 2011-10-21
2417
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2418
  table => $table1,
2419
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2420
  where   => {"$table1.$key2" => 3},
2421
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2422
           " $table2 on $table1.$key1 = $table2.$key1",
2423
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2424
)->all;
2425
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2426

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2427
test 'select() string where';
2428
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2429
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2430
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2431
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2432
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2433
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2434
  table => $table1,
2435
  where => "$key1 = :$key1 and $key2 = :$key2",
2436
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2437
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2438
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2439

            
2440
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2441
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2442
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2443
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2444
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2445
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2446
  table => $table1,
2447
  where => [
2448
    "$key1 = :$key1 and $key2 = :$key2",
2449
    {$key1 => 1, $key2 => 2}
2450
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2451
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2452
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2453

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

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

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

            
2497

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

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

            
2527
test 'insert id and primary_key option';
2528
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2529
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2530
$dbi->execute($create_table1_2);
2531
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2532
  {$key3 => 3},
2533
  primary_key => [$key1, $key2], 
2534
  table => $table1,
2535
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2536
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2537
is($dbi->select(table => $table1)->one->{$key1}, 1);
2538
is($dbi->select(table => $table1)->one->{$key2}, 2);
2539
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2540

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2541
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2542
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2543
  {$key2 => 2, $key3 => 3},
2544
  primary_key => $key1, 
2545
  table => $table1,
2546
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2547
);
2548

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2553
$dbi = DBIx::Custom->connect;
2554
eval { $dbi->execute("drop table $table1") };
2555
$dbi->execute($create_table1_2);
2556
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2557
  {$key3 => 3},
2558
  primary_key => [$key1, $key2], 
2559
  table => $table1,
2560
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2561
);
2562
is($dbi->select(table => $table1)->one->{$key1}, 1);
2563
ok(!$dbi->select(table => $table1)->one->{$key2});
2564
is($dbi->select(table => $table1)->one->{$key3}, 3);
2565

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2566
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2567
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2568
$dbi->execute($create_table1_2);
2569
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2570
  {$key3 => 3},
2571
  primary_key => [$key1, $key2], 
2572
  table => $table1,
2573
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2575
is($dbi->select(table => $table1)->one->{$key1}, 1);
2576
is($dbi->select(table => $table1)->one->{$key2}, 2);
2577
is($dbi->select(table => $table1)->one->{$key3}, 3);
test cleanup
Yuki Kimoto authored on 2011-08-10
2578

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2579
$dbi = DBIx::Custom->connect;
2580
eval { $dbi->execute("drop table $table1") };
2581
$dbi->execute($create_table1_2);
2582
$param = {$key3 => 3, $key2 => 4};
2583
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2584
  $param,
2585
  primary_key => [$key1, $key2], 
2586
  table => $table1,
2587
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2588
);
2589
is($dbi->select(table => $table1)->one->{$key1}, 1);
2590
is($dbi->select(table => $table1)->one->{$key2}, 4);
2591
is($dbi->select(table => $table1)->one->{$key3}, 3);
2592
is_deeply($param, {$key3 => 3, $key2 => 4});
2593

            
added test
Yuki Kimoto authored on 2011-10-25
2594
$dbi = DBIx::Custom->connect;
2595
eval { $dbi->execute("drop table $table1") };
2596
$dbi->execute($create_table1_2);
2597
$param = {$key3 => 3, $key2 => 4};
2598
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2599
  $param,
2600
  primary_key => [$key1, $key2], 
2601
  table => $table1,
2602
  id => [1, 2],
2603
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2604
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2605
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2606
is_deeply($param, {$key3 => 3, $key2 => 4});
2607

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2608
test 'model insert id and primary_key option';
2609
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2610
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2611
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2612
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2613
  {$key3 => 3},
2614
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2615
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2616
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2617
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2618
is($row->{$key1}, 1);
2619
is($row->{$key2}, 2);
2620
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2621

            
2622
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2623
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2624
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2625
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2626
  {$key3 => 3},
2627
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2628
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2629
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2630
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2631
is($row->{$key1}, 1);
2632
is($row->{$key2}, 2);
2633
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2634

            
2635
test 'update and id option';
2636
$dbi = DBIx::Custom->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);
cleanup
Yuki Kimoto authored on 2011-11-01
2639
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2640
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2641
  {$key3 => 4},
2642
  table => $table1,
2643
  primary_key => [$key1, $key2],
2644
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2645
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2646
is($dbi->select(table => $table1)->one->{$key1}, 1);
2647
is($dbi->select(table => $table1)->one->{$key2}, 2);
2648
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2649

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2650
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2651
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2652
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2653
  {$key3 => 4},
2654
  table => $table1,
2655
  primary_key => $key1,
2656
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2657
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2658
is($dbi->select(table => $table1)->one->{$key1}, 0);
2659
is($dbi->select(table => $table1)->one->{$key2}, 2);
2660
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2661

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

            
2676

            
2677
test 'model update and id option';
2678
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2679
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2680
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2681
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2682
$dbi->model($table1)->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2683
  {$key3 => 4},
2684
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2685
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2686
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2687
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2688
is($row->{$key1}, 1);
2689
is($row->{$key2}, 2);
2690
is($row->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2691

            
2692

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

            
cleanup
Yuki Kimoto authored on 2011-11-01
2705
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2706
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2707
  table => $table1,
2708
  primary_key => $key1,
2709
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2710
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2711
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2712

            
2713

            
2714
test 'model delete and id option';
2715
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2716
eval { $dbi->execute("drop table $table1") };
2717
eval { $dbi->execute("drop table $table2") };
2718
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2719
$dbi->execute($create_table1_2);
2720
$dbi->execute($create_table2_2);
2721
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2722
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2723
$dbi->model($table1)->delete(id => [1, 2]);
2724
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2725
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2726
$dbi->model($table1)->delete(id => [1, 2]);
2727
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2728
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2729
$dbi->model($table3)->delete(id => [1, 2]);
2730
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2731

            
2732

            
2733
test 'select and id option';
2734
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2735
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2736
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2737
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2738
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2739
  table => $table1,
2740
  primary_key => [$key1, $key2],
2741
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2742
);
2743
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2744
is($row->{$key1}, 1);
2745
is($row->{$key2}, 2);
2746
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2747

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2748
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2749
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2750
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2751
  table => $table1,
2752
  primary_key => $key1,
2753
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2754
);
2755
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2756
is($row->{$key1}, 0);
2757
is($row->{$key2}, 2);
2758
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2759

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2760
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2761
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2762
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2763
  table => $table1,
2764
  primary_key => [$key1, $key2],
2765
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2766
);
2767
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2768
is($row->{$key1}, 1);
2769
is($row->{$key2}, 2);
2770
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2771

            
2772

            
2773
test 'model select_at';
2774
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2775
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2776
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2777
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2778
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2779
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2780
is($row->{$key1}, 1);
2781
is($row->{$key2}, 2);
2782
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2783

            
2784
test 'column separator is default .';
2785
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2786
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2787
eval { $dbi->execute("drop table $table1") };
2788
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2789
$dbi->execute($create_table1);
2790
$dbi->execute($create_table2);
2791
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2792
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2793
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2794
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2795
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2796
  column => [$model->column($table2)],
2797
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2798
);
2799
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2800
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2801

            
2802
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2803
  column => [$model->column($table2 => [$key1, $key3])],
2804
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2805
);
2806
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2807
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2808

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2809
test 'separator';
2810
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2811
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2812
eval { $dbi->execute("drop table $table1") };
2813
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2814
$dbi->execute($create_table1);
2815
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2816

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2817
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2818
  table => $table1,
2819
  join => [
2820
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2821
  ],
2822
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2823
);
2824
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2825
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2826
);
2827
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2828
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2829
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2830
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2831
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2832
  column => [
2833
    $model->mycolumn,
2834
    {$table2 => [$key1, $key3]}
2835
  ],
2836
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2837
);
2838
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2839
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2840
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2841

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2842
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2843
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2844
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2845
  column => [
2846
    $model->mycolumn,
2847
    {$table2 => [$key1, $key3]}
2848
  ],
2849
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2850
);
2851
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2852
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2853
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2854

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2855
$dbi->separator('-');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2856
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2857
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2858
  column => [
2859
    $model->mycolumn,
2860
    {$table2 => [$key1, $key3]}
2861
  ],
2862
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2863
);
2864
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2865
  {$key1 => 1, $key2 => 2, "$table2-$key1" => 1, "$table2-$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2866
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2867

            
2868

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2869
test 'filter_off';
2870
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2871
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2872
eval { $dbi->execute("drop table $table1") };
2873
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2874
$dbi->execute($create_table1);
2875
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2876

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2877
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2878
  table => $table1,
2879
  join => [
2880
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2881
  ],
2882
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2883
);
2884
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2885
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2886
$model = $dbi->model($table1);
2887
$result = $model->select(column => $key1);
2888
$result->filter($key1 => sub { $_[0] * 2 });
2889
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
2890

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2891
test 'available_datetype';
2892
$dbi = DBIx::Custom->connect;
2893
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
2894

            
2895

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2896
test 'select prefix option';
2897
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2898
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2899
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2900
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2901
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2902
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
2903

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

            
added tests
Yuki Kimoto authored on 2011-08-26
2905
test 'mapper';
2906
$dbi = DBIx::Custom->connect;
2907
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2908
  id => {key => "$table1.id"},
2909
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2910
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
2911
);
2912
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2913
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
2914

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2915
$dbi = DBIx::Custom->connect;
2916
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2917
  id => {key => "$table1.id"},
2918
  author => ["$table1.author" => $dbi->like_value],
2919
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2920
);
2921
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
2922
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2923

            
added tests
Yuki Kimoto authored on 2011-08-26
2924
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2925
  id => {key => "$table1.id"},
2926
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2927
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
added tests
Yuki Kimoto authored on 2011-08-26
2928
);
2929
is_deeply($param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
2930

            
2931
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2932
  id => {key => "$table1.id"},
2933
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
2934
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
2935
);
2936
is_deeply($param, {});
2937

            
2938
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2939
  id => {key => "$table1.id"},
2940
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
2941
);
2942
is_deeply($param, {"$table1.price" => undef});
2943

            
2944
$param = $dbi->mapper(param => {price => 'a'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2945
  id => {key => "$table1.id", condition => 'exists'},
2946
  price => ["$table1.price", sub { '%' . $_[0] }, 'exists']
added tests
Yuki Kimoto authored on 2011-08-26
2947
);
2948
is_deeply($param, {"$table1.price" => '%a'});
2949

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2956
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
2957
  price => sub { '%' . $_[0] },
2958
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2959
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
2960
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
2961

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

            
2967
$where = $dbi->where;
2968
$where->clause(['and', ":${key1}{=}"]);
2969
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
2970
$where->param($param);
2971
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
2972
$row = $result->all;
2973
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2974

            
2975
$where = $dbi->where;
2976
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2977
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
2978
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2979
$row = $result->all;
2980
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2981
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2982
$row = $result->all;
2983
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2984

            
2985
$where = $dbi->where;
2986
$where->clause(['and', ":${key1}{=}"]);
2987
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'defined')->map;
2988
$where->param($param);
2989
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
2990
$row = $result->all;
2991
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2992
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
2993
$row = $result->all;
2994
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
2995

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2997
$where = $dbi->where;
2998
$where->clause(['and', ":${key1}{=}"]);
2999
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3000
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3001
$where->param($param);
3002
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3003
$row = $result->all;
3004
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3005

            
3006
$where = $dbi->where;
3007
$where->clause(['and', ":${key1}{=}"]);
3008
$param = $dbi->mapper(param => {$key1 => ''}, condition => 'length')->map;
3009
$where->param($param);
3010
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3011
$row = $result->all;
3012
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3013

            
3014
$where = $dbi->where;
3015
$where->clause(['and', ":${key1}{=}"]);
3016
$param = $dbi->mapper(param => {$key1 => 5}, condition => sub { ($_[0] || '') eq 5 })
cleanup
Yuki Kimoto authored on 2012-01-20
3017
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3018
$where->param($param);
3019
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3020
$row = $result->all;
3021
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
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 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3027
$where->param($param);
3028
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3029
$row = $result->all;
3030
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3031

            
3032
$where = $dbi->where;
3033
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3034
  id => {key => "$table1.id"},
3035
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3036
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3037
);
3038
$where->param($param);
3039
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3040
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3041

            
3042
$where = $dbi->where;
3043
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3044
  id => {key => "$table1.id"},
3045
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3046
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3047
);
3048
$where->param($param);
3049
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3050

            
3051
$where = $dbi->where;
3052
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3053
  id => {key => "$table1.id"},
3054
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3055
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3056
);
3057
$where->param($param);
3058
is_deeply($where->param, {});
3059

            
3060
$where = $dbi->where;
3061
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3062
  id => {key => "$table1.id"},
3063
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3064
);
3065
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3066

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

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

            
3083
$where = $dbi->where;
3084
$param = $dbi->mapper(param => {id => ['', ''], author => 'Ken', price => 1900}, condition => 'length')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3085
  id => {key => "$table1.id"},
3086
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3087
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3088
);
3089
is_deeply($param, {"$table1.id" => [$dbi->not_exists, $dbi->not_exists], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3090
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3091

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3106
test 'order';
3107
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3108
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3109
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3110
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3111
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3112
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3113
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3114
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3115
$order->prepend($key1, "$key2 desc");
3116
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3117
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3118
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3119
$order->prepend("$key1 desc");
3120
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3121
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3122
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3123

            
3124
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3125
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3126
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3127
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3128
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3129
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3130
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3131
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3132
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3133

            
3134
test 'tag_parse';
3135
$dbi = DBIx::Custom->connect;
3136
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3137
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3138
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3139
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3140
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3141
ok($@);
3142

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3143
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3144
{
cleanup
Yuki Kimoto authored on 2012-01-20
3145
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3146
  $dbi = DBIx::Custom->connect;
3147
  eval { $dbi->execute("drop table $table1") };
3148
  $dbi->execute($create_table1);
3149
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3150
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3151
  ok($@);
3152
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3153
  ok($@);
3154
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3155
}
3156

            
3157
{
cleanup
Yuki Kimoto authored on 2012-01-20
3158
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3159
  $dbi = DBIx::Custom->connect;
3160
  eval { $dbi->execute("drop table $table1") };
3161
  $dbi->execute($create_table1);
3162
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3163
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3164
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3165
}
3166

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3167
test 'last_sql';
3168
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3169
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3170
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3171
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3172
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3173

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

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

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

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3205
$source = "select * from $table1 where :$table1.${key1}{=} and :$table1.${key2}{=}";
test cleanup
Yuki Kimoto authored on 2011-08-10
3206
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
3207
  $source,
3208
  {"$table1.$key1" => 1, "$table1.$key2" => 1},
3209
  filter => {"$table1.$key2" => sub { $_[0] * 2 }}
test cleanup
Yuki Kimoto authored on 2011-08-10
3210
);
3211
$rows = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3212
is_deeply($rows, [{$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3213

            
3214
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3215
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3216
$dbi->execute($create_table1_highperformance);
3217
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3218
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3219
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3220
];
3221
{
cleanup
Yuki Kimoto authored on 2012-01-20
3222
  my $query;
3223
  for my $row (@$rows) {
3224
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3225
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3226
  }
3227
  is_deeply($dbi->select(table => $table1)->all,
3228
    [
3229
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3230
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3231
    ]
3232
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3233
}
3234

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3235
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3236
$dbi->execute($create_table1_highperformance);
3237
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3238
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3239
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3240
];
3241
{
cleanup
Yuki Kimoto authored on 2012-01-20
3242
  my $query;
3243
  my $sth;
3244
  for my $row (@$rows) {
3245
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3246
    $sth ||= $query->{sth};
3247
    $sth->execute(map { $row->{$_} } sort keys %$row);
3248
  }
3249
  is_deeply($dbi->select(table => $table1)->all,
3250
    [
3251
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3252
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3253
    ]
3254
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3255
}
3256

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3257
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3258
$dbi->execute($create_table1_highperformance);
3259
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3260
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3261
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3262
];
3263
{
cleanup
Yuki Kimoto authored on 2012-01-20
3264
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3265
  my $query;
3266
  for my $row (@$rows) {
3267
    $query ||= $model->insert($row, query => 1);
3268
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3269
  }
3270
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3271
    [
3272
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3273
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3274
    ]
3275
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3276
}
3277

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3278
eval { $dbi->execute("drop table $table1") };
3279
$dbi->execute($create_table1);
3280
{
cleanup
Yuki Kimoto authored on 2012-01-20
3281
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3282
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3283
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3284
  like($@, qr/primary_key/);
3285
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3286
}
3287

            
3288
{
cleanup
Yuki Kimoto authored on 2012-01-20
3289
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3290
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3291
  $model->insert({$key1 => 1});
3292
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3293
    table => $table1, primary_key => $key1);
3294
  is($result->one->{$key1}, 1);
3295
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3296
}
3297

            
3298
eval { $dbi->execute("drop table $table1") };
3299
$dbi->execute($create_table1);
3300
{
cleanup
Yuki Kimoto authored on 2012-01-20
3301
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3302
  $model->insert({$key1 => 1});
3303
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3304
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3305
}
3306

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3307
test 'id option more';
3308
eval { $dbi->execute("drop table $table1") };
3309
$dbi->execute($create_table1_highperformance);
3310
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3311
  $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
3312
};
3313
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3314
$model->insert($row);
3315
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3316
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3317
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3318
  {$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
3319
);
3320

            
3321
eval { $dbi->execute("drop table $table1") };
3322
eval { $dbi->execute("drop table $table2") };
3323
$dbi->execute($create_table1);
3324
$dbi->execute($create_table2);
3325
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3326
$model->insert({$key1 => 1, $key2 => 2});
3327
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3329
$model->insert({$key1 => 1, $key3 => 3});
3330
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3331
  column => {$table1 => ["$key2"]},
3332
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3333
);
3334
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3335

            
3336
eval { $dbi->execute("drop table $table1") };
3337
$dbi->execute($create_table1_highperformance);
3338
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3339
  $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
3340
};
3341
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3342
$model->insert($row);
3343
$query = $model->delete(id => 1, query => 1);
3344
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3345
is_deeply($dbi->select(table => $table1)->all, []);
3346

            
3347
eval { $dbi->execute("drop table $table1") };
3348
eval { $dbi->execute($create_table1_highperformance) };
3349
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3350
  $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
3351
};
3352
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3353
$model->insert($row);
3354
$query = $model->select(id => 1, query => 1);
3355
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3356
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3357
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3358
  {$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
3359
);
3360

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3361
test 'result';
3362
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3363
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3364
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3365
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3366
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3367

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3368
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3369
@rows = ();
3370
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3371
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3372
}
3373
is_deeply(\@rows, [[1, 2], [3, 4]]);
3374

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3375
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3376
@rows = ();
3377
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3378
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3379
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3380
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3381

            
3382
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3383
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3384
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3385
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3386
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3387

            
3388
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3389
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3390
$rows = $result->fetch_all;
3391
is_deeply($rows, [[1, 2], [3, 4]]);
3392

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3397
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3398
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3399
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3400
$rows = $result->fetch_all;
3401
is_deeply($rows, [[3, 2], [9, 4]], "array");
3402

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3415
test 'DBIx::Custom::Result fetch_multi';
3416
eval { $dbi->execute("drop table $table1") };
3417
$dbi->execute($create_table1);
3418
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3419
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3420
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3421
$result = $dbi->select(table => $table1);
3422
$rows = $result->fetch_multi(2);
3423
is_deeply($rows, [[1, 2], [3, 4]]);
3424
$rows = $result->fetch_multi(2);
3425
is_deeply($rows, [[5, 6]]);
3426
$rows = $result->fetch_multi(2);
3427
ok(!$rows);
3428

            
3429
test 'DBIx::Custom::Result fetch_hash_multi';
3430
eval { $dbi->execute("drop table $table1") };
3431
$dbi->execute($create_table1);
3432
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3433
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3434
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3435
$result = $dbi->select(table => $table1);
3436
$rows = $result->fetch_hash_multi(2);
3437
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3438
$rows = $result->fetch_hash_multi(2);
3439
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3440
$rows = $result->fetch_hash_multi(2);
3441
ok(!$rows);
3442

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3443
test "query_builder";
3444
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3445
  # Basic tests
3446
  {   name            => 'placeholder basic',
3447
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3448
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3449
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3450
  },
3451
  {
3452
    name            => 'placeholder in',
3453
    source            => "{in k1 3}",
3454
    sql_expected    => "k1 in (?, ?, ?)",
3455
    columns_expected   => [qw/k1 k1 k1/]
3456
  },
3457
  
3458
  # Table name
3459
  {
3460
    name            => 'placeholder with table name',
3461
    source            => "{= a.k1} {= a.k2}",
3462
    sql_expected    => "a.k1 = ? a.k2 = ?",
3463
    columns_expected  => [qw/a.k1 a.k2/]
3464
  },
3465
  {   
3466
    name            => 'placeholder in with table name',
3467
    source            => "{in a.k1 2} {in b.k2 2}",
3468
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3469
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3470
  },
3471
  {
3472
    name            => 'not contain tag',
3473
    source            => "aaa",
3474
    sql_expected    => "aaa",
3475
    columns_expected  => [],
3476
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3477
];
3478

            
3479
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3480
  my $data = $datas->[$i];
3481
  my $dbi = DBIx::Custom->new;
3482
  my $builder = $dbi->query_builder;
3483
  my $query = $builder->build_query($data->{source});
3484
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3485
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3486
}
3487

            
cleanup
Yuki Kimoto authored on 2011-08-13
3488
$dbi = DBIx::Custom->new;
3489
$builder = $dbi->query_builder;
3490
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3491
  p => sub {
3492
    my @args = @_;
3493
    
3494
    my $expand    = "? $args[0] $args[1]";
3495
    my $columns = [2];
3496
    return [$expand, $columns];
3497
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3498
);
3499

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3510
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3511
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3512
});
3513

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3517
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3518
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3519
});
3520

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

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

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

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

            
3535

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

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

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

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

            
3551
test 'variouse source';
3552
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3553
$query = $builder->build_query($source);
3554
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3555

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

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

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

            
3568
$source = "a {= b} }";
3569
eval{$builder->build_query($source)};
3570
like($@, qr/unexpected "}"/, "error : 1");
3571

            
3572
$source = "a {= {}";
3573
eval{$builder->build_query($source)};
3574
like($@, qr/unexpected "{"/, "error : 2");
3575

            
3576
test 'select() sqlfilter option';
3577
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3578
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3579
eval { $dbi->execute("drop table $table1") };
3580
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3581
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3582
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3583
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3584
  table => $table1,
3585
  column => $key1,
3586
  sqlfilter => sub {
3587
    my $sql = shift;
3588
    $sql = "select * from ( $sql ) t where $key1 = 1";
3589
    return $sql;
3590
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3591
)->all;
3592
is_deeply($rows, [{$key1 => 1}]);
3593

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3594
test 'select() after_build_sql option';
3595
$dbi = DBIx::Custom->connect;
3596
$dbi->user_table_info($user_table_info);
3597
eval { $dbi->execute("drop table $table1") };
3598
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3599
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3600
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3601
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3602
  table => $table1,
3603
  column => $key1,
3604
  after_build_sql => sub {
3605
    my $sql = shift;
3606
    $sql = "select * from ( $sql ) t where $key1 = 1";
3607
    return $sql;
3608
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3609
)->all;
3610
is_deeply($rows, [{$key1 => 1}]);
3611

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3612
test 'dbi method from model';
3613
$dbi = MyDBI9->connect;
3614
eval { $dbi->execute("drop table $table1") };
3615
$dbi->execute($create_table1);
3616
$dbi->setup_model;
3617
$model = $dbi->model($table1);
3618
eval{$model->execute("select * from $table1")};
3619
ok(!$@);
3620

            
3621
test 'column table option';
3622
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3623
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3624
eval { $dbi->execute("drop table $table1") };
3625
$dbi->execute($create_table1);
3626
eval { $dbi->execute("drop table $table2") };
3627
$dbi->execute($create_table2);
3628
$dbi->setup_model;
3629
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3630
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3631
$model = $dbi->model($table1);
3632
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3633
  column => [
3634
    $model->column($table2, {alias => $table2_alias})
3635
  ],
3636
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3637
);
3638
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3639
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3640

            
3641
$dbi->separator('__');
3642
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3643
  column => [
3644
    $model->column($table2, {alias => $table2_alias})
3645
  ],
3646
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3647
);
3648
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3649
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3650

            
3651
$dbi->separator('-');
3652
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3653
  column => [
3654
      $model->column($table2, {alias => $table2_alias})
3655
  ],
3656
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3657
);
3658
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3659
  {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3660

            
3661
test 'create_model';
3662
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3663
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3664
eval { $dbi->execute("drop table $table1") };
3665
eval { $dbi->execute("drop table $table2") };
3666
$dbi->execute($create_table1);
3667
$dbi->execute($create_table2);
3668

            
3669
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3670
  table => $table1,
3671
  join => [
3672
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3673
  ],
3674
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3675
);
3676
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3677
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3678
);
3679
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3680
  table => $table3,
3681
  filter => [
3682
    $key1 => {in => sub { uc $_[0] }}
3683
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3684
);
3685
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3686
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3687
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3688
$model = $dbi->model($table1);
3689
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3690
  column => [$model->mycolumn, $model->column($table2)],
3691
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3692
);
3693
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3694
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3695
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3696

            
3697
test 'model method';
3698
$dbi = DBIx::Custom->connect;
3699
eval { $dbi->execute("drop table $table2") };
3700
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3701
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3702
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3703
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3704
);
3705
$model->method(foo => sub { shift->select(@_) });
3706
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3707

            
3708
test 'model helper';
3709
$dbi = DBIx::Custom->connect;
3710
eval { $dbi->execute("drop table $table2") };
3711
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3712
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3713
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3714
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3715
);
3716
$model->helper(foo => sub { shift->select(@_) });
3717
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3718

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

            
3726
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3727
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3728
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3729
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3730
where $key1 = 1
3731
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3732
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3733
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3734
$rows   = $result->all;
3735
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3736
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3737
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3738

            
3739

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

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

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

            
3765
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3766
$assign_clause = $dbi->update_param($param, {no_set => 1});
cleanup test
Yuki Kimoto authored on 2011-08-15
3767
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3768
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3769
where $key1 = 1
3770
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3771
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3772
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3773
$rows   = $result->all;
3774
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3775
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3776
  "update param no_set");
cleanup test
Yuki Kimoto authored on 2011-08-15
3777

            
cleanup
Yuki Kimoto authored on 2012-01-20
3778
          
cleanup test
Yuki Kimoto authored on 2011-08-15
3779
$dbi = DBIx::Custom->connect;
3780
eval { $dbi->execute("drop table $table1") };
3781
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
3782
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3, $key4 => 4, $key5 => 5}, table => $table1);
3783
$dbi->insert({$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3784

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3785
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3786
$assign_clause = $dbi->assign_param($param);
3787
$sql = <<"EOS";
3788
update $table1 set $assign_clause
3789
where $key1 = 1
3790
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3791
$dbi->execute($sql, $param, table => $table1);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3792
$result = $dbi->execute("select * from $table1 order by $key1");
3793
$rows   = $result->all;
3794
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3795
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3796
  "basic");
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3797

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3811
test 'Model class';
3812
$dbi = MyDBI1->connect;
3813
eval { $dbi->execute("drop table $table1") };
3814
$dbi->execute($create_table1);
3815
$model = $dbi->model($table1);
3816
$model->insert({$key1 => 'a', $key2 => 'b'});
3817
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3818
eval { $dbi->execute("drop table $table2") };
3819
$dbi->execute($create_table2);
3820
$model = $dbi->model($table2);
3821
$model->insert({$key1 => 'a'});
3822
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3823
is($dbi->models->{$table1}, $dbi->model($table1));
3824
is($dbi->models->{$table2}, $dbi->model($table2));
3825

            
3826
$dbi = MyDBI4->connect;
3827
eval { $dbi->execute("drop table $table1") };
3828
$dbi->execute($create_table1);
3829
$model = $dbi->model($table1);
3830
$model->insert({$key1 => 'a', $key2 => 'b'});
3831
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3832
eval { $dbi->execute("drop table $table2") };
3833
$dbi->execute($create_table2);
3834
$model = $dbi->model($table2);
3835
$model->insert({$key1 => 'a'});
3836
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3837

            
3838
$dbi = MyDBI5->connect;
3839
eval { $dbi->execute("drop table $table1") };
3840
eval { $dbi->execute("drop table $table2") };
3841
$dbi->execute($create_table1);
3842
$dbi->execute($create_table2);
3843
$model = $dbi->model($table2);
3844
$model->insert({$key1 => 'a'});
3845
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
3846
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3847
$model = $dbi->model($table1);
3848
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
3849

            
3850
test 'primary_key';
3851
$dbi = MyDBI1->connect;
3852
$model = $dbi->model($table1);
3853
$model->primary_key([$key1, $key2]);
3854
is_deeply($model->primary_key, [$key1, $key2]);
3855

            
3856
test 'columns';
3857
$dbi = MyDBI1->connect;
3858
$model = $dbi->model($table1);
3859
$model->columns([$key1, $key2]);
3860
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3861

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3862
test 'setup_model';
3863
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3864
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3865
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3866
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3867

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3868
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3869
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
3870
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
3871
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
3872
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
3873

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3874
test 'each_column';
3875
$dbi = DBIx::Custom->connect;
3876
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3877
eval { $dbi->execute("drop table $table1") };
3878
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3879
eval { $dbi->execute("drop table $table3") };
3880
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3881
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3882

            
3883
$infos = [];
3884
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3885
  my ($self, $table, $column, $cinfo) = @_;
3886
  
3887
  if ($table =~ /^table\d/i) {
3888
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
3889
     push @$infos, $info;
3890
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3891
});
3892
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
3893
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
3894
  [
3895
    [$table1, $key1, $key1],
3896
    [$table1, $key2, $key2],
3897
    [$table2, $key1, $key1],
3898
    [$table2, $key3, $key3]
3899
  ]
3900
  
cleanup test
Yuki Kimoto authored on 2011-08-10
3901
);
cleanup test
Yuki Kimoto authored on 2011-08-16
3902

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3903
test 'each_table';
3904
$dbi = DBIx::Custom->connect;
3905
eval { $dbi->execute("drop table $table1") };
3906
eval { $dbi->execute("drop table $table2") };
3907
$dbi->execute($create_table2);
3908
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
3909

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3910
$infos = [];
3911
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
3912
  my ($self, $table, $table_info) = @_;
3913
  
3914
  if ($table =~ /^table\d/i) {
3915
    my $info = [$table, $table_info->{TABLE_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, $table1],
3923
    [$table2, $table2],
3924
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
3925
);
3926

            
cleanup test
Yuki Kimoto authored on 2011-08-16
3927
$dbi = DBIx::Custom->connect;
3928
eval { $dbi->execute("drop table $table1") };
3929
eval { $dbi->execute("drop table $table2") };
3930
$dbi->execute($create_table2);
3931
$dbi->execute($create_table1_type);
3932

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3952
test 'type_rule into';
3953
eval { $dbi->execute("drop table $table1") };
3954
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3955
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
3956

            
3957

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3958
$dbi = DBIx::Custom->connect;
3959
eval { $dbi->execute("drop table $table1") };
3960
$dbi->execute($create_table1_type);
3961

            
cleanup
Yuki Kimoto authored on 2011-08-16
3962
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3963
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3964
  into1 => {
3965
    $date_typename => sub { '2010-' . $_[0] }
3966
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
3967
);
cleanup test
Yuki Kimoto authored on 2011-08-15
3968
$dbi->insert({$key1 => '01-01'}, table => $table1);
3969
$result = $dbi->select(table => $table1);
3970
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3971

            
3972
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3973
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
3974
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
3975
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3976
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3977
  into1 => [
3978
     [$date_typename, $datetime_typename] => sub {
3979
        my $value = shift;
3980
        $value =~ s/02/03/g;
3981
        return $value;
3982
     }
3983
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3984
);
3985
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
3986
$result = $dbi->select(table => $table1);
3987
$row = $result->one;
3988
like($row->{$key1}, qr/^2010-01-03/);
3989
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
3990

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3991
$dbi = DBIx::Custom->connect;
3992
eval { $dbi->execute("drop table $table1") };
3993
$dbi->execute($create_table1_type);
3994
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
3995
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3996
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
3997
  into1 => [
3998
    [$date_typename, $datetime_typename] => sub {
3999
      my $value = shift;
4000
      $value =~ s/02/03/g;
4001
      return $value;
4002
    }
4003
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4004
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4005
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4006
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4007
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4008
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4009
$row = $result->one;
4010
like($row->{$key1}, qr/^2010-01-03/);
4011
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4012

            
4013
$dbi = DBIx::Custom->connect;
4014
eval { $dbi->execute("drop table $table1") };
4015
$dbi->execute($create_table1_type);
4016
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4017
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4018
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4019
  into1 => [
4020
    [$date_typename, $datetime_typename] => sub {
4021
      my $value = shift;
4022
      $value =~ s/02/03/g;
4023
      return $value;
4024
    }
4025
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4026
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4027
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4028
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4029
  {$key1 => '2010-01-02', "$table1.$key2" => '2010-01-01 01:01:02'},
4030
  table => $table1
cleanup test
Yuki Kimoto authored on 2011-08-15
4031
);
4032
$row = $result->one;
4033
like($row->{$key1}, qr/^2010-01-03/);
4034
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4035

            
4036
$dbi = DBIx::Custom->connect;
4037
eval { $dbi->execute("drop table $table1") };
4038
$dbi->execute($create_table1_type);
4039
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4040
  my $value = shift || '';
4041
  $value =~ s/02/03/;
4042
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4043
});
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
  from1 => {
4047
    $date_datatype => 'convert',
4048
  },
4049
  into1 => {
4050
      $date_typename => 'convert',
4051
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4052
);
4053
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4054
$result = $dbi->select(table => $table1);
4055
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4056
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4057
$row = $result->fetch;
4058
like($row->[0], qr/^2010-03-03/);
4059
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4060

            
4061
test 'type_rule and filter order';
4062
$dbi = DBIx::Custom->connect;
4063
eval { $dbi->execute("drop table $table1") };
4064
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4065
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4066
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4067
  into1 => {
4068
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4069
  },
4070
  into2 => {
4071
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4072
  },
4073
  from1 => {
4074
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4075
  },
4076
  from2 => {
4077
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4078
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4079
);
4080
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4081
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4082
$result = $dbi->select(table => $table1);
4083
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4084
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4085

            
4086

            
4087
$dbi = DBIx::Custom->connect;
4088
eval { $dbi->execute("drop table $table1") };
4089
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4090
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4091
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4092
  from1 => {
4093
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4094
  },
4095
  from2 => {
4096
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4097
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4098
);
4099
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4100
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4101
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4102
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4103
  from1 => {
4104
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4105
  },
4106
  from2 => {
4107
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4108
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4109
);
cleanup test
Yuki Kimoto authored on 2011-08-15
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-10
4112

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4113
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4114
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
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/5/; return $v }
4121
  },
4122
  into1 => {
4123
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4124
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4125
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4126
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4127
$result = $dbi->select(table => $table1, type_rule_off => 1);
4128
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4129

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4130
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4131
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4132
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4133
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4134
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4135
  from1 => {
4136
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4137
  },
4138
  into1 => {
4139
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4140
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4141
);
4142
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4143
$result = $dbi->select(table => $table1, type_rule_off => 1);
4144
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4145

            
4146
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4147
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4148
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4149
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4150
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4151
  from1 => {
4152
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4153
  },
4154
  into1 => {
4155
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4156
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4157
);
4158
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4159
$result = $dbi->select(table => $table1);
4160
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4161

            
4162
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4163
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4164
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4165
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4166
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4167
  from1 => {
4168
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4169
  },
4170
  into1 => {
4171
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4172
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4173
);
4174
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4175
$result = $dbi->select(table => $table1);
4176
like($result->fetch->[0], qr/2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4177

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4192
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4193
  into1 => {
4194
    $date_typename => 'pp'
4195
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4196
)};
4197
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4198

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4199
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4200
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4201
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4202
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4203
  $dbi->type_rule(
4204
    from1 => {
4205
      Date => sub { $_[0] * 2 },
4206
    }
4207
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4208
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4209
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4210

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4211
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4212
  $dbi->type_rule(
4213
    into1 => {
4214
      Date => sub { $_[0] * 2 },
4215
    }
4216
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4217
};
4218
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4219

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

            
4237
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4238
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4239
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4240
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4241
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4242
  from1 => {
4243
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4244
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4245
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4246
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4247
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4248
$result = $dbi->select(table => $table1);
4249
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4250
  from1 => {
4251
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4252
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4253
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4254
$row = $result->one;
4255
like($row->{$key1}, qr/^2010-01-05/);
4256
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4257

            
4258
$result = $dbi->select(table => $table1);
4259
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4260
  from1 => {
4261
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4262
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4263
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4264
$row = $result->one;
4265
like($row->{$key1}, qr/2010-01-05/);
4266
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4267

            
4268
$result = $dbi->select(table => $table1);
4269
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4270
  from1 => {
4271
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4272
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4273
);
4274
$row = $result->one;
4275
like($row->{$key1}, qr/2010-01-05/);
4276
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4277

            
4278
$result = $dbi->select(table => $table1);
4279
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4280
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4281
);
4282
$row = $result->one;
4283
like($row->{$key1}, qr/2010-01-05/);
4284
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4285

            
4286
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4287
$result = $dbi->select(table => $table1);
4288
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4289
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4290
);
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 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4298
);
4299
$row = $result->one;
4300
like($row->{$key1}, qr/^2010-01-03/);
4301
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4302

            
4303
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4304
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4305
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4306
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4307
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4308
  from1 => {
4309
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4310
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4311
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4312
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4313
$result = $dbi->select(table => $table1);
4314
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4315
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4316

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4317
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4318
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4319
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4320
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4321
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4322
  from1 => {
4323
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4324
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4325
);
4326
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4327
$result = $dbi->select(table => $table1);
4328
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4329
like($result->fetch->[0], qr/^2010-01-05/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4330

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4403
test 'join';
4404
$dbi = DBIx::Custom->connect;
4405
eval { $dbi->execute("drop table $table1") };
4406
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4407
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4408
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4409
eval { $dbi->execute("drop table $table2") };
4410
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4411
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4412
eval { $dbi->execute("drop table $table3") };
4413
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4414
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4415
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4416
  table => $table1,
4417
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4418
  where   => {"$table1.$key2" => 2},
4419
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4420
)->all;
4421
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4422

            
4423
$dbi = DBIx::Custom->connect;
4424
eval { $dbi->execute("drop table $table1") };
4425
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4426
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4427
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4428
eval { $dbi->execute("drop table $table2") };
4429
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4430
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4431
eval { $dbi->execute("drop table $table3") };
4432
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4433
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4434
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4435
  table => $table1,
4436
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4437
  where   => {"$table1.$key2" => 2},
4438
  join  => {
4439
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4440
    table => [$table1, $table2]
4441
  }
added test
Yuki Kimoto authored on 2011-10-27
4442
)->all;
4443
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
4444

            
4445
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4446
  table => $table1,
4447
  where   => {$key1 => 1},
4448
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4449
)->all;
4450
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4451

            
4452
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4453
  table => $table1,
4454
  where   => {$key1 => 1},
4455
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4456
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4457
)->all;
4458
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4459

            
4460
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4461
  column => "$table3.$key4 as ${table3}__$key4",
4462
  table => $table1,
4463
  where   => {"$table1.$key1" => 1},
4464
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4465
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4466
)->all;
4467
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4468

            
4469
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4470
  column => "$table1.$key1 as ${table1}__$key1",
4471
  table => $table1,
4472
  where   => {"$table3.$key4" => 4},
4473
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4474
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4475
)->all;
4476
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4477

            
4478
$dbi = DBIx::Custom->connect;
4479
eval { $dbi->execute("drop table $table1") };
4480
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4481
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4482
eval { $dbi->execute("drop table $table2") };
4483
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4484
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4485
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4486
  table => $table1,
4487
  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",
4488
  where   => {"$table1.$key2" => 2},
4489
  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
4490
)->all;
4491
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4492
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4493

            
4494

            
4495
$dbi = DBIx::Custom->connect;
4496
eval { $dbi->execute("drop table $table1") };
4497
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4498
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4499
$sql = <<"EOS";
4500
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4501
select * from $table1 t1
4502
where t1.$key2 = (
4503
  select max(t2.$key2) from $table1 t2
4504
  where t1.$key1 = t2.$key1
4505
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4506
) $table3 on $table1.$key1 = $table3.$key1
4507
EOS
4508
$join = [$sql];
4509
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4510
  table => $table1,
4511
  column => "$table3.$key1 as ${table3}__$key1",
4512
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4513
)->all;
4514
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4515

            
4516
$dbi = DBIx::Custom->connect;
4517
eval { $dbi->execute("drop table $table1") };
4518
eval { $dbi->execute("drop table $table2") };
4519
$dbi->execute($create_table1);
4520
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4521
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4522
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4523
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4524
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4525
  table => $table1,
4526
  join => [
4527
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4528
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4529
);
4530
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4531
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4532
  table => $table1,
4533
  column => [{$table2 => [$key3]}],
4534
  join => [
4535
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4536
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4537
);
4538
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4539
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4540
  table => $table1,
4541
  column => [{$table2 => [$key3]}],
4542
  join => [
4543
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4544
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4545
);
4546
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4547

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4568
$dbi = DBIx::Custom->connect;
4569
eval { $dbi->execute("drop table $table1") };
4570
eval { $dbi->execute("drop table $table2") };
4571
$dbi->execute($create_table1);
4572
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4573
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4574
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4575
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4576
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4577
  table => $table1,
4578
  column => [{$table2 => [$key3]}],
4579
  join => [
4580
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4581
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4582
);
4583
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4584

            
4585
$dbi = DBIx::Custom->connect;
4586
eval { $dbi->execute("drop table $table1") };
4587
eval { $dbi->execute("drop table $table2") };
4588
$dbi->execute($create_table1);
4589
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4590
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4591
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4592
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4593
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4594
  table => $table1,
4595
  column => [{$table2 => [$key3]}],
4596
  join => [
4597
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4598
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4599
);
4600
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4601

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4602
test 'columns';
4603
$dbi = MyDBI1->connect;
4604
$model = $dbi->model($table1);
4605

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4606
test 'count';
4607
$dbi = DBIx::Custom->connect;
4608
eval { $dbi->execute("drop table $table1") };
4609
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4610
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4611
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4612
is($dbi->count(table => $table1), 2);
4613
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4614
$model = $dbi->create_model(table => $table1);
4615
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4616

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4617
eval { $dbi->execute("drop table $table1") };
4618
eval { $dbi->execute("drop table $table2") };
4619
$dbi->execute($create_table1);
4620
$dbi->execute($create_table2);
4621
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4622
$model->insert({$key1 => 1, $key2 => 2});
4623
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4624
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4625
$model->insert({$key1 => 1, $key3 => 3});
4626
is($model->count(id => 1), 1);
4627
is($model->count(where => {"$table2.$key3" => 3}), 1);
4628

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