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

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

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

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

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

            
3619

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3740

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3944

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
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

            
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 => sub { '2010-' . $_[0] }
4171
  }
cleanup test
Yuki Kimoto authored on 2011-08-10
4172
);
cleanup test
Yuki Kimoto authored on 2011-08-15
4173
$dbi->insert({$key1 => '01-01'}, table => $table1);
4174
$result = $dbi->select(table => $table1);
4175
like($result->one->{$key1}, qr/^2010-01-01/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4176

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

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

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

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

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

            
4291

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

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

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

            
4351
$dbi = DBIx::Custom->connect;
finishied sqlite test cleanu...
Yuki Kimoto authored on 2011-08-15
4352
eval { $dbi->execute("drop table $table1") };
cleanup test
Yuki Kimoto authored on 2011-08-15
4353
$dbi->execute($create_table1_type);
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
  from1 => {
4357
    $date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
4358
  },
4359
  into1 => {
4360
    $date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
4361
  }
cleanup test
Yuki Kimoto authored on 2011-08-15
4362
);
4363
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
4364
$result = $dbi->select(table => $table1);
4365
like($result->one->{$key1}, qr/^2010-01-05/);
cleanup test
Yuki Kimoto authored on 2011-08-10
4366

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
4699

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

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

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

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

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

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

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

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

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