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

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

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

            
14
plan 'no_plan';
15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
169
  use base 'MyModel2::Base1';
170

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1354
test 'fetch filter';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1355
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1356
$dbi->register_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1357
  twice       => sub { $_[0] * 2 },
1358
  three_times => sub { $_[0] * 3 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1359
);
1360
$dbi->default_fetch_filter('twice');
1361
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1362
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1363
$result = $dbi->select(table => $table1);
1364
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
1365
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1366
is_deeply($row, {$key1 => 3, $key2 => 4}, "default_fetch_filter and filter");
test cleanup
Yuki Kimoto authored on 2011-08-10
1367

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1368
$dbi->default_fetch_filter('twice');
1369
eval { $dbi->execute("drop table $table1") };
1370
$dbi->execute($create_table1);
1371
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1372
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1373
$result->filter({$key1 => 'three_times'});
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1374
$row = $result->fetch_one;
1375
is_deeply($row, [3, 3, 4], "default_fetch_filter and filter");
1376

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1383
test 'filters';
1384
$dbi = DBIx::Custom->new;
1385

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1392
test 'transaction1';
test cleanup
Yuki Kimoto authored on 2011-08-10
1393
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1394
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1395
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1396
$dbi->begin_work;
1397
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1398
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1399
$dbi->rollback;
1400
$dbi->dbh->{AutoCommit} = 1;
1401

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

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

            
1406
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1407
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1408
$dbi->execute($create_table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1409
$dbi->begin_work;
1410
$dbi->dbh->{AutoCommit} = 0;
test cleanup
Yuki Kimoto authored on 2011-11-01
1411
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1412
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
fixed transaction test
Yuki Kimoto authored on 2011-08-14
1413
$dbi->commit;
1414
$dbi->dbh->{AutoCommit} = 1;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1415
$result = $dbi->select(table => $table1);
1416
is_deeply(scalar $result->all, [{$key1 => 1, $key2 => 2}, {$key1 => 2, $key2 => 3}],
cleanup
Yuki Kimoto authored on 2012-01-20
1417
  "commit");
test cleanup
Yuki Kimoto authored on 2011-08-10
1418

            
1419
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1420
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1421
$dbi->execute($create_table1);
1422
{
cleanup
Yuki Kimoto authored on 2012-01-20
1423
  local $Carp::Verbose = 0;
1424
  eval{$dbi->execute("select * frm $table1")};
1425
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1426
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1427
}
1428
{
cleanup
Yuki Kimoto authored on 2012-01-20
1429
  local $Carp::Verbose = 1;
1430
  eval{$dbi->execute("select * frm $table1")};
1431
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1432
}
1433

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

            
1439
{
cleanup
Yuki Kimoto authored on 2012-01-20
1440
  local $Carp::Verbose = 0;
1441
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1442
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1443
}
1444
{
cleanup
Yuki Kimoto authored on 2012-01-20
1445
  local $Carp::Verbose = 1;
1446
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1447
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1448
}
1449

            
1450

            
cleanup test
Yuki Kimoto authored on 2011-08-10
1451
test 'transaction2';
test cleanup
Yuki Kimoto authored on 2011-08-10
1452
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1453
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1454
$dbi->execute($create_table1);
1455

            
1456
$dbi->begin_work;
1457

            
1458
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
1459
  $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1460
  die "Error";
1461
  $dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1462
};
1463

            
1464
$dbi->rollback if $@;
1465

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

            
1470
$dbi->begin_work;
1471

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

            
1477
$dbi->commit unless $@;
1478

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

            
1483
$dbi->dbh->{AutoCommit} = 0;
1484
eval{ $dbi->begin_work };
1485
ok($@, "exception");
1486
$dbi->dbh->{AutoCommit} = 1;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
1487

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1488
test 'cache';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1489
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1490
$dbi->cache(1);
1491
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1492
$source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
test cleanup
Yuki Kimoto authored on 2011-08-10
1493
$dbi->execute($source, {}, query => 1);
1494
is_deeply($dbi->{_cached}->{$source}, 
cleanup
Yuki Kimoto authored on 2012-01-20
1495
  {sql => " select * from $table1 where $key1 = ?  and $key2 = ? ", columns => [$key1, $key2], tables => []}, "cache");
test cleanup
Yuki Kimoto authored on 2011-08-10
1496

            
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1497
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1498
$dbi->execute($create_table1);
1499
$dbi->{_cached} = {};
1500
$dbi->cache(0);
test cleanup
Yuki Kimoto authored on 2011-11-01
1501
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1502
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
1503

            
1504
test 'execute';
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1505
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1506
$dbi->execute($create_table1);
1507
{
cleanup
Yuki Kimoto authored on 2012-01-20
1508
  local $Carp::Verbose = 0;
1509
  eval{$dbi->execute("select * frm $table1")};
1510
  like($@, qr/\Qselect * frm $table1/, "fail prepare");
1511
  like($@, qr/\.t /, "fail : not verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1512
}
1513
{
cleanup
Yuki Kimoto authored on 2012-01-20
1514
  local $Carp::Verbose = 1;
1515
  eval{$dbi->execute("select * frm $table1")};
1516
  like($@, qr/Custom.*\.t /s, "fail : verbose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1517
}
1518

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

            
1524
{
cleanup
Yuki Kimoto authored on 2012-01-20
1525
  local $Carp::Verbose = 0;
1526
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1527
  like($@, qr/\Q.t /, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1528
}
1529
{
cleanup
Yuki Kimoto authored on 2012-01-20
1530
  local $Carp::Verbose = 1;
1531
  eval{$dbi->execute("select * from $table1 where {0 $key1}", {}, query => 1)};
1532
  like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
test cleanup
Yuki Kimoto authored on 2011-08-10
1533
}
1534

            
1535
test 'method';
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1536
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1537
  one => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1538
);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1539
$dbi->helper(
cleanup
Yuki Kimoto authored on 2012-01-20
1540
  two => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
1541
);
1542
$dbi->method({
cleanup
Yuki Kimoto authored on 2012-01-20
1543
  twice => sub {
1544
    my $self = shift;
1545
    return $_[0] * 2;
1546
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
1547
});
1548

            
1549
is($dbi->one, 1, "first");
1550
is($dbi->two, 2, "second");
1551
is($dbi->twice(5), 10 , "second");
1552

            
1553
eval {$dbi->XXXXXX};
1554
ok($@, "not exists");
1555

            
1556
test 'out filter';
1557
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1558
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1559
$dbi->execute($create_table1);
1560
$dbi->register_filter(twice => sub { $_[0] * 2 });
1561
$dbi->register_filter(three_times => sub { $_[0] * 3});
1562
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1563
  $table1, $key1 => {out => 'twice', in => 'three_times'}, 
1564
            $key2 => {out => 'three_times', in => 'twice'});
test cleanup
Yuki Kimoto authored on 2011-11-01
1565
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
1566
$result = $dbi->execute("select * from $table1");
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1567
$row   = $result->fetch_hash_one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1568
is_deeply($row, {$key1 => 2, $key2 => 6}, "insert");
1569
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1570
$row   = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1571
is_deeply($row, {$key1 => 6, $key2 => 12}, "insert");
test cleanup
Yuki Kimoto authored on 2011-08-10
1572

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

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

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

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

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

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

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

            
1660
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1661
eval { $dbi->execute("drop table $table1") };
1662
eval { $dbi->execute("drop table $table2") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1663
$dbi->execute($create_table1);
1664
$dbi->execute($create_table2);
1665
$dbi->register_filter(twice => sub { $_[0] * 2 });
1666
$dbi->register_filter(three_times => sub { $_[0] * 3 });
1667
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1668
  $table1, $key2 => {out => 'twice', in => 'twice'}
cleanup test
Yuki Kimoto authored on 2011-08-15
1669
);
1670
$dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2012-01-20
1671
  $table2, $key3 => {out => 'three_times', in => 'three_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1672
);
cleanup
Yuki Kimoto authored on 2011-11-01
1673
$dbi->insert({$key1 => 5, $key2 => 2}, table => $table1, filter => {$key2 => undef});
1674
$dbi->insert({$key1 => 5, $key3 => 6}, table => $table2, filter => {$key3 => undef});
cleanup test
Yuki Kimoto authored on 2011-08-15
1675
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1676
  table => [$table1, $table2],
1677
  column => [$key2, $key3],
1678
  where => {"$table1.$key2" => 1, "$table2.$key3" => 2}, relation => {"$table1.$key1" => "$table2.$key1"});
cleanup test
Yuki Kimoto authored on 2011-08-15
1679

            
1680
$result->filter({$key2 => 'twice'});
1681
$rows   = $result->all;
1682
is_deeply($rows, [{$key2 => 4, $key3 => 18}], "select : join");
1683

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

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

            
1693
test 'connect super';
test cleanup
Yuki Kimoto authored on 2011-08-10
1694
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1695
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1696
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1697
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1698
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1699

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1700
$dbi = DBIx::Custom->new;
test cleanup
Yuki Kimoto authored on 2011-08-10
1701
$dbi->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1702
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1703
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1704
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1705
is($dbi->select(table => $table1)->one->{$key1}, 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1706

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

            
1713
test 'end_filter';
1714
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1715
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1716
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1717
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1718
$result = $dbi->select(table => $table1);
1719
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1720
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1721
$row = $result->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1722
is_deeply($row, [6, 40]);
1723

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1724
$dbi = DBIx::Custom->connect;
1725
eval { $dbi->execute("drop table $table1") };
1726
$dbi->execute($create_table1);
1727
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1728
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1729
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1730
$result->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
1731
$row = $result->fetch_one;
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1732
is_deeply($row, [6, 6, 40]);
1733

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

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

            
1754
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1755
$result = $dbi->select(table => $table1);
1756
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1757
$result->end_filter({$key1 => sub { $_[0] * 3 }, $key2 => 'five_times' });
test cleanup
Yuki Kimoto authored on 2011-08-10
1758
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1759
is_deeply($row, {$key1 => 6, $key2 => 40});
test cleanup
Yuki Kimoto authored on 2011-08-10
1760

            
1761
$dbi->register_filter(five_times => sub { $_[0] * 5 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1762
$dbi->apply_filter($table1,
cleanup
Yuki Kimoto authored on 2012-01-20
1763
  $key1 => {end => sub { $_[0] * 3 } },
1764
  $key2 => {end => 'five_times'}
test cleanup
Yuki Kimoto authored on 2011-08-10
1765
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1766
$result = $dbi->select(table => $table1);
1767
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
test cleanup
Yuki Kimoto authored on 2011-08-10
1768
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1769
is_deeply($row, {$key1 => 6, $key2 => 40}, 'apply_filter');
test cleanup
Yuki Kimoto authored on 2011-08-10
1770

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
1783
$result = $dbi->select(column => [$key1, $key1, $key2], table => $table1);
1784
$result->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 });
1785
$result->filter($key1 => undef);
1786
$result->end_filter($key1 => undef);
1787
$row = $result->fetch;
1788
is_deeply($row, [1, 1, 40], 'apply_filter overwrite');
1789

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1790
test 'remove_end_filter and remove_filter';
1791
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1792
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1793
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1794
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1795
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
1796
$row = $result
cleanup
Yuki Kimoto authored on 2012-01-20
1797
  ->filter($key1 => sub { $_[0] * 2 }, $key2 => sub { $_[0] * 4 })
1798
  ->remove_filter
1799
  ->end_filter($key1 => sub { $_[0] * 3 }, $key2 => sub { $_[0] * 5 })
1800
  ->remove_end_filter
1801
  ->fetch_one;
test cleanup
Yuki Kimoto authored on 2011-08-10
1802
is_deeply($row, [1, 2]);
1803

            
1804
test 'empty where select';
1805
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1806
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1807
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1808
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1809
$result = $dbi->select(table => $table1, where => {});
test cleanup
Yuki Kimoto authored on 2011-08-10
1810
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1811
is_deeply($row, {$key1 => 1, $key2 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
1812

            
1813
test 'select query option';
1814
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1815
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1816
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
1817
$query = $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1818
ok(ref $query);
cleanup
Yuki Kimoto authored on 2011-11-01
1819
$query = $dbi->update({$key2 => 2}, table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1820
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1821
$query = $dbi->delete(table => $table1, where => {$key1 => 1}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1822
ok(ref $query);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1823
$query = $dbi->select(table => $table1, where => {$key1 => 1, $key2 => 2}, query => 1);
micro optimization
Yuki Kimoto authored on 2011-11-16
1824
ok(ref $query);
test cleanup
Yuki Kimoto authored on 2011-08-10
1825

            
1826
test 'where';
1827
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
1828
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
1829
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
1830
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
1831
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1832
$where = $dbi->where->clause(['and', "$key1 = :$key1", "$key2 = :$key2"]);
1833
is("$where", "where ( $key1 = :$key1 and $key2 = :$key2 )", 'no param');
test cleanup
Yuki Kimoto authored on 2011-08-10
1834

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

            
1839
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1840
  table => $table1,
1841
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1842
);
1843
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
1844
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
1845

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

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

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

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

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

            
1894
eval {
1895
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
1896
           ->clause(['uuu']);
test cleanup
Yuki Kimoto authored on 2011-08-10
1897
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
1898
  table => $table1,
1899
  where => $where
test cleanup
Yuki Kimoto authored on 2011-08-10
1900
);
1901
};
1902
ok($@);
1903

            
1904
$where = $dbi->where;
1905
is("$where", '');
1906

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

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

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

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

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

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

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

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

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

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

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

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

            
2027
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2028
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2029
  ->param({$key1 => [2, $dbi->not_exists]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2030
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2031
  table => $table1,
2032
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2033
);
2034
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2035
is_deeply($row, [{$key1 => 3, $key2 => 4}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2036

            
2037
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2038
  ->clause(['and', "{> $key1}", "{< $key1}" ])
2039
  ->param({$key1 => [$dbi->not_exists, 2]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2040
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2041
  table => $table1,
2042
  where => $where,
test cleanup
Yuki Kimoto authored on 2011-08-10
2043
);
2044
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2045
is_deeply($row, [{$key1 => 1, $key2 => 2}], 'not_exists');
test cleanup
Yuki Kimoto authored on 2011-08-10
2046

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

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

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

            
2076
eval {$dbi->where(ppp => 1) };
2077
like($@, qr/invalid/);
2078

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

            
2090

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

            
2102
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2103
$where->clause(['and', ":${key1}{=}"]);
2104
$where->param({$key1 => undef});
2105
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
test cleanup
Yuki Kimoto authored on 2011-08-10
2106
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2107
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2108

            
2109
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2110
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2111
$where->param({$key1 => [undef, undef]});
2112
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2113
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2114
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2115
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2116
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2117
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2118

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

            
2120
$dbi = DBIx::Custom->connect;
2121
eval { $dbi->execute("drop table $table1") };
2122
$dbi->execute($create_table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2123
$dbi->insert({$key1 => 1, $key2 => '00:00:00'}, table => $table1);
2124
$dbi->insert({$key1 => 1, $key2 => '3'}, table => $table1);
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2125
$where = $dbi->where
cleanup
Yuki Kimoto authored on 2012-01-20
2126
  ->clause(['and', "$key1 = :$key1", "$key2 = '00:00:00'"])
2127
  ->param({$key1 => 1});
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2128

            
2129
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2130
  table => $table1,
2131
  where => $where
fixed where clause parsing b...
Yuki Kimoto authored on 2011-11-01
2132
);
2133
$row = $result->all;
2134
is_deeply($row, [{$key1 => 1, $key2 => '00:00:00'}]);
2135

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2136
test 'register_tag_processor';
2137
$dbi = DBIx::Custom->connect;
2138
$dbi->register_tag_processor(
cleanup
Yuki Kimoto authored on 2012-01-20
2139
  a => sub { 1 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2140
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2141
is($dbi->{_tags}->{a}->(), 1);
test cleanup
Yuki Kimoto authored on 2011-08-10
2142

            
2143
test 'register_tag';
2144
$dbi = DBIx::Custom->connect;
2145
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
2146
  b => sub { 2 }
test cleanup
Yuki Kimoto authored on 2011-08-10
2147
);
test cleanup
Yuki Kimoto authored on 2011-08-10
2148
is($dbi->{_tags}->{b}->(), 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2149

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2155
test 'more tests';
2156
$dbi = DBIx::Custom->connect;
2157
eval{$dbi->apply_filter('table', 'column', [])};
2158
like($@, qr/apply_filter/);
2159

            
2160
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2161
like($@, qr/apply_filter/);
2162

            
2163
$dbi->apply_filter(
2164

            
2165
);
2166
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2167
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2168
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2169
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2170
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2171
$dbi->apply_filter($table1, $key2, 
cleanup
Yuki Kimoto authored on 2012-01-20
2172
                 {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2173
$rows = $dbi->select(table => $table1, where => {$key2 => 1})->all;
2174
is_deeply($rows, [{$key1 => 1, $key2 => 6}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2175

            
2176
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2177
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2178
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2179
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2180
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2181
$dbi->apply_filter($table1, $key2, {});
2182
$rows = $dbi->select(table => $table1, where => {$key2 => 2})->all;
2183
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2184

            
2185
$dbi = DBIx::Custom->connect;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2186
eval {$dbi->apply_filter($table1, $key2, {out => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2187
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2188
eval {$dbi->apply_filter($table1, $key2, {in => 'no'})};
test cleanup
Yuki Kimoto authored on 2011-08-10
2189
like($@, qr/not registered/);
2190
$dbi->method({one => sub { 1 }});
2191
is($dbi->one, 1);
2192

            
2193
eval{DBIx::Custom->connect(dsn => undef)};
2194
like($@, qr/_connect/);
2195

            
2196
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2197
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2198
$dbi->execute($create_table1);
2199
$dbi->register_filter(twice => sub { $_[0] * 2 });
cleanup
Yuki Kimoto authored on 2011-11-01
2200
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2201
           filter => {$key1 => 'twice'});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2202
$row = $dbi->select(table => $table1)->one;
2203
is_deeply($row, {$key1 => 2, $key2 => 2});
cleanup
Yuki Kimoto authored on 2011-11-01
2204
eval {$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
2205
           filter => {$key1 => 'no'}) };
test cleanup
Yuki Kimoto authored on 2011-08-10
2206
like($@, qr//);
2207

            
2208
$dbi->register_filter(one => sub { });
2209
$dbi->default_fetch_filter('one');
2210
ok($dbi->default_fetch_filter);
2211
$dbi->default_bind_filter('one');
2212
ok($dbi->default_bind_filter);
2213
eval{$dbi->default_fetch_filter('no')};
2214
like($@, qr/not registered/);
2215
eval{$dbi->default_bind_filter('no')};
2216
like($@, qr/not registered/);
2217
$dbi->default_bind_filter(undef);
2218
ok(!defined $dbi->default_bind_filter);
2219
$dbi->default_fetch_filter(undef);
2220
ok(!defined $dbi->default_fetch_filter);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2221
eval {$dbi->execute("select * from $table1 {} {= author") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2222
like($@, qr/Tag not finished/);
2223

            
2224
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2225
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2226
$dbi->execute($create_table1);
2227
$dbi->register_filter(one => sub { 1 });
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2228
$result = $dbi->select(table => $table1);
2229
eval {$result->filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2230
like($@, qr/not registered/);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2231
eval {$result->end_filter($key1 => 'no')};
test cleanup
Yuki Kimoto authored on 2011-08-10
2232
like($@, qr/not registered/);
2233
$result->default_filter(undef);
2234
ok(!defined $result->default_filter);
2235
$result->default_filter('one');
2236
is($result->default_filter->(), 1);
2237

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2238
test 'option';
2239
$dbi = DBIx::Custom->connect(option => {PrintError => 1});
2240
ok($dbi->dbh->{PrintError});
test cleanup
Yuki Kimoto authored on 2011-08-10
2241
$dbi = DBIx::Custom->connect(dbi_option => {PrintError => 1});
2242
ok($dbi->dbh->{PrintError});
2243
$dbi = DBIx::Custom->connect(dbi_options => {PrintError => 1});
2244
ok($dbi->dbh->{PrintError});
2245

            
2246
test 'DBIx::Custom::Result stash()';
2247
$result = DBIx::Custom::Result->new;
2248
is_deeply($result->stash, {}, 'default');
2249
$result->stash->{foo} = 1;
2250
is($result->stash->{foo}, 1, 'get and set');
test cleanup
Yuki Kimoto authored on 2011-08-10
2251

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2252
test 'delete_at';
2253
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2254
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2255
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2256
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2257
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2258
  table => $table1,
2259
  primary_key => [$key1, $key2],
2260
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2261
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2262
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2263

            
cleanup
Yuki Kimoto authored on 2011-11-01
2264
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2265
$dbi->delete_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2266
  table => $table1,
2267
  primary_key => $key1,
2268
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2269
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2270
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2271

            
2272
test 'insert_at';
2273
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2274
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2275
$dbi->execute($create_table1_2);
2276
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2277
  {$key3 => 3},
2278
  primary_key => [$key1, $key2], 
2279
  table => $table1,
2280
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2281
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2282
is($dbi->select(table => $table1)->one->{$key1}, 1);
2283
is($dbi->select(table => $table1)->one->{$key2}, 2);
2284
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2285

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2286
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2287
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2288
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2289
  {$key2 => 2, $key3 => 3},
2290
  primary_key => $key1, 
2291
  table => $table1,
2292
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2293
);
2294

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

            
2299
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2300
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2301
$dbi->execute($create_table1_2);
2302
$dbi->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2303
  {$key3 => 3},
2304
  primary_key => [$key1, $key2], 
2305
  table => $table1,
2306
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2307
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2308
is($dbi->select(table => $table1)->one->{$key1}, 1);
2309
is($dbi->select(table => $table1)->one->{$key2}, 2);
2310
is($dbi->select(table => $table1)->one->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2311

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2327
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2328
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2329
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2330
  {$key3 => 4},
2331
  table => $table1,
2332
  primary_key => $key1,
2333
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2334
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2335
is($dbi->select(table => $table1)->one->{$key1}, 1);
2336
is($dbi->select(table => $table1)->one->{$key2}, 2);
2337
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2338

            
2339
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2340
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2341
$dbi->execute($create_table1_2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2342
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2343
$dbi->update_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2344
  {$key3 => 4},
2345
  table => $table1,
2346
  primary_key => [$key1, $key2],
2347
  where => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2348
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2349
is($dbi->select(table => $table1)->one->{$key1}, 1);
2350
is($dbi->select(table => $table1)->one->{$key2}, 2);
2351
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2352

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2368
$dbi->delete_all(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2369
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2370
$result = $dbi->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2371
  table => $table1,
2372
  primary_key => $key1,
2373
  where => 1,
cleanup test
Yuki Kimoto authored on 2011-08-10
2374
);
2375
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2376
is($row->{$key1}, 1);
2377
is($row->{$key2}, 2);
2378
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2379

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

            
2392
test 'model delete_at';
2393
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2394
eval { $dbi->execute("drop table $table1") };
2395
eval { $dbi->execute("drop table $table2") };
2396
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2397
$dbi->execute($create_table1_2);
2398
$dbi->execute($create_table2_2);
2399
$dbi->execute($create_table3);
test cleanup
Yuki Kimoto authored on 2011-11-01
2400
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2401
$dbi->model($table1)->delete_at(where => [1, 2]);
2402
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2403
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2404
$dbi->model($table1)->delete_at(where => [1, 2]);
2405
is_deeply($dbi->select(table => $table1)->all, []);
test cleanup
Yuki Kimoto authored on 2011-11-01
2406
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2407
$dbi->model($table3)->delete_at(where => [1, 2]);
2408
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2409

            
2410
test 'model insert_at';
2411
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2412
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2413
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2414
$dbi->model($table1)->insert_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2415
  {$key3 => 3},
2416
  where => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2417
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2418
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2419
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2420
is($row->{$key1}, 1);
2421
is($row->{$key2}, 2);
2422
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2423

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

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

            
2450

            
2451
test 'mycolumn and column';
2452
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2453
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2454
eval { $dbi->execute("drop table $table1") };
2455
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2456
$dbi->execute($create_table1);
2457
$dbi->execute($create_table2);
2458
$dbi->separator('__');
2459
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2460
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2461
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2462
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2463
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2464
  column => [$model->mycolumn, $model->column($table2)],
2465
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2466
);
2467
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2468
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2469

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2470
test 'values_clause';
test cleanup
Yuki Kimoto authored on 2011-08-10
2471
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2472
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
2473
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2474
$param = {$key1 => 1, $key2 => 2};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2475
$values_clause = $dbi->values_clause($param);
test cleanup
Yuki Kimoto authored on 2011-08-10
2476
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2477
insert into $table1 $values_clause
test cleanup
Yuki Kimoto authored on 2011-08-10
2478
EOS
test cleanup
Yuki Kimoto authored on 2011-11-01
2479
$dbi->execute($sql, $param, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2480
is($dbi->select(table => $table1)->one->{$key1}, 1);
2481
is($dbi->select(table => $table1)->one->{$key2}, 2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2482

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2495
test 'mycolumn';
2496
$dbi = MyDBI8->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2497
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2498
eval { $dbi->execute("drop table $table1") };
2499
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2500
$dbi->execute($create_table1);
2501
$dbi->execute($create_table2);
2502
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2503
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2504
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2505
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2506
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2507
  column => [
2508
    $model->mycolumn,
2509
    $model->column($table2)
2510
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2511
);
2512
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2513
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2514

            
2515
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2516
  column => [
2517
    $model->mycolumn([$key1]),
2518
    $model->column($table2 => [$key1])
2519
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2520
);
2521
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2522
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2523
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2524
  column => [
2525
    $model->mycolumn([$key1]),
2526
    {$table2 => [$key1]}
2527
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2528
);
2529
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2530
        {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2531

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

            
2541
$result = $model->select_at(
cleanup
Yuki Kimoto authored on 2012-01-20
2542
  column => [
2543
    $model->mycolumn([$key1]),
2544
    ["$table2.$key1" => "$table2.$key1"]
2545
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
2546
);
2547
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2548
  {$key1 => 1, "$table2.$key1" => 1});
cleanup test
Yuki Kimoto authored on 2011-08-10
2549

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2550
test 'merge_param';
2551
$dbi = DBIx::Custom->new;
2552
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2553
  {$key1 => 1, $key2 => 2, $key3 => 3},
2554
  {$key1 => 1, $key2 => 2},
2555
  {$key1 => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2556
];
2557
$param = $dbi->merge_param($params->[0], $params->[1], $params->[2]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2558
is_deeply($param, {$key1 => [1, 1, 1], $key2 => [2, 2], $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2559

            
2560
$params = [
cleanup
Yuki Kimoto authored on 2012-01-20
2561
  {$key1 => [1, 2], $key2 => 1, $key3 => [1, 2]},
2562
  {$key1 => [3, 4], $key2 => [2, 3], $key3 => 3}
cleanup test
Yuki Kimoto authored on 2011-08-10
2563
];
2564
$param = $dbi->merge_param($params->[0], $params->[1]);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2565
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
2566

            
2567
test 'select() param option';
2568
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2569
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2570
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2571
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2572
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2573
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2574
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
2575
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
2576
$dbi->insert({$key1 => 2, $key3 => 5}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
2577
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2578
  table => $table1,
2579
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2580
  where   => {"$table1.$key2" => 3},
2581
  join  => ["inner join (select * from $table2 where {= $table2.$key3})" . 
2582
            " $table2 on $table1.$key1 = $table2.$key1"],
2583
  param => {"$table2.$key3" => 5}
cleanup test
Yuki Kimoto authored on 2011-08-10
2584
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2585
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2586

            
cleanup
Yuki Kimoto authored on 2011-10-21
2587
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2588
  table => $table1,
2589
  column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2590
  where   => {"$table1.$key2" => 3},
2591
  join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2592
           " $table2 on $table1.$key1 = $table2.$key1",
2593
  param => {"$table2.$key3" => 5}
cleanup
Yuki Kimoto authored on 2011-10-21
2594
)->all;
2595
is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2596

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2597
test 'select() string where';
2598
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2599
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2600
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2601
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2602
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2603
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2604
  table => $table1,
2605
  where => "$key1 = :$key1 and $key2 = :$key2",
2606
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2607
)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2608
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2609

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2638
test 'delete() string where';
2639
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2640
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2641
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
2642
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2643
$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2644
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2645
  table => $table1,
2646
  where => "$key1 = :$key1 and $key2 = :$key2",
2647
  where_param => {$key1 => 1, $key2 => 2}
cleanup test
Yuki Kimoto authored on 2011-08-10
2648
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2649
$rows = $dbi->select(table => $table1)->all;
2650
is_deeply($rows, [{$key1 => 2, $key2 => 3}]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2651

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

            
2667

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

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2711
$dbi->delete_all(table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2712
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2713
  {$key2 => 2, $key3 => 3},
2714
  primary_key => $key1, 
2715
  table => $table1,
2716
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2717
);
2718

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2723
$dbi = DBIx::Custom->connect;
2724
eval { $dbi->execute("drop table $table1") };
2725
$dbi->execute($create_table1_2);
2726
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2727
  {$key3 => 3},
2728
  primary_key => [$key1, $key2], 
2729
  table => $table1,
2730
  id => 1,
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2731
);
2732
is($dbi->select(table => $table1)->one->{$key1}, 1);
2733
ok(!$dbi->select(table => $table1)->one->{$key2});
2734
is($dbi->select(table => $table1)->one->{$key3}, 3);
2735

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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2749
$dbi = DBIx::Custom->connect;
2750
eval { $dbi->execute("drop table $table1") };
2751
$dbi->execute($create_table1_2);
2752
$param = {$key3 => 3, $key2 => 4};
2753
$dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2754
  $param,
2755
  primary_key => [$key1, $key2], 
2756
  table => $table1,
2757
  id => [1, 2],
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
2758
);
2759
is($dbi->select(table => $table1)->one->{$key1}, 1);
2760
is($dbi->select(table => $table1)->one->{$key2}, 4);
2761
is($dbi->select(table => $table1)->one->{$key3}, 3);
2762
is_deeply($param, {$key3 => 3, $key2 => 4});
2763

            
added test
Yuki Kimoto authored on 2011-10-25
2764
$dbi = DBIx::Custom->connect;
2765
eval { $dbi->execute("drop table $table1") };
2766
$dbi->execute($create_table1_2);
2767
$param = {$key3 => 3, $key2 => 4};
2768
$query = $dbi->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2769
  $param,
2770
  primary_key => [$key1, $key2], 
2771
  table => $table1,
2772
  id => [1, 2],
2773
  query => 1
added test
Yuki Kimoto authored on 2011-10-25
2774
);
micro optimization
Yuki Kimoto authored on 2011-11-16
2775
ok(ref $query);
added test
Yuki Kimoto authored on 2011-10-25
2776
is_deeply($param, {$key3 => 3, $key2 => 4});
2777

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2778
test 'model insert id and primary_key option';
2779
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2780
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2781
$dbi->execute($create_table1_2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2782
$dbi->model($table1)->insert(
cleanup
Yuki Kimoto authored on 2012-01-20
2783
  {$key3 => 3},
2784
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2785
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2786
$result = $dbi->model($table1)->select;
cleanup test
Yuki Kimoto authored on 2011-08-10
2787
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2788
is($row->{$key1}, 1);
2789
is($row->{$key2}, 2);
2790
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2791

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

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2820
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2821
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2822
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2823
  {$key3 => 4},
2824
  table => $table1,
2825
  primary_key => $key1,
2826
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2827
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2828
is($dbi->select(table => $table1)->one->{$key1}, 0);
2829
is($dbi->select(table => $table1)->one->{$key2}, 2);
2830
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2831

            
2832
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2833
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2834
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2835
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2836
$dbi->update(
cleanup
Yuki Kimoto authored on 2012-01-20
2837
  {$key3 => 4},
2838
  table => $table1,
2839
  primary_key => [$key1, $key2],
2840
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2841
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2842
is($dbi->select(table => $table1)->one->{$key1}, 1);
2843
is($dbi->select(table => $table1)->one->{$key2}, 2);
2844
is($dbi->select(table => $table1)->one->{$key3}, 4);
cleanup test
Yuki Kimoto authored on 2011-08-10
2845

            
2846

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

            
2862

            
2863
test 'delete and id option';
2864
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2865
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2866
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2867
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2868
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2869
  table => $table1,
2870
  primary_key => [$key1, $key2],
2871
  id => [1, 2],
cleanup test
Yuki Kimoto authored on 2011-08-10
2872
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2873
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2874

            
cleanup
Yuki Kimoto authored on 2011-11-01
2875
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2876
$dbi->delete(
cleanup
Yuki Kimoto authored on 2012-01-20
2877
  table => $table1,
2878
  primary_key => $key1,
2879
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2880
);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2881
is_deeply($dbi->select(table => $table1)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2882

            
2883

            
2884
test 'model delete and id option';
2885
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2886
eval { $dbi->execute("drop table $table1") };
2887
eval { $dbi->execute("drop table $table2") };
2888
eval { $dbi->execute("drop table $table3") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2889
$dbi->execute($create_table1_2);
2890
$dbi->execute($create_table2_2);
2891
$dbi->execute($create_table3);
cleanup
Yuki Kimoto authored on 2011-11-01
2892
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2893
$dbi->model($table1)->delete(id => [1, 2]);
2894
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2895
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2896
$dbi->model($table1)->delete(id => [1, 2]);
2897
is_deeply($dbi->select(table => $table1)->all, []);
cleanup
Yuki Kimoto authored on 2011-11-01
2898
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table3);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2899
$dbi->model($table3)->delete(id => [1, 2]);
2900
is_deeply($dbi->select(table => $table3)->all, []);
cleanup test
Yuki Kimoto authored on 2011-08-10
2901

            
2902

            
2903
test 'select and id option';
2904
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2905
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2906
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2907
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2908
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2909
  table => $table1,
2910
  primary_key => [$key1, $key2],
2911
  id => [1, 2]
cleanup test
Yuki Kimoto authored on 2011-08-10
2912
);
2913
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2914
is($row->{$key1}, 1);
2915
is($row->{$key2}, 2);
2916
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2917

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2918
$dbi->delete_all(table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2919
$dbi->insert({$key1 => 0, $key2 => 2, $key3 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2920
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2921
  table => $table1,
2922
  primary_key => $key1,
2923
  id => 0,
cleanup test
Yuki Kimoto authored on 2011-08-10
2924
);
2925
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2926
is($row->{$key1}, 0);
2927
is($row->{$key2}, 2);
2928
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2929

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

            
2942

            
2943
test 'model select_at';
2944
$dbi = MyDBI6->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2945
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2946
$dbi->execute($create_table1_2);
cleanup
Yuki Kimoto authored on 2011-11-01
2947
$dbi->insert({$key1 => 1, $key2 => 2, $key3 => 3}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2948
$result = $dbi->model($table1)->select(id => [1, 2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
2949
$row = $result->one;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2950
is($row->{$key1}, 1);
2951
is($row->{$key2}, 2);
2952
is($row->{$key3}, 3);
cleanup test
Yuki Kimoto authored on 2011-08-10
2953

            
2954
test 'column separator is default .';
2955
$dbi = MyDBI7->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2956
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2957
eval { $dbi->execute("drop table $table1") };
2958
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2959
$dbi->execute($create_table1);
2960
$dbi->execute($create_table2);
2961
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2962
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2963
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2964
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
2965
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2966
  column => [$model->column($table2)],
2967
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2968
);
2969
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2970
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-10
2971

            
2972
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
2973
  column => [$model->column($table2 => [$key1, $key3])],
2974
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
2975
);
2976
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
2977
        {"$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
2978

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2979
test 'separator';
2980
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
2981
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
2982
eval { $dbi->execute("drop table $table1") };
2983
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
2984
$dbi->execute($create_table1);
2985
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
2986

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2987
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2988
  table => $table1,
2989
  join => [
2990
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
2991
  ],
2992
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
2993
);
2994
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
2995
  table => $table2,
cleanup test
Yuki Kimoto authored on 2011-08-10
2996
);
2997
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
2998
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
2999
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3000
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3001
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3002
  column => [
3003
    $model->mycolumn,
3004
    {$table2 => [$key1, $key3]}
3005
  ],
3006
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3007
);
3008
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3009
        {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3010
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3011

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3012
$dbi->separator('__');
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3013
$model = $dbi->model($table1);
cleanup test
Yuki Kimoto authored on 2011-08-10
3014
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3015
  column => [
3016
    $model->mycolumn,
3017
    {$table2 => [$key1, $key3]}
3018
  ],
3019
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-10
3020
);
3021
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3022
        {$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3023
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
test cleanup
Yuki Kimoto authored on 2011-08-10
3024

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

            
3038

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3039
test 'filter_off';
3040
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3041
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3042
eval { $dbi->execute("drop table $table1") };
3043
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3044
$dbi->execute($create_table1);
3045
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-08-10
3046

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3047
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3048
  table => $table1,
3049
  join => [
3050
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3051
  ],
3052
  primary_key => [$key1],
cleanup test
Yuki Kimoto authored on 2011-08-10
3053
);
3054
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3055
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3056
$model = $dbi->model($table1);
3057
$result = $model->select(column => $key1);
3058
$result->filter($key1 => sub { $_[0] * 2 });
3059
is_deeply($result->one, {$key1 => 2});
test cleanup
Yuki Kimoto authored on 2011-08-10
3060

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3061
test 'available_datetype';
3062
$dbi = DBIx::Custom->connect;
3063
ok($dbi->can('available_datatype'));
test cleanup
Yuki Kimoto authored on 2011-08-10
3064

            
3065

            
cleanup test
Yuki Kimoto authored on 2011-08-10
3066
test 'select prefix option';
3067
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3068
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-10
3069
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3070
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3071
$rows = $dbi->select(prefix => "$key1,", column => $key2, table => $table1)->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3072
is_deeply($rows, [{$key1 => 1, $key2 => 2}], "table");
test cleanup
Yuki Kimoto authored on 2011-08-10
3073

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

            
added tests
Yuki Kimoto authored on 2011-08-26
3075
test 'mapper';
3076
$dbi = DBIx::Custom->connect;
3077
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3078
  id => {key => "$table1.id"},
3079
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3080
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added tests
Yuki Kimoto authored on 2011-08-26
3081
);
3082
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3083
"$table1.price" => 1900});
added tests
Yuki Kimoto authored on 2011-08-26
3084

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3085
$dbi = DBIx::Custom->connect;
3086
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3087
  id => {key => "$table1.id"},
3088
  author => ["$table1.author" => $dbi->like_value],
3089
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3090
);
3091
is_deeply($param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3092
"$table1.price" => 1900});
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3093

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

            
3101
$param = $dbi->mapper(param => {id => '', author => '', price => ''})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3102
  id => {key => "$table1.id"},
3103
  author => ["$table1.author" => sub { '%' . $_[0] . '%' }],
3104
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 1 }]
added tests
Yuki Kimoto authored on 2011-08-26
3105
);
3106
is_deeply($param, {});
3107

            
3108
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3109
  id => {key => "$table1.id"},
3110
  price => {key => "$table1.price", condition => 'exists'}
added tests
Yuki Kimoto authored on 2011-08-26
3111
);
3112
is_deeply($param, {"$table1.price" => undef});
3113

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

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

            
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3126
$param = $dbi->mapper(param => {price => 'a', author => 'b'})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3127
  price => sub { '%' . $_[0] },
3128
  author => 'book.author'
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3129
);
- added {key => ..., value =...
Yuki Kimoto authored on 2011-10-04
3130
is_deeply($param, {price => '%a', 'book.author' => 'b'});
- added {KEY => sub { VALUE ...
Yuki Kimoto authored on 2011-09-02
3131

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

            
3137
$where = $dbi->where;
3138
$where->clause(['and', ":${key1}{=}"]);
3139
$param = $dbi->mapper(param => {$key1 => undef}, condition => 'defined')->map;
3140
$where->param($param);
3141
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3142
$row = $result->all;
3143
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3144

            
3145
$where = $dbi->where;
3146
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
3147
$param = $dbi->mapper(param => {$key1 => [undef, undef]}, condition => 'exists')->map;
3148
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
3149
$row = $result->all;
3150
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3151
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
3152
$row = $result->all;
3153
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3154

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3167
$where = $dbi->where;
3168
$where->clause(['and', ":${key1}{=}"]);
3169
$param = $dbi->mapper(param => {$key1 => 0}, condition => 'length')
cleanup
Yuki Kimoto authored on 2012-01-20
3170
->pass([$key1, $key2])->map;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3171
$where->param($param);
3172
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3173
$row = $result->all;
3174
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
3175

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3194
$where = $dbi->where;
3195
$where->clause(['and', ":${key1}{=}"]);
3196
$param = $dbi->mapper(param => {$key1 => 7}, condition => sub { ($_[0] || '') eq 5 })->map;
3197
$where->param($param);
3198
$result = $dbi->execute("select * from $table1 $where", {$key1 => 1});
3199
$row = $result->all;
3200
is_deeply($row, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3201

            
3202
$where = $dbi->where;
3203
$param = $dbi->mapper(param => {id => 1, author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3204
  id => {key => "$table1.id"},
3205
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3206
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3207
);
3208
$where->param($param);
3209
is_deeply($where->param, {"$table1.id" => 1, "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3210
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3211

            
3212
$where = $dbi->where;
3213
$param = $dbi->mapper(param => {id => 0, author => 0, price => 0})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3214
  id => {key => "$table1.id"},
3215
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3216
  price => ["$table1.price", sub { '%' . $_[0] . '%' }, sub { $_[0] eq 0 }]
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3217
);
3218
$where->param($param);
3219
is_deeply($where->param, {"$table1.id" => 0, "$table1.author" => '%0%', "$table1.price" => '%0%'});
3220

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

            
3230
$where = $dbi->where;
3231
$param = $dbi->mapper(param => {id => undef, author => undef, price => undef}, condition => 'exists')->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3232
  id => {key => "$table1.id"},
3233
  price => {key => "$table1.price", condition => 'exists'}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3234
);
3235
is_deeply($param, {"$table1.id"  => undef,"$table1.price" => undef});
3236

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

            
3244
$where = $dbi->where;
3245
$param = $dbi->mapper(param => {id => [1, 2], author => 'Ken', price => 1900})->map(
cleanup
Yuki Kimoto authored on 2012-01-20
3246
  id => {key => "$table1.id"},
3247
  author => ["$table1.author", sub { '%' . $_[0] . '%' }],
3248
  price => {key => "$table1.price", condition => sub { $_[0] eq 1900 }}
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3249
);
3250
is_deeply($param, {"$table1.id" => [1, 2], "$table1.author" => '%Ken%',
cleanup
Yuki Kimoto authored on 2012-01-20
3251
"$table1.price" => 1900});
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3252

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3276
test 'order';
3277
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3278
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3279
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3280
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3281
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
3282
$dbi->insert({$key1 => 2, $key2 => 2}, table => $table1);
3283
$dbi->insert({$key1 => 2, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3284
my $order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3285
$order->prepend($key1, "$key2 desc");
3286
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3287
is_deeply($result->all, [{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1},
cleanup
Yuki Kimoto authored on 2012-01-20
3288
{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2}]);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3289
$order->prepend("$key1 desc");
3290
$result = $dbi->select(table => $table1, append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3291
is_deeply($result->all, [{$key1 => 2, $key2 => 4}, {$key1 => 2, $key2 => 2},
cleanup
Yuki Kimoto authored on 2012-01-20
3292
{$key1 => 1, $key2 => 3}, {$key1 => 1, $key2 => 1}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3293

            
3294
$order = $dbi->order;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3295
$order->prepend(["$table1-$key1"], ["$table1-$key2", 'desc']);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3296
$result = $dbi->select(table => $table1,
cleanup
Yuki Kimoto authored on 2012-01-20
3297
column => [[$key1 => "$table1-$key1"], [$key2 => "$table1-$key2"]],
3298
append => $order);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3299
is_deeply($result->all, [{"$table1-$key1" => 1, "$table1-$key2" => 3},
cleanup
Yuki Kimoto authored on 2012-01-20
3300
{"$table1-$key1" => 1, "$table1-$key2" => 1},
3301
{"$table1-$key1" => 2, "$table1-$key2" => 4},
3302
{"$table1-$key1" => 2, "$table1-$key2" => 2}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3303

            
3304
test 'tag_parse';
3305
$dbi = DBIx::Custom->connect;
3306
$dbi->tag_parse(0);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3307
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3308
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3309
$dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3310
eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
test cleanup
Yuki Kimoto authored on 2011-08-10
3311
ok($@);
3312

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3313
test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3314
{
cleanup
Yuki Kimoto authored on 2012-01-20
3315
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3316
  $dbi = DBIx::Custom->connect;
3317
  eval { $dbi->execute("drop table $table1") };
3318
  $dbi->execute($create_table1);
3319
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3320
  eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3321
  ok($@);
3322
  eval {$dbi->select(table => $table1, where => ["{= $key1}", {$key1 => 1}]) };
3323
  ok($@);
3324
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3325
}
3326

            
3327
{
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3329
  $dbi = DBIx::Custom->connect;
3330
  eval { $dbi->execute("drop table $table1") };
3331
  $dbi->execute($create_table1);
3332
  $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3333
  is($dbi->select(table => $table1, wher => {$key1 => 1})->one->{$key1}, 1);
3334
  delete$ENV{DBIX_CUSTOM_TAG_PARSE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3335
}
3336

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3337
test 'last_sql';
3338
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3339
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3340
$dbi->execute($create_table1);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3341
$dbi->execute("select * from $table1");
micro optimization
Yuki Kimoto authored on 2011-11-18
3342
is($dbi->last_sql, " select * from $table1");
test cleanup
Yuki Kimoto authored on 2011-08-10
3343

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

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

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

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

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

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

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

            
3384
test 'high perfomance way';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3385
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3386
$dbi->execute($create_table1_highperformance);
3387
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3388
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3389
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3390
];
3391
{
cleanup
Yuki Kimoto authored on 2012-01-20
3392
  my $query;
3393
  for my $row (@$rows) {
3394
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3395
    $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3396
  }
3397
  is_deeply($dbi->select(table => $table1)->all,
3398
    [
3399
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3400
      {$key7 => 2, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3401
    ]
3402
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3403
}
3404

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3405
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3406
$dbi->execute($create_table1_highperformance);
3407
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3408
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3409
  {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
test cleanup
Yuki Kimoto authored on 2011-08-10
3410
];
3411
{
cleanup
Yuki Kimoto authored on 2012-01-20
3412
  my $query;
3413
  my $sth;
3414
  for my $row (@$rows) {
3415
    $query ||= $dbi->insert($row, table => $table1, query => 1);
3416
    $sth ||= $query->{sth};
3417
    $sth->execute(map { $row->{$_} } sort keys %$row);
3418
  }
3419
  is_deeply($dbi->select(table => $table1)->all,
3420
    [
3421
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 7},
3422
      {$key7 => 1, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => 8},
3423
    ]
3424
  );
test cleanup
Yuki Kimoto authored on 2011-08-10
3425
}
3426

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3427
eval { $dbi->execute("drop table $table1") };
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3428
$dbi->execute($create_table1_highperformance);
3429
$rows = [
cleanup
Yuki Kimoto authored on 2012-01-20
3430
  {$key7 => 10, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5},
3431
  {$key7 => 11, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6},
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3432
];
3433
{
cleanup
Yuki Kimoto authored on 2012-01-20
3434
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3435
  my $query;
3436
  for my $row (@$rows) {
3437
    $query ||= $model->insert($row, query => 1);
3438
    $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
3439
  }
3440
  is_deeply($dbi->select(table => $table1, append => 'order by key2')->all,
3441
    [
3442
      {$key7 => 20, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 5, $key1 => undef},
3443
      {$key7 => 22, $key6 => 2, $key5 => 3, $key4 => 4, $key3 => 5, $key2 => 6, $key1 => undef},
3444
    ]
3445
  );
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
3446
}
3447

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3448
eval { $dbi->execute("drop table $table1") };
3449
$dbi->execute($create_table1);
3450
{
cleanup
Yuki Kimoto authored on 2012-01-20
3451
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3452
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3453
  eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3454
  like($@, qr/primary_key/);
3455
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3456
}
3457

            
3458
{
cleanup
Yuki Kimoto authored on 2012-01-20
3459
  $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3460
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3461
  $model->insert({$key1 => 1});
3462
  $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3463
    table => $table1, primary_key => $key1);
3464
  is($result->one->{$key1}, 1);
3465
  delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3466
}
3467

            
3468
eval { $dbi->execute("drop table $table1") };
3469
$dbi->execute($create_table1);
3470
{
cleanup
Yuki Kimoto authored on 2012-01-20
3471
  $model = $dbi->create_model(table => $table1, primary_key => $key1);
3472
  $model->insert({$key1 => 1});
3473
  eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3474
  is($result->one->{$key1}, 1);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3475
}
3476

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3477
test 'id option more';
3478
eval { $dbi->execute("drop table $table1") };
3479
$dbi->execute($create_table1_highperformance);
3480
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3481
  $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
3482
};
3483
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3484
$model->insert($row);
3485
$query = $model->update({$key7 => 11}, id => 1, query => 1);
3486
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3487
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3488
  {$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
3489
);
3490

            
3491
eval { $dbi->execute("drop table $table1") };
3492
eval { $dbi->execute("drop table $table2") };
3493
$dbi->execute($create_table1);
3494
$dbi->execute($create_table2);
3495
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3496
$model->insert({$key1 => 1, $key2 => 2});
3497
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
3498
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3499
$model->insert({$key1 => 1, $key3 => 3});
3500
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3501
  column => {$table1 => ["$key2"]},
3502
  id => 1
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3503
);
3504
is_deeply($result->all, [{"$table1.$key2" => 2}]);
3505

            
3506
eval { $dbi->execute("drop table $table1") };
3507
$dbi->execute($create_table1_highperformance);
3508
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3509
  $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
3510
};
3511
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3512
$model->insert($row);
3513
$query = $model->delete(id => 1, query => 1);
3514
$model->execute($query, {}, id => 1, , filter => {"$table1.$key1" => sub { $_[0] * 2 }});
3515
is_deeply($dbi->select(table => $table1)->all, []);
3516

            
3517
eval { $dbi->execute("drop table $table1") };
3518
eval { $dbi->execute($create_table1_highperformance) };
3519
$row = {
cleanup
Yuki Kimoto authored on 2012-01-20
3520
  $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
3521
};
3522
$model = $dbi->create_model(table => $table1, primary_key => $key1);
3523
$model->insert($row);
3524
$query = $model->select(id => 1, query => 1);
3525
$model->execute($query, {$key7 => 11}, id => 1, filter => {"$table1.$key1" => sub { $_[0] * 2 }});
fixed sqlserver test bug
Yuki Kimoto authored on 2011-10-23
3526
$query = undef;
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
3527
is_deeply($dbi->select(table => $table1)->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3528
  {$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
3529
);
3530

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3531
test 'result';
3532
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3533
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3534
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3535
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3536
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3537

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3538
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3539
@rows = ();
3540
while (my $row = $result->fetch) {
cleanup
Yuki Kimoto authored on 2012-01-20
3541
  push @rows, [@$row];
test cleanup
Yuki Kimoto authored on 2011-08-10
3542
}
3543
is_deeply(\@rows, [[1, 2], [3, 4]]);
3544

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3545
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3546
@rows = ();
3547
while (my $row = $result->fetch_hash) {
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  push @rows, {%$row};
test cleanup
Yuki Kimoto authored on 2011-08-10
3549
}
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3550
is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
3551

            
3552
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
3553
eval { $dbi->execute("drop table $table1") };
test cleanup
Yuki Kimoto authored on 2011-08-10
3554
$dbi->execute($create_table1);
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3555
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3556
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3557

            
3558
test 'fetch_all';
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3559
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3560
$rows = $result->fetch_all;
3561
is_deeply($rows, [[1, 2], [3, 4]]);
3562

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

            
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3567
$result = $dbi->select(table => $table1);
test cleanup
Yuki Kimoto authored on 2011-08-10
3568
$result->dbi->filters({three_times => sub { $_[0] * 3}});
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
3569
$result->filter({$key1 => 'three_times'});
test cleanup
Yuki Kimoto authored on 2011-08-10
3570
$rows = $result->fetch_all;
3571
is_deeply($rows, [[3, 2], [9, 4]], "array");
3572

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2012-02-28
3585
test 'flat';
3586
$result = $dbi->select(table => $table1);
3587
$rows = [$result->flat];
3588
is_deeply($rows, [1, 2, 3, 4]);
3589

            
added EXPERIMETAL DBIx::Cust...
Yuki Kimoto authored on 2012-02-28
3590
test 'kv';
3591
$dbi = DBIx::Custom->connect;
3592
eval { $dbi->execute("drop table $table1") };
3593
$dbi->execute($create_table1);
3594
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3595
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3596

            
3597
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key1");
3598
$rows = $result->kv;
3599
is_deeply($rows, {0 => {$key2 => 2}, 3 => {$key2 => 4}});
3600

            
3601
$dbi = DBIx::Custom->connect;
3602
eval { $dbi->execute("drop table $table1") };
3603
$dbi->execute($create_table1);
3604
$dbi->insert({$key1 => 0, $key2 => 1}, table => $table1);
3605
$dbi->insert({$key1 => 0, $key2 => 2}, table => $table1);
3606
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3607
$dbi->insert({$key1 => 3, $key2 => 5}, table => $table1);
3608

            
3609
$result = $dbi->select([$key1, $key2], table => $table1, append => "order by $key2");
3610
$rows = $result->kv(multi => 1);
3611
is_deeply($rows, {
3612
  0 => [
3613
    {$key2 => 1},
3614
    {$key2 => 2}
3615
  ],
3616
  3 => [
3617
    {$key2 => 4},
3618
    {$key2 => 5}
3619
  ]
3620
});
3621

            
3622

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3623
test 'DBIx::Custom::Result fetch_multi';
3624
eval { $dbi->execute("drop table $table1") };
3625
$dbi->execute($create_table1);
3626
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3627
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3628
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3629
$result = $dbi->select(table => $table1);
3630
$rows = $result->fetch_multi(2);
3631
is_deeply($rows, [[1, 2], [3, 4]]);
3632
$rows = $result->fetch_multi(2);
3633
is_deeply($rows, [[5, 6]]);
3634
$rows = $result->fetch_multi(2);
3635
ok(!$rows);
3636

            
3637
test 'DBIx::Custom::Result fetch_hash_multi';
3638
eval { $dbi->execute("drop table $table1") };
3639
$dbi->execute($create_table1);
3640
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3641
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3642
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3643
$result = $dbi->select(table => $table1);
3644
$rows = $result->fetch_hash_multi(2);
3645
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3646
$rows = $result->fetch_hash_multi(2);
3647
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3648
$rows = $result->fetch_hash_multi(2);
3649
ok(!$rows);
3650

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3651
test "query_builder";
3652
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3653
  # Basic tests
3654
  {   name            => 'placeholder basic',
3655
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3656
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3657
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3658
  },
3659
  {
3660
    name            => 'placeholder in',
3661
    source            => "{in k1 3}",
3662
    sql_expected    => "k1 in (?, ?, ?)",
3663
    columns_expected   => [qw/k1 k1 k1/]
3664
  },
3665
  
3666
  # Table name
3667
  {
3668
    name            => 'placeholder with table name',
3669
    source            => "{= a.k1} {= a.k2}",
3670
    sql_expected    => "a.k1 = ? a.k2 = ?",
3671
    columns_expected  => [qw/a.k1 a.k2/]
3672
  },
3673
  {   
3674
    name            => 'placeholder in with table name',
3675
    source            => "{in a.k1 2} {in b.k2 2}",
3676
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3677
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3678
  },
3679
  {
3680
    name            => 'not contain tag',
3681
    source            => "aaa",
3682
    sql_expected    => "aaa",
3683
    columns_expected  => [],
3684
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3685
];
3686

            
3687
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3688
  my $data = $datas->[$i];
3689
  my $dbi = DBIx::Custom->new;
3690
  my $builder = $dbi->query_builder;
3691
  my $query = $builder->build_query($data->{source});
3692
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3693
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3694
}
3695

            
cleanup
Yuki Kimoto authored on 2011-08-13
3696
$dbi = DBIx::Custom->new;
3697
$builder = $dbi->query_builder;
3698
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3699
  p => sub {
3700
    my @args = @_;
3701
    
3702
    my $expand    = "? $args[0] $args[1]";
3703
    my $columns = [2];
3704
    return [$expand, $columns];
3705
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3706
);
3707

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3718
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3719
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3720
});
3721

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3725
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3726
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3727
});
3728

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

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

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

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

            
3743

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

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

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

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

            
3759
test 'variouse source';
3760
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3761
$query = $builder->build_query($source);
3762
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3763

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

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

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

            
3776
$source = "a {= b} }";
3777
eval{$builder->build_query($source)};
3778
like($@, qr/unexpected "}"/, "error : 1");
3779

            
3780
$source = "a {= {}";
3781
eval{$builder->build_query($source)};
3782
like($@, qr/unexpected "{"/, "error : 2");
3783

            
3784
test 'select() sqlfilter option';
3785
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3786
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3787
eval { $dbi->execute("drop table $table1") };
3788
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3789
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3790
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3791
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3792
  table => $table1,
3793
  column => $key1,
3794
  sqlfilter => sub {
3795
    my $sql = shift;
3796
    $sql = "select * from ( $sql ) t where $key1 = 1";
3797
    return $sql;
3798
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3799
)->all;
3800
is_deeply($rows, [{$key1 => 1}]);
3801

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3820
test 'dbi method from model';
3821
$dbi = MyDBI9->connect;
3822
eval { $dbi->execute("drop table $table1") };
3823
$dbi->execute($create_table1);
3824
$dbi->setup_model;
3825
$model = $dbi->model($table1);
3826
eval{$model->execute("select * from $table1")};
3827
ok(!$@);
3828

            
3829
test 'column table option';
3830
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3831
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3832
eval { $dbi->execute("drop table $table1") };
3833
$dbi->execute($create_table1);
3834
eval { $dbi->execute("drop table $table2") };
3835
$dbi->execute($create_table2);
3836
$dbi->setup_model;
3837
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3838
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3839
$model = $dbi->model($table1);
3840
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3841
  column => [
3842
    $model->column($table2, {alias => $table2_alias})
3843
  ],
3844
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3845
);
3846
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3847
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3848

            
3849
$dbi->separator('__');
3850
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3851
  column => [
3852
    $model->column($table2, {alias => $table2_alias})
3853
  ],
3854
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3855
);
3856
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3857
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3858

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

            
3869
test 'create_model';
3870
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3871
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3872
eval { $dbi->execute("drop table $table1") };
3873
eval { $dbi->execute("drop table $table2") };
3874
$dbi->execute($create_table1);
3875
$dbi->execute($create_table2);
3876

            
3877
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3878
  table => $table1,
3879
  join => [
3880
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3881
  ],
3882
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3883
);
3884
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3885
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3886
);
3887
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3888
  table => $table3,
3889
  filter => [
3890
    $key1 => {in => sub { uc $_[0] }}
3891
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3892
);
3893
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3894
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3895
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3896
$model = $dbi->model($table1);
3897
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3898
  column => [$model->mycolumn, $model->column($table2)],
3899
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3900
);
3901
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3902
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3903
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3904

            
3905
test 'model method';
3906
$dbi = DBIx::Custom->connect;
3907
eval { $dbi->execute("drop table $table2") };
3908
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3909
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3910
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3911
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3912
);
3913
$model->method(foo => sub { shift->select(@_) });
3914
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3915

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

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

            
3934
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3935
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3936
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3937
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3938
where $key1 = 1
3939
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3940
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3941
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3942
$rows   = $result->all;
3943
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3944
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3945
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3946

            
3947

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

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4019
test 'Model class';
4020
$dbi = MyDBI1->connect;
4021
eval { $dbi->execute("drop table $table1") };
4022
$dbi->execute($create_table1);
4023
$model = $dbi->model($table1);
4024
$model->insert({$key1 => 'a', $key2 => 'b'});
4025
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4026
eval { $dbi->execute("drop table $table2") };
4027
$dbi->execute($create_table2);
4028
$model = $dbi->model($table2);
4029
$model->insert({$key1 => 'a'});
4030
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4031
is($dbi->models->{$table1}, $dbi->model($table1));
4032
is($dbi->models->{$table2}, $dbi->model($table2));
4033

            
4034
$dbi = MyDBI4->connect;
4035
eval { $dbi->execute("drop table $table1") };
4036
$dbi->execute($create_table1);
4037
$model = $dbi->model($table1);
4038
$model->insert({$key1 => 'a', $key2 => 'b'});
4039
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
4040
eval { $dbi->execute("drop table $table2") };
4041
$dbi->execute($create_table2);
4042
$model = $dbi->model($table2);
4043
$model->insert({$key1 => 'a'});
4044
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4045

            
4046
$dbi = MyDBI5->connect;
4047
eval { $dbi->execute("drop table $table1") };
4048
eval { $dbi->execute("drop table $table2") };
4049
$dbi->execute($create_table1);
4050
$dbi->execute($create_table2);
4051
$model = $dbi->model($table2);
4052
$model->insert({$key1 => 'a'});
4053
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4054
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4055
$model = $dbi->model($table1);
4056
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4057

            
4058
test 'primary_key';
4059
$dbi = MyDBI1->connect;
4060
$model = $dbi->model($table1);
4061
$model->primary_key([$key1, $key2]);
4062
is_deeply($model->primary_key, [$key1, $key2]);
4063

            
4064
test 'columns';
4065
$dbi = MyDBI1->connect;
4066
$model = $dbi->model($table1);
4067
$model->columns([$key1, $key2]);
4068
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4069

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4070
test 'setup_model';
4071
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4072
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4073
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4074
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4075

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4076
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4077
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4078
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4079
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4080
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4081

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4082
test 'each_column';
4083
$dbi = DBIx::Custom->connect;
4084
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4085
eval { $dbi->execute("drop table $table1") };
4086
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4087
eval { $dbi->execute("drop table $table3") };
4088
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4089
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4090

            
4091
$infos = [];
4092
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4093
  my ($self, $table, $column, $cinfo) = @_;
4094
  
4095
  if ($table =~ /^table\d/i) {
4096
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4097
     push @$infos, $info;
4098
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4099
});
4100
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4101
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4102
  [
4103
    [$table1, $key1, $key1],
4104
    [$table1, $key2, $key2],
4105
    [$table2, $key1, $key1],
4106
    [$table2, $key3, $key3]
4107
  ]
4108
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4109
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4110

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4111
test 'each_table';
4112
$dbi = DBIx::Custom->connect;
4113
eval { $dbi->execute("drop table $table1") };
4114
eval { $dbi->execute("drop table $table2") };
4115
$dbi->execute($create_table2);
4116
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4117

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4118
$infos = [];
4119
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4120
  my ($self, $table, $table_info) = @_;
4121
  
4122
  if ($table =~ /^table\d/i) {
4123
    my $info = [$table, $table_info->{TABLE_NAME}];
4124
    push @$infos, $info;
4125
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4126
});
4127
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4128
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4129
  [
4130
    [$table1, $table1],
4131
    [$table2, $table2],
4132
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4133
);
4134

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4135
$dbi = DBIx::Custom->connect;
4136
eval { $dbi->execute("drop table $table1") };
4137
eval { $dbi->execute("drop table $table2") };
4138
$dbi->execute($create_table2);
4139
$dbi->execute($create_table1_type);
4140

            
4141
$infos = [];
4142
$dbi->user_table_info($user_table_info);
4143
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4144
  my ($self, $table, $table_info) = @_;
4145
  
4146
  if ($table =~ /^table\d/i) {
4147
     my $info = [$table, $table_info->{TABLE_NAME}];
4148
     push @$infos, $info;
4149
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4150
});
4151
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4152
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4153
  [
4154
    [$table1, $table1],
4155
    [$table2, $table2],
4156
    [$table3, $table3],
4157
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4158
);
4159

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4160
test 'type_rule into';
4161
eval { $dbi->execute("drop table $table1") };
4162
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4163
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4164

            
4165

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

            
cleanup
Yuki Kimoto authored on 2011-08-16
4170
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4171
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4172
  into1 => {
4173
    $date_typename => sub { '2010-' . $_[0] }
4174
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4175
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4176
$dbi->insert({$key1 => '01-01'}, table => $table1);
4177
$result = $dbi->select(table => $table1);
4178
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4179

            
4180
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4181
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4182
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4183
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4184
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4185
  into1 => [
4186
     [$date_typename, $datetime_typename] => sub {
4187
        my $value = shift;
4188
        $value =~ s/02/03/g;
4189
        return $value;
4190
     }
4191
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4192
);
4193
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4194
$result = $dbi->select(table => $table1);
4195
$row = $result->one;
4196
like($row->{$key1}, qr/^2010-01-03/);
4197
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4198

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

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

            
4244
$dbi = DBIx::Custom->connect;
4245
eval { $dbi->execute("drop table $table1") };
4246
$dbi->execute($create_table1_type);
4247
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4248
  my $value = shift || '';
4249
  $value =~ s/02/03/;
4250
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4251
});
cleanup
Yuki Kimoto authored on 2011-08-16
4252
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4253
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4254
  from1 => {
4255
    $date_datatype => 'convert',
4256
  },
4257
  into1 => {
4258
      $date_typename => 'convert',
4259
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4260
);
4261
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4262
$result = $dbi->select(table => $table1);
4263
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4264
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4265
$row = $result->fetch;
4266
like($row->[0], qr/^2010-03-03/);
4267
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4268

            
4269
test 'type_rule and filter order';
4270
$dbi = DBIx::Custom->connect;
4271
eval { $dbi->execute("drop table $table1") };
4272
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4273
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4274
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4275
  into1 => {
4276
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4277
  },
4278
  into2 => {
4279
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4280
  },
4281
  from1 => {
4282
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4283
  },
4284
  from2 => {
4285
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4286
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4287
);
4288
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4289
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4290
$result = $dbi->select(table => $table1);
4291
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4292
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4293

            
4294

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4321
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4322
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4323
eval { $dbi->execute("drop table $table1") };
4324
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4325
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4326
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4327
  from1 => {
4328
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4329
  },
4330
  into1 => {
4331
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4332
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4333
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4334
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4335
$result = $dbi->select(table => $table1, type_rule_off => 1);
4336
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4337

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4400
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4401
  into1 => {
4402
    $date_typename => 'pp'
4403
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4404
)};
4405
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4406

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4407
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4408
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4409
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4410
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4411
  $dbi->type_rule(
4412
    from1 => {
4413
      Date => sub { $_[0] * 2 },
4414
    }
4415
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4416
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4417
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4418

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4419
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4420
  $dbi->type_rule(
4421
    into1 => {
4422
      Date => sub { $_[0] * 2 },
4423
    }
4424
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4425
};
4426
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4427

            
4428
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4429
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4430
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4431
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4432
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4433
  from1 => {
4434
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4435
  },
4436
  into1 => {
4437
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4438
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4439
);
4440
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4441
$result = $dbi->select(table => $table1);
4442
$result->type_rule_off;
4443
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4444

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

            
4466
$result = $dbi->select(table => $table1);
4467
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4468
  from1 => {
4469
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4470
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4471
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4472
$row = $result->one;
4473
like($row->{$key1}, qr/2010-01-05/);
4474
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4475

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

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

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

            
4503
$result = $dbi->select(table => $table1);
4504
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4505
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4506
);
4507
$row = $result->one;
4508
like($row->{$key1}, qr/^2010-01-03/);
4509
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4510

            
4511
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4512
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4513
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4514
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4515
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4516
  from1 => {
4517
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4518
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4519
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4520
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4521
$result = $dbi->select(table => $table1);
4522
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4523
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4524

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4539
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4540
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4541
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4542
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4543
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4544
  into1 => {
4545
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4546
  },
4547
  into2 => {
4548
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4549
  },
4550
  from1 => {
4551
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4552
  },
4553
  from2 => {
4554
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4555
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4556
);
4557
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4558
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4559
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4560
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4561
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4562

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4611
test 'join';
4612
$dbi = DBIx::Custom->connect;
4613
eval { $dbi->execute("drop table $table1") };
4614
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4615
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4616
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4617
eval { $dbi->execute("drop table $table2") };
4618
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4619
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4620
eval { $dbi->execute("drop table $table3") };
4621
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4622
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4623
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4624
  table => $table1,
4625
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4626
  where   => {"$table1.$key2" => 2},
4627
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4628
)->all;
4629
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4630

            
4631
$dbi = DBIx::Custom->connect;
4632
eval { $dbi->execute("drop table $table1") };
4633
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4634
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4635
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4636
eval { $dbi->execute("drop table $table2") };
4637
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4638
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4639
eval { $dbi->execute("drop table $table3") };
4640
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4641
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4642
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4643
  table => $table1,
4644
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4645
  where   => {"$table1.$key2" => 2},
4646
  join  => {
4647
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4648
    table => [$table1, $table2]
4649
  }
added test
Yuki Kimoto authored on 2011-10-27
4650
)->all;
4651
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
4652

            
4653
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4654
  table => $table1,
4655
  where   => {$key1 => 1},
4656
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4657
)->all;
4658
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4659

            
4660
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4661
  table => $table1,
4662
  where   => {$key1 => 1},
4663
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4664
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4665
)->all;
4666
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4667

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

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

            
4686
$dbi = DBIx::Custom->connect;
4687
eval { $dbi->execute("drop table $table1") };
4688
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4689
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4690
eval { $dbi->execute("drop table $table2") };
4691
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4692
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4693
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4694
  table => $table1,
4695
  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",
4696
  where   => {"$table1.$key2" => 2},
4697
  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
4698
)->all;
4699
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4700
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4701

            
4702

            
4703
$dbi = DBIx::Custom->connect;
4704
eval { $dbi->execute("drop table $table1") };
4705
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4706
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4707
$sql = <<"EOS";
4708
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4709
select * from $table1 t1
4710
where t1.$key2 = (
4711
  select max(t2.$key2) from $table1 t2
4712
  where t1.$key1 = t2.$key1
4713
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4714
) $table3 on $table1.$key1 = $table3.$key1
4715
EOS
4716
$join = [$sql];
4717
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4718
  table => $table1,
4719
  column => "$table3.$key1 as ${table3}__$key1",
4720
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4721
)->all;
4722
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4723

            
4724
$dbi = DBIx::Custom->connect;
4725
eval { $dbi->execute("drop table $table1") };
4726
eval { $dbi->execute("drop table $table2") };
4727
$dbi->execute($create_table1);
4728
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4729
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4730
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4731
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4732
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4733
  table => $table1,
4734
  join => [
4735
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4736
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4737
);
4738
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4739
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4740
  table => $table1,
4741
  column => [{$table2 => [$key3]}],
4742
  join => [
4743
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4744
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4745
);
4746
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4747
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4748
  table => $table1,
4749
  column => [{$table2 => [$key3]}],
4750
  join => [
4751
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4752
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4753
);
4754
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4755

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4776
$dbi = DBIx::Custom->connect;
4777
eval { $dbi->execute("drop table $table1") };
4778
eval { $dbi->execute("drop table $table2") };
4779
$dbi->execute($create_table1);
4780
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4781
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4782
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4783
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4784
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4785
  table => $table1,
4786
  column => [{$table2 => [$key3]}],
4787
  join => [
4788
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4789
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4790
);
4791
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4792

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4810
test 'columns';
4811
$dbi = MyDBI1->connect;
4812
$model = $dbi->model($table1);
4813

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4814
test 'count';
4815
$dbi = DBIx::Custom->connect;
4816
eval { $dbi->execute("drop table $table1") };
4817
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4818
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4819
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4820
is($dbi->count(table => $table1), 2);
4821
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4822
$model = $dbi->create_model(table => $table1);
4823
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4824

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4825
eval { $dbi->execute("drop table $table1") };
4826
eval { $dbi->execute("drop table $table2") };
4827
$dbi->execute($create_table1);
4828
$dbi->execute($create_table2);
4829
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4830
$model->insert({$key1 => 1, $key2 => 2});
4831
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4832
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4833
$model->insert({$key1 => 1, $key3 => 3});
4834
is($model->count(id => 1), 1);
4835
is($model->count(where => {"$table2.$key3" => 3}), 1);
4836

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