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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1380
test 'filters';
1381
$dbi = DBIx::Custom->new;
1382

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

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

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

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

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

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

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

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

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

            
1447

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

            
1453
$dbi->begin_work;
1454

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

            
1461
$dbi->rollback if $@;
1462

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

            
1467
$dbi->begin_work;
1468

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

            
1474
$dbi->commit unless $@;
1475

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

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

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

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

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

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

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

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

            
1546
is($dbi->one, 1, "first");
1547
is($dbi->two, 2, "second");
1548
is($dbi->twice(5), 10 , "second");
1549

            
1550
eval {$dbi->XXXXXX};
1551
ok($@, "not exists");
1552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1901
$where = $dbi->where;
1902
is("$where", '');
1903

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2073
eval {$dbi->where(ppp => 1) };
2074
like($@, qr/invalid/);
2075

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

            
2087

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

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

            
2106
$where = $dbi->where;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2107
$where->clause(['or', ":${key1}{=}", ":${key1}{=}"]);
2108
$where->param({$key1 => [undef, undef]});
2109
$result = $dbi->execute("select * from $table1 $where", {$key1 => [1, 0]});
test cleanup
Yuki Kimoto authored on 2011-08-10
2110
$row = $result->all;
test cleanup in progress
Yuki Kimoto authored on 2011-08-15
2111
is_deeply($row, [{$key1 => 1, $key2 => 2}]);
2112
$result = $dbi->execute("select * from $table1 $where", {$key1 => [0, 1]});
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}]);
test cleanup
Yuki Kimoto authored on 2011-08-10
2115

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

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

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

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

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

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

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

            
2157
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
2158
like($@, qr/apply_filter/);
2159

            
2160
$dbi->apply_filter(
2161

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

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

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

            
2190
eval{DBIx::Custom->connect(dsn => undef)};
2191
like($@, qr/_connect/);
2192

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2447

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2664

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2843

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

            
2859

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

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

            
2880

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

            
2899

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

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

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

            
2939

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

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

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

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

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

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

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

            
3035

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

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

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

            
3062

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3582
test 'DBIx::Custom::Result fetch_multi';
3583
eval { $dbi->execute("drop table $table1") };
3584
$dbi->execute($create_table1);
3585
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3586
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3587
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3588
$result = $dbi->select(table => $table1);
3589
$rows = $result->fetch_multi(2);
3590
is_deeply($rows, [[1, 2], [3, 4]]);
3591
$rows = $result->fetch_multi(2);
3592
is_deeply($rows, [[5, 6]]);
3593
$rows = $result->fetch_multi(2);
3594
ok(!$rows);
3595

            
3596
test 'DBIx::Custom::Result fetch_hash_multi';
3597
eval { $dbi->execute("drop table $table1") };
3598
$dbi->execute($create_table1);
3599
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3600
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
3601
$dbi->insert({$key1 => 5, $key2 => 6}, table => $table1);
3602
$result = $dbi->select(table => $table1);
3603
$rows = $result->fetch_hash_multi(2);
3604
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}]);
3605
$rows = $result->fetch_hash_multi(2);
3606
is_deeply($rows, [{$key1 => 5, $key2 => 6}]);
3607
$rows = $result->fetch_hash_multi(2);
3608
ok(!$rows);
3609

            
test cleanup
Yuki Kimoto authored on 2011-08-10
3610
test "query_builder";
3611
$datas = [
cleanup
Yuki Kimoto authored on 2012-01-20
3612
  # Basic tests
3613
  {   name            => 'placeholder basic',
3614
    source            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
3615
    sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?",
3616
    columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
3617
  },
3618
  {
3619
    name            => 'placeholder in',
3620
    source            => "{in k1 3}",
3621
    sql_expected    => "k1 in (?, ?, ?)",
3622
    columns_expected   => [qw/k1 k1 k1/]
3623
  },
3624
  
3625
  # Table name
3626
  {
3627
    name            => 'placeholder with table name',
3628
    source            => "{= a.k1} {= a.k2}",
3629
    sql_expected    => "a.k1 = ? a.k2 = ?",
3630
    columns_expected  => [qw/a.k1 a.k2/]
3631
  },
3632
  {   
3633
    name            => 'placeholder in with table name',
3634
    source            => "{in a.k1 2} {in b.k2 2}",
3635
    sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?)",
3636
    columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
3637
  },
3638
  {
3639
    name            => 'not contain tag',
3640
    source            => "aaa",
3641
    sql_expected    => "aaa",
3642
    columns_expected  => [],
3643
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3644
];
3645

            
3646
for (my $i = 0; $i < @$datas; $i++) {
cleanup
Yuki Kimoto authored on 2012-01-20
3647
  my $data = $datas->[$i];
3648
  my $dbi = DBIx::Custom->new;
3649
  my $builder = $dbi->query_builder;
3650
  my $query = $builder->build_query($data->{source});
3651
  is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql");
3652
  is_deeply($query->{columns}, $data->{columns_expected}, "$data->{name} : columns");
test cleanup
Yuki Kimoto authored on 2011-08-10
3653
}
3654

            
cleanup
Yuki Kimoto authored on 2011-08-13
3655
$dbi = DBIx::Custom->new;
3656
$builder = $dbi->query_builder;
3657
$dbi->register_tag(
cleanup
Yuki Kimoto authored on 2012-01-20
3658
  p => sub {
3659
    my @args = @_;
3660
    
3661
    my $expand    = "? $args[0] $args[1]";
3662
    my $columns = [2];
3663
    return [$expand, $columns];
3664
  }
test cleanup
Yuki Kimoto authored on 2011-08-10
3665
);
3666

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3677
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3678
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3679
});
3680

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3684
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3685
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3686
});
3687

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

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

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

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

            
3702

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

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

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

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

            
3718
test 'variouse source';
3719
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3720
$query = $builder->build_query($source);
3721
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3722

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

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

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

            
3735
$source = "a {= b} }";
3736
eval{$builder->build_query($source)};
3737
like($@, qr/unexpected "}"/, "error : 1");
3738

            
3739
$source = "a {= {}";
3740
eval{$builder->build_query($source)};
3741
like($@, qr/unexpected "{"/, "error : 2");
3742

            
3743
test 'select() sqlfilter option';
3744
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3745
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3746
eval { $dbi->execute("drop table $table1") };
3747
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3748
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3749
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
3750
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3751
  table => $table1,
3752
  column => $key1,
3753
  sqlfilter => sub {
3754
    my $sql = shift;
3755
    $sql = "select * from ( $sql ) t where $key1 = 1";
3756
    return $sql;
3757
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
3758
)->all;
3759
is_deeply($rows, [{$key1 => 1}]);
3760

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3761
test 'select() after_build_sql option';
3762
$dbi = DBIx::Custom->connect;
3763
$dbi->user_table_info($user_table_info);
3764
eval { $dbi->execute("drop table $table1") };
3765
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
3766
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3767
$dbi->insert({$key1 => 2, $key2 => 3}, table => $table1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3768
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3769
  table => $table1,
3770
  column => $key1,
3771
  after_build_sql => sub {
3772
    my $sql = shift;
3773
    $sql = "select * from ( $sql ) t where $key1 = 1";
3774
    return $sql;
3775
  }
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3776
)->all;
3777
is_deeply($rows, [{$key1 => 1}]);
3778

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3779
test 'dbi method from model';
3780
$dbi = MyDBI9->connect;
3781
eval { $dbi->execute("drop table $table1") };
3782
$dbi->execute($create_table1);
3783
$dbi->setup_model;
3784
$model = $dbi->model($table1);
3785
eval{$model->execute("select * from $table1")};
3786
ok(!$@);
3787

            
3788
test 'column table option';
3789
$dbi = MyDBI9->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3790
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3791
eval { $dbi->execute("drop table $table1") };
3792
$dbi->execute($create_table1);
3793
eval { $dbi->execute("drop table $table2") };
3794
$dbi->execute($create_table2);
3795
$dbi->setup_model;
3796
$dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3797
$dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3798
$model = $dbi->model($table1);
3799
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3800
  column => [
3801
    $model->column($table2, {alias => $table2_alias})
3802
  ],
3803
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3804
);
3805
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3806
        {"$table2_alias.$key1" => 1, "$table2_alias.$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3807

            
3808
$dbi->separator('__');
3809
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3810
  column => [
3811
    $model->column($table2, {alias => $table2_alias})
3812
  ],
3813
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3814
);
3815
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3816
  {"${table2_alias}__$key1" => 1, "${table2_alias}__$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3817

            
3818
$dbi->separator('-');
3819
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3820
  column => [
3821
      $model->column($table2, {alias => $table2_alias})
3822
  ],
3823
  where => {"$table2_alias.$key3" => 4}
cleanup test
Yuki Kimoto authored on 2011-08-15
3824
);
3825
is_deeply($result->one, 
cleanup
Yuki Kimoto authored on 2012-01-20
3826
  {"$table2_alias-$key1" => 1, "$table2_alias-$key3" => 4});
cleanup test
Yuki Kimoto authored on 2011-08-15
3827

            
3828
test 'create_model';
3829
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3830
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3831
eval { $dbi->execute("drop table $table1") };
3832
eval { $dbi->execute("drop table $table2") };
3833
$dbi->execute($create_table1);
3834
$dbi->execute($create_table2);
3835

            
3836
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3837
  table => $table1,
3838
  join => [
3839
   "left outer join $table2 on $table1.$key1 = $table2.$key1"
3840
  ],
3841
  primary_key => [$key1]
cleanup test
Yuki Kimoto authored on 2011-08-15
3842
);
3843
$model2 = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3844
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3845
);
3846
$dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3847
  table => $table3,
3848
  filter => [
3849
    $key1 => {in => sub { uc $_[0] }}
3850
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
3851
);
3852
$dbi->setup_model;
test cleanup
Yuki Kimoto authored on 2011-11-01
3853
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
3854
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3855
$model = $dbi->model($table1);
3856
$result = $model->select(
cleanup
Yuki Kimoto authored on 2012-01-20
3857
  column => [$model->mycolumn, $model->column($table2)],
3858
  where => {"$table1.$key1" => 1}
cleanup test
Yuki Kimoto authored on 2011-08-15
3859
);
3860
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2012-01-20
3861
  {$key1 => 1, $key2 => 2, "$table2.$key1" => 1, "$table2.$key3" => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3862
is_deeply($model2->select->one, {$key1 => 1, $key3 => 3});
3863

            
3864
test 'model method';
3865
$dbi = DBIx::Custom->connect;
3866
eval { $dbi->execute("drop table $table2") };
3867
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3868
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
3869
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3870
  table => $table2
cleanup test
Yuki Kimoto authored on 2011-08-15
3871
);
3872
$model->method(foo => sub { shift->select(@_) });
3873
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3874

            
3875
test 'model helper';
3876
$dbi = DBIx::Custom->connect;
3877
eval { $dbi->execute("drop table $table2") };
3878
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
3879
$dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3880
$model = $dbi->create_model(
cleanup
Yuki Kimoto authored on 2012-01-20
3881
  table => $table2
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3882
);
3883
$model->helper(foo => sub { shift->select(@_) });
3884
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
cleanup test
Yuki Kimoto authored on 2011-08-15
3885

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

            
3893
$param = {$key2 => 11};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3894
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3895
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3896
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3897
where $key1 = 1
3898
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3899
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3900
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3901
$rows   = $result->all;
3902
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3903
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3904
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3905

            
3906

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

            
3913
$param = {$key2 => 11, $key3 => 33};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3914
$assign_clause = $dbi->assign_clause($param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3915
$sql = <<"EOS";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3916
update $table1 set $assign_clause
cleanup test
Yuki Kimoto authored on 2011-08-15
3917
where $key1 = 1
3918
EOS
cleanup
Yuki Kimoto authored on 2011-11-01
3919
$dbi->execute($sql, $param);
cleanup test
Yuki Kimoto authored on 2011-08-15
3920
$result = $dbi->execute("select * from $table1 order by $key1", table => $table1);
3921
$rows   = $result->all;
3922
is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5},
cleanup
Yuki Kimoto authored on 2012-01-20
3923
  {$key1 => 6, $key2 => 7,  $key3 => 8, $key4 => 9, $key5 => 10}],
3924
  "basic");
cleanup test
Yuki Kimoto authored on 2011-08-15
3925

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
3978
test 'Model class';
3979
$dbi = MyDBI1->connect;
3980
eval { $dbi->execute("drop table $table1") };
3981
$dbi->execute($create_table1);
3982
$model = $dbi->model($table1);
3983
$model->insert({$key1 => 'a', $key2 => 'b'});
3984
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3985
eval { $dbi->execute("drop table $table2") };
3986
$dbi->execute($create_table2);
3987
$model = $dbi->model($table2);
3988
$model->insert({$key1 => 'a'});
3989
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
3990
is($dbi->models->{$table1}, $dbi->model($table1));
3991
is($dbi->models->{$table2}, $dbi->model($table2));
3992

            
3993
$dbi = MyDBI4->connect;
3994
eval { $dbi->execute("drop table $table1") };
3995
$dbi->execute($create_table1);
3996
$model = $dbi->model($table1);
3997
$model->insert({$key1 => 'a', $key2 => 'b'});
3998
is_deeply($model->list->all, [{$key1 => 'a', $key2 => 'b'}], 'basic');
3999
eval { $dbi->execute("drop table $table2") };
4000
$dbi->execute($create_table2);
4001
$model = $dbi->model($table2);
4002
$model->insert({$key1 => 'a'});
4003
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'basic');
4004

            
4005
$dbi = MyDBI5->connect;
4006
eval { $dbi->execute("drop table $table1") };
4007
eval { $dbi->execute("drop table $table2") };
4008
$dbi->execute($create_table1);
4009
$dbi->execute($create_table2);
4010
$model = $dbi->model($table2);
4011
$model->insert({$key1 => 'a'});
4012
is_deeply($model->list->all, [{$key1 => 'a', $key3 => undef}], 'include all model');
cleanup
Yuki Kimoto authored on 2011-11-01
4013
$dbi->insert({$key1 => 1}, table => $table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4014
$model = $dbi->model($table1);
4015
is_deeply($model->list->all, [{$key1 => 1, $key2 => undef}], 'include all model');
4016

            
4017
test 'primary_key';
4018
$dbi = MyDBI1->connect;
4019
$model = $dbi->model($table1);
4020
$model->primary_key([$key1, $key2]);
4021
is_deeply($model->primary_key, [$key1, $key2]);
4022

            
4023
test 'columns';
4024
$dbi = MyDBI1->connect;
4025
$model = $dbi->model($table1);
4026
$model->columns([$key1, $key2]);
4027
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4028

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4029
test 'setup_model';
4030
$dbi = MyDBI1->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
4031
$dbi->user_table_info($user_table_info);
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4032
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4033
eval { $dbi->execute("drop table $table2") };
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
4034

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4035
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4036
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4037
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4038
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4039
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4040

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4041
test 'each_column';
4042
$dbi = DBIx::Custom->connect;
4043
eval { $dbi->execute("drop table ${q}table$p") };
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4044
eval { $dbi->execute("drop table $table1") };
4045
eval { $dbi->execute("drop table $table2") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4046
eval { $dbi->execute("drop table $table3") };
4047
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4048
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-15
4049

            
4050
$infos = [];
4051
$dbi->each_column(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4052
  my ($self, $table, $column, $cinfo) = @_;
4053
  
4054
  if ($table =~ /^table\d/i) {
4055
     my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
4056
     push @$infos, $info;
4057
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4058
});
4059
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4060
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4061
  [
4062
    [$table1, $key1, $key1],
4063
    [$table1, $key2, $key2],
4064
    [$table2, $key1, $key1],
4065
    [$table2, $key3, $key3]
4066
  ]
4067
  
cleanup test
Yuki Kimoto authored on 2011-08-10
4068
);
cleanup test
Yuki Kimoto authored on 2011-08-16
4069

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4070
test 'each_table';
4071
$dbi = DBIx::Custom->connect;
4072
eval { $dbi->execute("drop table $table1") };
4073
eval { $dbi->execute("drop table $table2") };
4074
$dbi->execute($create_table2);
4075
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4076

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4077
$infos = [];
4078
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4079
  my ($self, $table, $table_info) = @_;
4080
  
4081
  if ($table =~ /^table\d/i) {
4082
    my $info = [$table, $table_info->{TABLE_NAME}];
4083
    push @$infos, $info;
4084
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4085
});
4086
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4087
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4088
  [
4089
    [$table1, $table1],
4090
    [$table2, $table2],
4091
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4092
);
4093

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4094
$dbi = DBIx::Custom->connect;
4095
eval { $dbi->execute("drop table $table1") };
4096
eval { $dbi->execute("drop table $table2") };
4097
$dbi->execute($create_table2);
4098
$dbi->execute($create_table1_type);
4099

            
4100
$infos = [];
4101
$dbi->user_table_info($user_table_info);
4102
$dbi->each_table(sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4103
  my ($self, $table, $table_info) = @_;
4104
  
4105
  if ($table =~ /^table\d/i) {
4106
     my $info = [$table, $table_info->{TABLE_NAME}];
4107
     push @$infos, $info;
4108
  }
cleanup test
Yuki Kimoto authored on 2011-08-16
4109
});
4110
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
4111
is_deeply($infos, 
cleanup
Yuki Kimoto authored on 2012-01-20
4112
  [
4113
    [$table1, $table1],
4114
    [$table2, $table2],
4115
    [$table3, $table3],
4116
  ]
cleanup test
Yuki Kimoto authored on 2011-08-16
4117
);
4118

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4119
test 'type_rule into';
4120
eval { $dbi->execute("drop table $table1") };
4121
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4122
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4123

            
4124

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4125
$dbi = DBIx::Custom->connect;
4126
eval { $dbi->execute("drop table $table1") };
4127
$dbi->execute($create_table1_type);
4128

            
cleanup
Yuki Kimoto authored on 2011-08-16
4129
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4130
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4131
  into1 => {
4132
    $date_typename => sub { '2010-' . $_[0] }
4133
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4134
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4135
$dbi->insert({$key1 => '01-01'}, table => $table1);
4136
$result = $dbi->select(table => $table1);
4137
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4138

            
4139
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4140
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4141
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4142
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4143
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4144
  into1 => [
4145
     [$date_typename, $datetime_typename] => sub {
4146
        my $value = shift;
4147
        $value =~ s/02/03/g;
4148
        return $value;
4149
     }
4150
  ]
cleanup test
Yuki Kimoto authored on 2011-08-15
4151
);
4152
$dbi->insert({$key1 => '2010-01-02', $key2 => '2010-01-01 01:01:02'}, table => $table1);
4153
$result = $dbi->select(table => $table1);
4154
$row = $result->one;
4155
like($row->{$key1}, qr/^2010-01-03/);
4156
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4157

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4158
$dbi = DBIx::Custom->connect;
4159
eval { $dbi->execute("drop table $table1") };
4160
$dbi->execute($create_table1_type);
4161
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4162
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4163
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4164
  into1 => [
4165
    [$date_typename, $datetime_typename] => sub {
4166
      my $value = shift;
4167
      $value =~ s/02/03/g;
4168
      return $value;
4169
    }
4170
  ]
cleanup test
Yuki Kimoto authored on 2011-08-10
4171
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4172
$result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
4173
  "select * from $table1 where $key1 = :$key1 and $key2 = :$table1.$key2",
4174
  {$key1 => '2010-01-03', "$table1.$key2" => '2010-01-01 01:01:02'}
cleanup test
Yuki Kimoto authored on 2011-08-10
4175
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4176
$row = $result->one;
4177
like($row->{$key1}, qr/^2010-01-03/);
4178
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4179

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

            
4203
$dbi = DBIx::Custom->connect;
4204
eval { $dbi->execute("drop table $table1") };
4205
$dbi->execute($create_table1_type);
4206
$dbi->register_filter(convert => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
4207
  my $value = shift || '';
4208
  $value =~ s/02/03/;
4209
  return $value;
cleanup test
Yuki Kimoto authored on 2011-08-15
4210
});
cleanup
Yuki Kimoto authored on 2011-08-16
4211
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4212
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4213
  from1 => {
4214
    $date_datatype => 'convert',
4215
  },
4216
  into1 => {
4217
      $date_typename => 'convert',
4218
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4219
);
4220
$dbi->insert({$key1 => '2010-02-02'}, table => $table1);
4221
$result = $dbi->select(table => $table1);
4222
like($result->fetch->[0], qr/^2010-03-03/);
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4223
$result = $dbi->select(column => [$key1, $key1], table => $table1);
4224
$row = $result->fetch;
4225
like($row->[0], qr/^2010-03-03/);
4226
like($row->[1], qr/^2010-03-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4227

            
4228
test 'type_rule and filter order';
4229
$dbi = DBIx::Custom->connect;
4230
eval { $dbi->execute("drop table $table1") };
4231
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4232
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4233
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4234
  into1 => {
4235
    $date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4236
  },
4237
  into2 => {
4238
    $date_typename => sub { my $v = shift || ''; $v =~ s/5/6/; return $v }
4239
  },
4240
  from1 => {
4241
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4242
  },
4243
  from2 => {
4244
    $date_datatype => sub { my $v = shift || ''; $v =~ s/7/8/; return $v }
4245
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4246
);
4247
$dbi->insert({$key1 => '2010-01-03'}, 
cleanup
Yuki Kimoto authored on 2012-01-20
4248
table => $table1, filter => {$key1 => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }});
cleanup test
Yuki Kimoto authored on 2011-08-15
4249
$result = $dbi->select(table => $table1);
4250
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4251
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4252

            
4253

            
4254
$dbi = DBIx::Custom->connect;
4255
eval { $dbi->execute("drop table $table1") };
4256
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4257
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4258
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4259
  from1 => {
4260
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4261
  },
4262
  from2 => {
4263
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4264
  },
cleanup test
Yuki Kimoto authored on 2011-08-15
4265
);
4266
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4267
$result = $dbi->select(table => $table1);
cleanup
Yuki Kimoto authored on 2011-08-16
4268
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4269
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4270
  from1 => {
4271
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4272
  },
4273
  from2 => {
4274
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/8/; return $v }
4275
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4276
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4277
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/8/9/; return $v });
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4278
like($result->fetch_one->[0], qr/^2010-01-09/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4279

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4280
test 'type_rule_off';
cleanup test
Yuki Kimoto authored on 2011-08-10
4281
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-15
4282
eval { $dbi->execute("drop table $table1") };
4283
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4284
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4285
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4286
  from1 => {
4287
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4288
  },
4289
  into1 => {
4290
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4291
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4292
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4293
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4294
$result = $dbi->select(table => $table1, type_rule_off => 1);
4295
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4296

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4359
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4360
  into1 => {
4361
    $date_typename => 'pp'
4362
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4363
)};
4364
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4365

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4366
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4367
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4368
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4369
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4370
  $dbi->type_rule(
4371
    from1 => {
4372
      Date => sub { $_[0] * 2 },
4373
    }
4374
  );
cleanup test
Yuki Kimoto authored on 2011-08-10
4375
};
cleanup test
Yuki Kimoto authored on 2011-08-15
4376
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4377

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4378
eval {
cleanup
Yuki Kimoto authored on 2012-01-20
4379
  $dbi->type_rule(
4380
    into1 => {
4381
      Date => sub { $_[0] * 2 },
4382
    }
4383
  );
cleanup test
Yuki Kimoto authored on 2011-08-15
4384
};
4385
like($@, qr/lower/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4386

            
4387
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4388
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4389
$dbi->execute($create_table1_type);
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
  from1 => {
4393
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4394
  },
4395
  into1 => {
4396
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4397
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4398
);
4399
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4400
$result = $dbi->select(table => $table1);
4401
$result->type_rule_off;
4402
like($result->one->{$key1}, qr/^2010-01-04/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4403

            
4404
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4405
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4406
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4407
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4408
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4409
  from1 => {
4410
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4411
    $datetime_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4412
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4413
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4414
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
4415
$result = $dbi->select(table => $table1);
4416
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4417
  from1 => {
4418
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4419
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4420
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4421
$row = $result->one;
4422
like($row->{$key1}, qr/^2010-01-05/);
4423
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4424

            
4425
$result = $dbi->select(table => $table1);
4426
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4427
  from1 => {
4428
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4429
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4430
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4431
$row = $result->one;
4432
like($row->{$key1}, qr/2010-01-05/);
4433
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4434

            
4435
$result = $dbi->select(table => $table1);
4436
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4437
  from1 => {
4438
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4439
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4440
);
4441
$row = $result->one;
4442
like($row->{$key1}, qr/2010-01-05/);
4443
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4444

            
4445
$result = $dbi->select(table => $table1);
4446
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4447
  from1 => [$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }]
cleanup test
Yuki Kimoto authored on 2011-08-15
4448
);
4449
$row = $result->one;
4450
like($row->{$key1}, qr/2010-01-05/);
4451
like($row->{$key2}, qr/2010-01-01 01:01:03/);
4452

            
4453
$dbi->register_filter(five => sub { my $v = shift || ''; $v =~ s/3/5/; return $v });
4454
$result = $dbi->select(table => $table1);
4455
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4456
  from1 => [$date_datatype => 'five']
cleanup test
Yuki Kimoto authored on 2011-08-15
4457
);
4458
$row = $result->one;
4459
like($row->{$key1}, qr/^2010-01-05/);
4460
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
4461

            
4462
$result = $dbi->select(table => $table1);
4463
$result->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4464
  from1 => [$date_datatype => undef]
cleanup test
Yuki Kimoto authored on 2011-08-15
4465
);
4466
$row = $result->one;
4467
like($row->{$key1}, qr/^2010-01-03/);
4468
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4469

            
4470
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4471
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4472
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4473
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4474
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4475
  from1 => {
4476
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
4477
  },
cleanup test
Yuki Kimoto authored on 2011-08-10
4478
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4479
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4480
$result = $dbi->select(table => $table1);
4481
$result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
4482
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4483

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4498
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4499
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4500
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4501
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4502
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4503
  into1 => {
4504
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4505
  },
4506
  into2 => {
4507
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4508
  },
4509
  from1 => {
4510
    $date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
4511
  },
4512
  from2 => {
4513
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|6)/7/; return $v }
4514
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4515
);
4516
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule_off => 1);
4517
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4518
like($result->type_rule_off->fetch_one->[0], qr/^2010-01-03/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4519
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4520
like($result->type_rule_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4521

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4522
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4523
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4524
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4525
$dbi->user_column_info($user_column_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
4526
$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4527
  into1 => {
4528
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4529
  },
4530
  into2 => {
4531
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
4532
  },
4533
  from1 => {
4534
    $date_datatype => sub { my $v = shift || ''; $v =~ s/(3|5)/6/; return $v }
4535
  },
4536
  from2 => {
4537
    $date_datatype => sub { my $v = shift || ''; $v =~ s/6/7/; return $v }
4538
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4539
);
4540
$dbi->insert({$key1 => '2010-01-03'}, table => $table1, type_rule1_off => 1);
4541
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4542
like($result->type_rule1_off->fetch_one->[0], qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-15
4543
$result = $dbi->select(table => $table1);
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4544
like($result->type_rule1_on->fetch_one->[0], qr/^2010-01-07/);
test cleanup
Yuki Kimoto authored on 2011-08-10
4545

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4570
test 'join';
4571
$dbi = DBIx::Custom->connect;
4572
eval { $dbi->execute("drop table $table1") };
4573
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4574
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4575
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4576
eval { $dbi->execute("drop table $table2") };
4577
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4578
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4579
eval { $dbi->execute("drop table $table3") };
4580
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4581
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4582
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4583
  table => $table1,
4584
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4585
  where   => {"$table1.$key2" => 2},
4586
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4587
)->all;
4588
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}]);
added test
Yuki Kimoto authored on 2011-10-27
4589

            
4590
$dbi = DBIx::Custom->connect;
4591
eval { $dbi->execute("drop table $table1") };
4592
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4593
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4594
$dbi->insert({$key1 => 3, $key2 => 4}, table => $table1);
added test
Yuki Kimoto authored on 2011-10-27
4595
eval { $dbi->execute("drop table $table2") };
4596
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4597
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added test
Yuki Kimoto authored on 2011-10-27
4598
eval { $dbi->execute("drop table $table3") };
4599
$dbi->execute("create table $table3 ($key3 int, $key4 int)");
cleanup
Yuki Kimoto authored on 2011-11-01
4600
$dbi->insert({$key3 => 5, $key4 => 4}, table => $table3);
added test
Yuki Kimoto authored on 2011-10-27
4601
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4602
  table => $table1,
4603
  column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
4604
  where   => {"$table1.$key2" => 2},
4605
  join  => {
4606
    clause => "left outer join $table2 on $table1.$key1 = $table2.$key1",
4607
    table => [$table1, $table2]
4608
  }
added test
Yuki Kimoto authored on 2011-10-27
4609
)->all;
4610
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
4611

            
4612
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4613
  table => $table1,
4614
  where   => {$key1 => 1},
4615
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4616
)->all;
4617
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4618

            
4619
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4620
  table => $table1,
4621
  where   => {$key1 => 1},
4622
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4623
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4624
)->all;
4625
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
4626

            
4627
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4628
  column => "$table3.$key4 as ${table3}__$key4",
4629
  table => $table1,
4630
  where   => {"$table1.$key1" => 1},
4631
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4632
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4633
)->all;
4634
is_deeply($rows, [{"${table3}__$key4" => 4}]);
4635

            
4636
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4637
  column => "$table1.$key1 as ${table1}__$key1",
4638
  table => $table1,
4639
  where   => {"$table3.$key4" => 4},
4640
  join  => ["left outer join $table2 on $table1.$key1 = $table2.$key1",
4641
            "left outer join $table3 on $table2.$key3 = $table3.$key3"]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4642
)->all;
4643
is_deeply($rows, [{"${table1}__$key1" => 1}]);
4644

            
4645
$dbi = DBIx::Custom->connect;
4646
eval { $dbi->execute("drop table $table1") };
4647
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4648
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4649
eval { $dbi->execute("drop table $table2") };
4650
$dbi->execute($create_table2);
cleanup
Yuki Kimoto authored on 2011-11-01
4651
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4652
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4653
  table => $table1,
4654
  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",
4655
  where   => {"$table1.$key2" => 2},
4656
  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
4657
)->all;
4658
is_deeply($rows, [{"${table1}_$key1" => 1, "${table2}_$key1" => 1, $key2 => 2, $key3 => 5}],
cleanup
Yuki Kimoto authored on 2012-01-20
4659
  'quote');
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4660

            
4661

            
4662
$dbi = DBIx::Custom->connect;
4663
eval { $dbi->execute("drop table $table1") };
4664
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4665
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4666
$sql = <<"EOS";
4667
left outer join (
cleanup
Yuki Kimoto authored on 2012-01-20
4668
select * from $table1 t1
4669
where t1.$key2 = (
4670
  select max(t2.$key2) from $table1 t2
4671
  where t1.$key1 = t2.$key1
4672
)
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4673
) $table3 on $table1.$key1 = $table3.$key1
4674
EOS
4675
$join = [$sql];
4676
$rows = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4677
  table => $table1,
4678
  column => "$table3.$key1 as ${table3}__$key1",
4679
  join  => $join
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4680
)->all;
4681
is_deeply($rows, [{"${table3}__$key1" => 1}]);
4682

            
4683
$dbi = DBIx::Custom->connect;
4684
eval { $dbi->execute("drop table $table1") };
4685
eval { $dbi->execute("drop table $table2") };
4686
$dbi->execute($create_table1);
4687
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4688
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4689
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4690
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4691
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4692
  table => $table1,
4693
  join => [
4694
    "left outer join $table2 on $table2.$key2 = '4' and $table1.$key1 = $table2.$key1"
4695
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4696
);
4697
is_deeply($result->all, [{$key1 => 1, $key2 => 2}]);
4698
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4699
  table => $table1,
4700
  column => [{$table2 => [$key3]}],
4701
  join => [
4702
    "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1"
4703
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4704
);
4705
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4706
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4707
  table => $table1,
4708
  column => [{$table2 => [$key3]}],
4709
  join => [
4710
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 = '4'"
4711
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4712
);
4713
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4714

            
4715
$dbi = DBIx::Custom->connect;
4716
eval { $dbi->execute("drop table $table1") };
4717
eval { $dbi->execute("drop table $table2") };
4718
$dbi->execute($create_table1);
4719
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4720
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4721
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4722
$dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4723
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4724
  table => $table1,
4725
  column => [{$table2 => [$key3]}],
4726
  join => [
4727
    {
4728
      clause => "left outer join $table2 on $table2.$key3 = '4' and $table1.$key1 = $table2.$key1",
4729
      table => [$table1, $table2]
4730
    }
4731
  ]
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4732
);
4733
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4734

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4735
$dbi = DBIx::Custom->connect;
4736
eval { $dbi->execute("drop table $table1") };
4737
eval { $dbi->execute("drop table $table2") };
4738
$dbi->execute($create_table1);
4739
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4740
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4741
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4742
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4743
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4744
  table => $table1,
4745
  column => [{$table2 => [$key3]}],
4746
  join => [
4747
    "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'"
4748
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4749
);
4750
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4751

            
4752
$dbi = DBIx::Custom->connect;
4753
eval { $dbi->execute("drop table $table1") };
4754
eval { $dbi->execute("drop table $table2") };
4755
$dbi->execute($create_table1);
4756
$dbi->execute($create_table2);
test cleanup
Yuki Kimoto authored on 2011-11-01
4757
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4758
$dbi->insert({$key1 => 1, $key3 => 4}, table => $table2);
4759
$dbi->insert({$key1 => 1, $key3 => 1}, table => $table2);
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4760
$result = $dbi->select(
cleanup
Yuki Kimoto authored on 2012-01-20
4761
  table => $table1,
4762
  column => [{$table2 => [$key3]}],
4763
  join => [
4764
    "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1"
4765
  ]
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
4766
);
4767
is_deeply($result->all, [{"$table2.$key3" => 4}]);
4768

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4769
test 'columns';
4770
$dbi = MyDBI1->connect;
4771
$model = $dbi->model($table1);
4772

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4773
test 'count';
4774
$dbi = DBIx::Custom->connect;
4775
eval { $dbi->execute("drop table $table1") };
4776
$dbi->execute($create_table1);
test cleanup
Yuki Kimoto authored on 2011-11-01
4777
$dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
cleanup
Yuki Kimoto authored on 2011-11-01
4778
$dbi->insert({$key1 => 1, $key2 => 3}, table => $table1);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
4779
is($dbi->count(table => $table1), 2);
4780
is($dbi->count(table => $table1, where => {$key2 => 2}), 1);
4781
$model = $dbi->create_model(table => $table1);
4782
is($model->count, 2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4783

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4784
eval { $dbi->execute("drop table $table1") };
4785
eval { $dbi->execute("drop table $table2") };
4786
$dbi->execute($create_table1);
4787
$dbi->execute($create_table2);
4788
$model = $dbi->create_model(table => $table1, primary_key => $key1);
4789
$model->insert({$key1 => 1, $key2 => 2});
4790
$model = $dbi->create_model(table => $table2, primary_key => $key1,
cleanup
Yuki Kimoto authored on 2012-01-20
4791
  join => ["left outer join $table1 on $table2.$key1 = $table1.$key1"]);
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4792
$model->insert({$key1 => 1, $key3 => 3});
4793
is($model->count(id => 1), 1);
4794
is($model->count(where => {"$table2.$key3" => 3}), 1);
4795

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