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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3682
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3683
  q => 'string'
test cleanup
Yuki Kimoto authored on 2011-08-10
3684
});
3685

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
3689
$dbi->register_tag({
cleanup
Yuki Kimoto authored on 2012-01-20
3690
  r => sub {} 
test cleanup
Yuki Kimoto authored on 2011-08-10
3691
});
3692

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

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

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

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

            
3707

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

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

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

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

            
3723
test 'variouse source';
3724
$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d";
3725
$query = $builder->build_query($source);
3726
is($query->sql, 'a b = ? c { } { = ? } = ? d', "basic : 1");
3727

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

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

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

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

            
3744
$source = "a {= {}";
3745
eval{$builder->build_query($source)};
3746
like($@, qr/unexpected "{"/, "error : 2");
3747

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

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

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

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

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

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

            
3833
test 'create_model';
3834
$dbi = DBIx::Custom->connect;
cleanup test
Yuki Kimoto authored on 2011-08-16
3835
$dbi->user_table_info($user_table_info);
cleanup test
Yuki Kimoto authored on 2011-08-15
3836
eval { $dbi->execute("drop table $table1") };
3837
eval { $dbi->execute("drop table $table2") };
3838
$dbi->execute($create_table1);
3839
$dbi->execute($create_table2);
3840

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

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

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

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

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

            
3911

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

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

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

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

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

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

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

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

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

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

            
4022
test 'primary_key';
4023
$dbi = MyDBI1->connect;
4024
$model = $dbi->model($table1);
4025
$model->primary_key([$key1, $key2]);
4026
is_deeply($model->primary_key, [$key1, $key2]);
4027

            
4028
test 'columns';
4029
$dbi = MyDBI1->connect;
4030
$model = $dbi->model($table1);
4031
$model->columns([$key1, $key2]);
4032
is_deeply($model->columns, [$key1, $key2]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4033

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
4040
$dbi->execute($create_table1);
cleanup test
Yuki Kimoto authored on 2011-08-15
4041
$dbi->execute($create_table2);
cleanup test
Yuki Kimoto authored on 2011-08-10
4042
$dbi->setup_model;
cleanup test
Yuki Kimoto authored on 2011-08-15
4043
is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4044
is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
cleanup test
Yuki Kimoto authored on 2011-08-10
4045

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4075
test 'each_table';
4076
$dbi = DBIx::Custom->connect;
4077
eval { $dbi->execute("drop table $table1") };
4078
eval { $dbi->execute("drop table $table2") };
4079
$dbi->execute($create_table2);
4080
$dbi->execute($create_table1_type);
cleanup test
Yuki Kimoto authored on 2011-08-10
4081

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

            
cleanup test
Yuki Kimoto authored on 2011-08-16
4099
$dbi = DBIx::Custom->connect;
4100
eval { $dbi->execute("drop table $table1") };
4101
eval { $dbi->execute("drop table $table2") };
4102
$dbi->execute($create_table2);
4103
$dbi->execute($create_table1_type);
4104

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4124
test 'type_rule into';
4125
eval { $dbi->execute("drop table $table1") };
4126
$dbi->execute($create_table1_type);
cleanup
Yuki Kimoto authored on 2011-08-16
4127
$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table);
4128

            
4129

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4130
$dbi = DBIx::Custom->connect;
4131
eval { $dbi->execute("drop table $table1") };
4132
$dbi->execute($create_table1_type);
4133

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

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

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

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

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

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

            
4258

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-15
4364
eval{$dbi->type_rule(
cleanup
Yuki Kimoto authored on 2012-01-20
4365
  into1 => {
4366
    $date_typename => 'pp'
4367
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4368
)};
4369
like($@, qr/not registered/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4370

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4666

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
4774
test 'columns';
4775
$dbi = MyDBI1->connect;
4776
$model = $dbi->model($table1);
4777

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

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

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