DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
2519 lines | 83.342kb
removed register_format()
yuki-kimoto authored on 2010-05-26
1
use Test::More;
2
use strict;
3
use warnings;
4

            
5
use utf8;
6
use Encode qw/encode_utf8 decode_utf8/;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
7
use Data::Dumper;
removed register_format()
yuki-kimoto authored on 2010-05-26
8

            
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
9
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
10

            
removed register_format()
yuki-kimoto authored on 2010-05-26
11
BEGIN {
12
    eval { require DBD::SQLite; 1 }
13
        or plan skip_all => 'DBD::SQLite required';
14
    eval { DBD::SQLite->VERSION >= 1.25 }
15
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
16

            
17
    plan 'no_plan';
18
    use_ok('DBIx::Custom');
19
}
20

            
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
21
use FindBin;
22
use lib "$FindBin::Bin/dbix-custom-core-sqlite";
23

            
removed register_format()
yuki-kimoto authored on 2010-05-26
24
# Function for test name
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
25
sub test { print "# $_[0]\n" }
removed register_format()
yuki-kimoto authored on 2010-05-26
26

            
27
# Constant varialbes for test
28
my $CREATE_TABLE = {
29
    0 => 'create table table1 (key1 char(255), key2 char(255));',
30
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
31
    2 => 'create table table2 (key1 char(255), key3 char(255));',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
32
    3 => 'create table table1 (key1 Date, key2 datetime);',
33
    4 => 'create table table3 (key3 int, key4 int);'
removed register_format()
yuki-kimoto authored on 2010-05-26
34
};
35

            
add tests
yuki-kimoto authored on 2010-08-10
36
my $SELECT_SOURCES = {
removed register_format()
yuki-kimoto authored on 2010-05-26
37
    0 => 'select * from table1;'
38
};
39

            
40
my $DROP_TABLE = {
41
    0 => 'drop table table1'
42
};
43

            
44
my $NEW_ARGS = {
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
45
    0 => {dsn => 'dbi:SQLite:dbname=:memory:'}
removed register_format()
yuki-kimoto authored on 2010-05-26
46
};
47

            
48
# Variables
49
my $dbi;
50
my $sth;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
51
my $source;
52
my @sources;
add tests
yuki-kimoto authored on 2010-08-10
53
my $select_SOURCE;
54
my $insert_SOURCE;
55
my $update_SOURCE;
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
56
my $param;
removed register_format()
yuki-kimoto authored on 2010-05-26
57
my $params;
58
my $sql;
59
my $result;
60
my $row;
61
my @rows;
62
my $rows;
63
my $query;
64
my @queries;
65
my $select_query;
66
my $insert_query;
67
my $update_query;
68
my $ret_val;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
69
my $infos;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
70
my $model;
create_model() return model
Yuki Kimoto authored on 2011-03-29
71
my $model2;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
72
my $where;
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
73
my $update_param;
74
my $insert_param;
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
75
my $join;
removed register_format()
yuki-kimoto authored on 2010-05-26
76

            
77
# Prepare table
78
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
79
$dbi->execute($CREATE_TABLE->{0});
80
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
81
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
82

            
83
test 'DBIx::Custom::Result test';
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
84
$source = "select key1, key2 from table1";
85
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
86
$result = $dbi->execute($query);
87

            
88
@rows = ();
89
while (my $row = $result->fetch) {
90
    push @rows, [@$row];
91
}
cleanup
Yuki Kimoto authored on 2011-01-23
92
is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
removed register_format()
yuki-kimoto authored on 2010-05-26
93

            
94
$result = $dbi->execute($query);
95
@rows = ();
96
while (my $row = $result->fetch_hash) {
97
    push @rows, {%$row};
98
}
cleanup
Yuki Kimoto authored on 2011-01-23
99
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash");
removed register_format()
yuki-kimoto authored on 2010-05-26
100

            
101
$result = $dbi->execute($query);
102
$rows = $result->fetch_all;
cleanup
Yuki Kimoto authored on 2011-01-23
103
is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
104

            
105
$result = $dbi->execute($query);
removed reconnect method
yuki-kimoto authored on 2010-05-28
106
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
107
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
108

            
109
test 'Insert query return value';
110
$dbi->execute($DROP_TABLE->{0});
111
$dbi->execute($CREATE_TABLE->{0});
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
112
$source = "insert into table1 {insert_param key1 key2}";
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
113
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
114
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
115
ok($ret_val);
removed register_format()
yuki-kimoto authored on 2010-05-26
116

            
117

            
118
test 'Direct query';
119
$dbi->execute($DROP_TABLE->{0});
120
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
121
$insert_SOURCE = "insert into table1 {insert_param key1 key2}";
122
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2});
123
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
124
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
125
is_deeply($rows, [{key1 => 1, key2 => 2}]);
removed register_format()
yuki-kimoto authored on 2010-05-26
126

            
127
test 'Filter basic';
128
$dbi->execute($DROP_TABLE->{0});
129
$dbi->execute($CREATE_TABLE->{0});
130
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
131
                    three_times => sub { $_[0] * 3});
132

            
add tests
yuki-kimoto authored on 2010-08-10
133
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
134
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
135
$insert_query->filter({key1 => 'twice'});
136
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
add tests
yuki-kimoto authored on 2010-08-10
137
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
138
$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
139
is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
140
$dbi->execute($DROP_TABLE->{0});
141

            
142
test 'Filter in';
143
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
144
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
145
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
146
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
147
$select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
148
$select_query = $dbi->create_query($select_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
149
$select_query->filter({'table1.key1' => 'twice'});
150
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
151
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
152
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
153

            
154
test 'DBIx::Custom::SQLTemplate basic tag';
155
$dbi->execute($DROP_TABLE->{0});
156
$dbi->execute($CREATE_TABLE->{1});
157
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
158
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
159

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
160
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
161
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
162
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
163
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
164
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
removed register_format()
yuki-kimoto authored on 2010-05-26
165

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
166
$source = "select * from table1 where {<= key1} and {like key2};";
167
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
168
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
169
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
170
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
removed register_format()
yuki-kimoto authored on 2010-05-26
171

            
172
test 'DIB::Custom::SQLTemplate in tag';
173
$dbi->execute($DROP_TABLE->{0});
174
$dbi->execute($CREATE_TABLE->{1});
175
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
176
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
177

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
178
$source = "select * from table1 where {in key1 2};";
179
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
180
$result = $dbi->execute($query, param => {key1 => [9, 1]});
181
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
182
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
183

            
184
test 'DBIx::Custom::SQLTemplate insert tag';
185
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
186
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
187
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
188

            
add tests
yuki-kimoto authored on 2010-08-10
189
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
190
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
191
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
192

            
193
test 'DBIx::Custom::SQLTemplate update tag';
194
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
195
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
196
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
197
$dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
removed register_format()
yuki-kimoto authored on 2010-05-26
198

            
add tests
yuki-kimoto authored on 2010-08-10
199
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
200
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
201

            
add tests
yuki-kimoto authored on 2010-08-10
202
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
203
$rows = $result->fetch_hash_all;
204
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
cleanup
Yuki Kimoto authored on 2011-01-23
205
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
206

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
207

            
208
test 'parameter';
209
$dbi->execute($DROP_TABLE->{0});
210
$dbi->execute($CREATE_TABLE->{1});
211
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
212
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
213

            
214
$source = "select * from table1 where key1 = :key1 and key2 = :key2";
215
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
216
$rows = $result->fetch_hash_all;
217
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
218

            
219
$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2";
220
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
221
$rows = $result->fetch_hash_all;
222
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
223

            
224
$source = "select * from table1 where key1 = :key1 or key1 = :key1";
225
$result = $dbi->execute($source, param => {key1 => [1, 2]});
226
$rows = $result->fetch_hash_all;
227
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
228

            
229
$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2";
230
$result = $dbi->execute(
231
    $source,
232
    param => {'table1.key1' => 1, 'table1.key2' => 1},
233
    filter => {'table1.key2' => sub { $_[0] * 2 }}
234
);
235
$rows = $result->fetch_hash_all;
236
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
237

            
removed register_format()
yuki-kimoto authored on 2010-05-26
238
test 'Error case';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
239
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')};
cleanup
Yuki Kimoto authored on 2011-01-23
240
ok($@, "connect error");
removed register_format()
yuki-kimoto authored on 2010-05-26
241

            
242
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
243
eval{$dbi->create_query("{p }")};
cleanup
Yuki Kimoto authored on 2011-01-23
244
ok($@, "create_query invalid SQL template");
removed register_format()
yuki-kimoto authored on 2010-05-26
245

            
246
test 'insert';
247
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
248
$dbi->execute($CREATE_TABLE->{0});
249
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
250
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
251
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
252
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
253
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
254

            
255
$dbi->execute('delete from table1');
256
$dbi->register_filter(
257
    twice       => sub { $_[0] * 2 },
258
    three_times => sub { $_[0] * 3 }
259
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
260
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
261
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
262
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
263
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
264
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
265
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
266

            
267
$dbi->execute($DROP_TABLE->{0});
268
$dbi->execute($CREATE_TABLE->{0});
269
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
270
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
271
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
272

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
273
eval{$dbi->insert(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
274
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
275

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
276
eval{$dbi->insert(table => 'table', param => {';' => 1})};
277
like($@, qr/safety/);
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
278

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
279
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
280
$dbi->reserved_word_quote('"');
281
$dbi->execute('create table "table" ("select")');
282
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
283
$dbi->insert(table => 'table', param => {select => 1});
284
$result = $dbi->execute('select * from "table"');
285
$rows   = $result->fetch_hash_all;
286
is_deeply($rows, [{select => 2}], "reserved word");
287

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
288
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
289
$dbi->execute($CREATE_TABLE->{0});
290
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
291
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
292
$result = $dbi->execute($SELECT_SOURCES->{0});
293
$rows   = $result->fetch_hash_all;
294
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
295

            
removed register_format()
yuki-kimoto authored on 2010-05-26
296
test 'update';
297
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
298
$dbi->execute($CREATE_TABLE->{1});
299
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
300
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
301
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
302
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
303
$rows   = $result->fetch_hash_all;
304
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
305
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
306
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
307
                  
308
$dbi->execute("delete from table1");
309
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
310
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
311
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
312
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
313
$rows   = $result->fetch_hash_all;
314
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
315
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
316
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
317

            
add tests
yuki-kimoto authored on 2010-08-10
318
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
319
$result = $dbi->execute($SELECT_SOURCES->{0});
320
$rows   = $result->fetch_hash_all;
321
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
322
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
323
                  "update key same as search key : param is array ref");
add tests
yuki-kimoto authored on 2010-08-10
324

            
removed register_format()
yuki-kimoto authored on 2010-05-26
325
$dbi->execute("delete from table1");
326
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
327
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
328
$dbi->register_filter(twice => sub { $_[0] * 2 });
329
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
330
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
331
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
332
$rows   = $result->fetch_hash_all;
333
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
334
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
335
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
336

            
337
$result = $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1}, append => '   ');
338

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
339
eval{$dbi->update(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
340
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
341

            
342
eval{$dbi->update(table => 'table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
343
like($@, qr/where/, "not contain where");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
344

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
345
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
346
$dbi->execute($CREATE_TABLE->{0});
347
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
348
$where = $dbi->where;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
349
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
350
$where->param({key1 => 1, key2 => 2});
351
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
352
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
353
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
354

            
355
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
356
$dbi->execute($CREATE_TABLE->{0});
357
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
358
$dbi->update(
359
    table => 'table1',
360
    param => {key1 => 3},
361
    where => [
362
        ['and', '{= key1}', '{= key2}'],
363
        {key1 => 1, key2 => 2}
364
    ]
365
);
366
$result = $dbi->select(table => 'table1');
367
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
368

            
369
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
370
$dbi->execute($CREATE_TABLE->{0});
371
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
372
$where = $dbi->where;
373
$where->clause(['and', '{= key2}']);
374
$where->param({key2 => 2});
375
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
376
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
377
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
378

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
379
eval{$dbi->update(table => 'table1', param => {';' => 1})};
380
like($@, qr/safety/);
381

            
382
eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})};
383
like($@, qr/safety/);
384

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
385
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
386
$dbi->reserved_word_quote('"');
387
$dbi->execute('create table "table" ("select", "update")');
388
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
389
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
390
$dbi->insert(table => 'table', param => {select => 1});
391
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
392
$result = $dbi->execute('select * from "table"');
393
$rows   = $result->fetch_hash_all;
394
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
395

            
396
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
397
like($@, qr/safety/);
398

            
399
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
400
$dbi->reserved_word_quote('"');
401
$dbi->execute('create table "table" ("select", "update")');
402
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
403
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
404
$dbi->insert(table => 'table', param => {select => 1});
405
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
406
$result = $dbi->execute('select * from "table"');
407
$rows   = $result->fetch_hash_all;
408
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
409

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
410
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
411
$dbi->execute($CREATE_TABLE->{1});
412
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
413
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
414
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
415
$result = $dbi->execute($SELECT_SOURCES->{0});
416
$rows   = $result->fetch_hash_all;
417
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
418
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
419
                  "basic");
420

            
removed register_format()
yuki-kimoto authored on 2010-05-26
421
test 'update_all';
422
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
423
$dbi->execute($CREATE_TABLE->{1});
424
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
425
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
426
$dbi->register_filter(twice => sub { $_[0] * 2 });
427
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
428
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
429
$rows   = $result->fetch_hash_all;
430
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
431
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
432
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
433

            
434

            
435
test 'delete';
436
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
437
$dbi->execute($CREATE_TABLE->{0});
438
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
439
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
440
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
441
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
442
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
443
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
444

            
445
$dbi->execute("delete from table1;");
446
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
447
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
448
$dbi->register_filter(twice => sub { $_[0] * 2 });
449
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
450
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
451
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
452
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
453

            
454
$dbi->delete(table => 'table1', where => {key1 => 1}, append => '   ');
455

            
456
$dbi->delete_all(table => 'table1');
457
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
458
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
459
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
460
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
461
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
462

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
463
eval{$dbi->delete(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
464
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
465

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
466
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
467
$dbi->execute($CREATE_TABLE->{0});
468
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
469
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
470
$where = $dbi->where;
471
$where->clause(['and', '{= key1}', '{= key2}']);
472
$where->param({ke1 => 1, key2 => 2});
473
$dbi->delete(table => 'table1', where => $where);
474
$result = $dbi->select(table => 'table1');
475
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
476

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
477
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
478
$dbi->execute($CREATE_TABLE->{0});
479
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
480
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
481
$dbi->delete(
482
    table => 'table1',
483
    where => [
484
        ['and', '{= key1}', '{= key2}'],
485
        {ke1 => 1, key2 => 2}
486
    ]
487
);
488
$result = $dbi->select(table => 'table1');
489
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
490

            
removed register_format()
yuki-kimoto authored on 2010-05-26
491
test 'delete error';
492
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
493
$dbi->execute($CREATE_TABLE->{0});
494
eval{$dbi->delete(table => 'table1')};
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
495
like($@, qr/"where" must be specified/,
cleanup
Yuki Kimoto authored on 2011-01-23
496
         "where key-value pairs not specified");
removed register_format()
yuki-kimoto authored on 2010-05-26
497

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
498
eval{$dbi->delete(table => 'table1', where => {';' => 1})};
499
like($@, qr/safety/);
500

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
501
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
502
$dbi->reserved_word_quote('"');
503
$dbi->execute('create table "table" ("select", "update")');
504
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
505
$dbi->insert(table => 'table', param => {select => 1});
506
$dbi->delete(table => 'table', where => {select => 1});
507
$result = $dbi->execute('select * from "table"');
508
$rows   = $result->fetch_hash_all;
509
is_deeply($rows, [], "reserved word");
510

            
removed register_format()
yuki-kimoto authored on 2010-05-26
511
test 'delete_all';
512
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
513
$dbi->execute($CREATE_TABLE->{0});
514
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
515
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
516
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
517
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
518
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
519
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
520

            
521

            
522
test 'select';
523
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
524
$dbi->execute($CREATE_TABLE->{0});
525
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
526
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
527
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
528
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
529
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
530

            
update document
yuki-kimoto authored on 2010-05-27
531
$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
532
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
533

            
534
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
535
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
536

            
update document
yuki-kimoto authored on 2010-05-27
537
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
538
is_deeply($rows, [{key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
539

            
540
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
541
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
removed register_format()
yuki-kimoto authored on 2010-05-26
542

            
543
$dbi->register_filter(decrement => sub { $_[0] - 1 });
update document
yuki-kimoto authored on 2010-05-27
544
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
removed register_format()
yuki-kimoto authored on 2010-05-26
545
            ->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
546
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
547

            
548
$dbi->execute($CREATE_TABLE->{2});
549
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
550
$rows = $dbi->select(
551
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
552
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
553
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
554
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
555
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
556
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where");
added commit method
yuki-kimoto authored on 2010-05-27
557

            
558
$rows = $dbi->select(
559
    table => [qw/table1 table2/],
560
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
561
    relation  => {'table1.key1' => 'table2.key1'}
562
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
563
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where");
removed register_format()
yuki-kimoto authored on 2010-05-26
564

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
565
eval{$dbi->select(table => 'table1', noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
566
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
567

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
568
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
569
$dbi->reserved_word_quote('"');
570
$dbi->execute('create table "table" ("select", "update")');
571
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
572
$dbi->insert(table => 'table', param => {select => 1, update => 2});
573
$result = $dbi->select(table => 'table', where => {select => 1});
574
$rows   = $result->fetch_hash_all;
575
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
576

            
removed register_format()
yuki-kimoto authored on 2010-05-26
577
test 'fetch filter';
578
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
579
$dbi->register_filter(
580
    twice       => sub { $_[0] * 2 },
581
    three_times => sub { $_[0] * 3 }
582
);
583
$dbi->default_fetch_filter('twice');
584
$dbi->execute($CREATE_TABLE->{0});
585
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
586
$result = $dbi->select(table => 'table1');
587
$result->filter({key1 => 'three_times'});
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
588
$row = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
589
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
590

            
591
test 'filters';
592
$dbi = DBIx::Custom->new;
593

            
update document
yuki-kimoto authored on 2010-05-27
594
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
cleanup
Yuki Kimoto authored on 2011-01-23
595
   'あ', "decode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
596

            
597
is($dbi->filters->{encode_utf8}->('あ'),
cleanup
Yuki Kimoto authored on 2011-01-23
598
   encode_utf8('あ'), "encode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
599

            
added commit method
yuki-kimoto authored on 2010-05-27
600
test 'transaction';
601
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
602
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
603
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
604
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
605
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
606
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
607
$result = $dbi->select(table => 'table1');
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
608
is_deeply(scalar $result->all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
609
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
610

            
611
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
612
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
613
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
614
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
615
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
616

            
617
$result = $dbi->select(table => 'table1');
cleanup
Yuki Kimoto authored on 2011-01-23
618
ok(! $result->fetch_first, "rollback");
add cache attribute
yuki-kimoto authored on 2010-06-14
619

            
620
test 'cache';
621
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
622
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
623
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
624
$source = 'select * from table1 where {= key1} and {= key2};';
625
$dbi->create_query($source);
626
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
627
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
628

            
629
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
630
$dbi->execute($CREATE_TABLE->{0});
631
$dbi->{_cached} = {};
632
$dbi->cache(0);
633
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
634
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
635

            
add tests
yuki-kimoto authored on 2010-08-10
636
test 'execute';
637
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
638
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
639
{
640
    local $Carp::Verbose = 0;
641
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
642
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
643
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
644
}
645
{
646
    local $Carp::Verbose = 1;
647
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
648
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
649
}
add tests
yuki-kimoto authored on 2010-08-10
650

            
651
eval{$dbi->execute('select * from table1', no_exists => 1)};
improved error messages
Yuki Kimoto authored on 2011-04-18
652
like($@, qr/wrong/, "invald SQL");
add tests
yuki-kimoto authored on 2010-08-10
653

            
654
$query = $dbi->create_query('select * from table1 where {= key1}');
655
$dbi->dbh->disconnect;
656
eval{$dbi->execute($query, param => {key1 => {a => 1}})};
cleanup
Yuki Kimoto authored on 2011-01-23
657
ok($@, "execute fail");
add tests
yuki-kimoto authored on 2010-08-10
658

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
659
{
660
    local $Carp::Verbose = 0;
661
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
662
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
663
}
664
{
665
    local $Carp::Verbose = 1;
666
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
667
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
668
}
cleanup
yuki-kimoto authored on 2010-10-17
669

            
670

            
671
test 'transaction';
672
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
673
$dbi->execute($CREATE_TABLE->{0});
674

            
675
$dbi->begin_work;
676

            
677
eval {
678
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
679
    die "Error";
680
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
681
};
682

            
683
$dbi->rollback if $@;
684

            
685
$result = $dbi->select(table => 'table1');
686
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
687
is_deeply($rows, [], "rollback");
cleanup
yuki-kimoto authored on 2010-10-17
688

            
689
$dbi->begin_work;
690

            
691
eval {
692
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
693
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
694
};
695

            
696
$dbi->commit unless $@;
697

            
698
$result = $dbi->select(table => 'table1');
699
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
700
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit");
cleanup
yuki-kimoto authored on 2010-10-17
701

            
702
$dbi->dbh->{AutoCommit} = 0;
703
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
704
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
705
$dbi->dbh->{AutoCommit} = 1;
706

            
added helper method
yuki-kimoto authored on 2010-10-17
707

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
708
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
709
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
710
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
711
    one => sub { 1 }
712
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
713
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
714
    two => sub { 2 }
715
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
716
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
717
    twice => sub {
718
        my $self = shift;
719
        return $_[0] * 2;
720
    }
721
});
722

            
cleanup
Yuki Kimoto authored on 2011-01-23
723
is($dbi->one, 1, "first");
724
is($dbi->two, 2, "second");
725
is($dbi->twice(5), 10 , "second");
added helper method
yuki-kimoto authored on 2010-10-17
726

            
727
eval {$dbi->XXXXXX};
autoload DBI method
Yuki Kimoto authored on 2011-01-26
728
ok($@, "not exists");
added helper method
yuki-kimoto authored on 2010-10-17
729

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
730
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
731
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
732
$dbi->execute($CREATE_TABLE->{0});
733
$dbi->register_filter(twice => sub { $_[0] * 2 });
734
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
735
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
736
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
737
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
738
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
739
$result = $dbi->execute($SELECT_SOURCES->{0});
740
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
741
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
742
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
743
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
744
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
745

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
746
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
747
$dbi->execute($CREATE_TABLE->{0});
748
$dbi->register_filter(twice => sub { $_[0] * 2 });
749
$dbi->register_filter(three_times => sub { $_[0] * 3});
750
$dbi->apply_filter(
751
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
752
              'key2' => {out => 'three_times', in => 'twice'});
753
$dbi->apply_filter(
754
    'table1', 'key1' => {out => undef}
755
); 
756
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
757
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
758
$row   = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
759
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
760

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
761
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
762
$dbi->execute($CREATE_TABLE->{0});
763
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
764
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
765
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
766
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
767
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
768
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
769
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
770
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
771
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
772

            
773
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
774
$dbi->execute($CREATE_TABLE->{0});
775
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
776
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
777
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
778
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
779
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
780
$dbi->delete(table => 'table1', where => {key1 => 1});
781
$result = $dbi->execute($SELECT_SOURCES->{0});
782
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
783
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
784

            
785
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
786
$dbi->execute($CREATE_TABLE->{0});
787
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
788
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
789
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
790
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
791
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
792
$result = $dbi->select(table => 'table1', where => {key1 => 1});
793
$result->filter({'key2' => 'twice'});
794
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
795
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
796

            
797
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
798
$dbi->execute($CREATE_TABLE->{0});
799
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
800
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
801
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
802
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
803
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
804
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
805
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
806
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
807
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
808
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
809

            
add table tag
Yuki Kimoto authored on 2011-02-09
810
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
811
$dbi->execute($CREATE_TABLE->{0});
812
$dbi->register_filter(twice => sub { $_[0] * 2 });
813
$dbi->apply_filter(
814
    'table1', 'key1' => {out => 'twice', in => 'twice'}
815
);
816
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
817
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
818
                        param => {key1 => 1, key2 => 2});
819
$rows   = $result->fetch_hash_all;
820
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
821

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
822
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
823
$dbi->execute($CREATE_TABLE->{0});
824
$dbi->execute($CREATE_TABLE->{2});
825
$dbi->register_filter(twice => sub { $_[0] * 2 });
826
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
827
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
828
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
829
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
830
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
831
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
832
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
833
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
834
$dbi->insert(table => 'table2', param => {key1 => 5, key3 => 6}, filter => {key3 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
835
$result = $dbi->select(
836
     table => ['table1', 'table2'],
837
     column => ['key2', 'key3'],
838
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
839

            
840
$result->filter({'key2' => 'twice'});
841
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
842
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
843

            
844
$result = $dbi->select(
845
     table => ['table1', 'table2'],
846
     column => ['key2', 'key3'],
847
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
848

            
849
$result->filter({'key2' => 'twice'});
850
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
851
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
852

            
pod fix
Yuki Kimoto authored on 2011-01-21
853
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
854
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
855
$dbi->execute($CREATE_TABLE->{2});
856
$dbi->execute($CREATE_TABLE->{3});
857

            
858
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
859
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
860
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
861
    
862
    if ($table =~ /^table/) {
863
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
864
         push @$infos, $info;
865
    }
866
});
867
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
868
is_deeply($infos, 
869
    [
870
        ['table1', 'key1', 'key1'],
871
        ['table1', 'key2', 'key2'],
872
        ['table2', 'key1', 'key1'],
873
        ['table2', 'key3', 'key3']
874
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
875
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
876
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
877

            
add examples
Yuki Kimoto authored on 2011-01-07
878
test 'limit';
879
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
880
$dbi->execute($CREATE_TABLE->{0});
881
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
882
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
883
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
884
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
885
    limit => sub {
886
        my ($count, $offset) = @_;
887
        
888
        my $s = '';
889
        $s .= "limit $count";
890
        $s .= " offset $offset" if defined $offset;
891
        
892
        return [$s, []];
893
    }
894
);
895
$rows = $dbi->select(
896
  table => 'table1',
897
  where => {key1 => 1},
898
  append => "order by key2 {limit 1 0}"
899
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
900
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
901
$rows = $dbi->select(
902
  table => 'table1',
903
  where => {key1 => 1},
904
  append => "order by key2 {limit 2 1}"
905
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
906
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
907
$rows = $dbi->select(
908
  table => 'table1',
909
  where => {key1 => 1},
910
  append => "order by key2 {limit 1}"
911
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
912
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
913

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
914
test 'connect super';
915
{
916
    package MyDBI;
917
    
918
    use base 'DBIx::Custom';
919
    sub connect {
920
        my $self = shift->SUPER::connect(@_);
921
        
922
        return $self;
923
    }
924
    
925
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
926
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
927
        
928
        return $self;
929
    }
930
}
931

            
932
$dbi = MyDBI->connect($NEW_ARGS->{0});
933
$dbi->execute($CREATE_TABLE->{0});
934
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
935
is($dbi->select(table => 'table1')->one->{key1}, 1);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
936

            
937
$dbi = MyDBI->new($NEW_ARGS->{0});
cleanup
Yuki Kimoto authored on 2011-01-25
938
$dbi->connect;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
939
$dbi->execute($CREATE_TABLE->{0});
940
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
941
is($dbi->select(table => 'table1')->one->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
942

            
cleanup
Yuki Kimoto authored on 2011-01-25
943
{
944
    package MyDBI2;
945
    
946
    use base 'DBIx::Custom';
947
    sub connect {
948
        my $self = shift->SUPER::new(@_);
949
        $self->connect;
950
        
951
        return $self;
952
    }
953
}
954

            
955
$dbi = MyDBI->connect($NEW_ARGS->{0});
956
$dbi->execute($CREATE_TABLE->{0});
957
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
958
is($dbi->select(table => 'table1')->one->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
959

            
960
test 'end_filter';
961
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
962
$dbi->execute($CREATE_TABLE->{0});
963
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
964
$result = $dbi->select(table => 'table1');
965
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
966
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
967
$row = $result->fetch_first;
968
is_deeply($row, [6, 40]);
969

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
970
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
971
$dbi->execute($CREATE_TABLE->{0});
972
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
973
$result = $dbi->select(table => 'table1');
974
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
975
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
976
$row = $result->fetch_first;
977
is_deeply($row, [6, 12]);
978

            
979
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
980
$dbi->execute($CREATE_TABLE->{0});
981
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
982
$result = $dbi->select(table => 'table1');
983
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
984
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
985
$row = $result->fetch_first;
986
is_deeply($row, [6, 12]);
987

            
many changed
Yuki Kimoto authored on 2011-01-23
988
$dbi->register_filter(five_times => sub { $_[0] * 5 });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
989
$result = $dbi->select(table => 'table1');
990
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
many changed
Yuki Kimoto authored on 2011-01-23
991
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' });
added tests
Yuki Kimoto authored on 2011-06-08
992
$row = $result->one;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
993
is_deeply($row, {key1 => 6, key2 => 40});
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
994

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
995
$dbi->register_filter(five_times => sub { $_[0] * 5 });
996
$dbi->apply_filter('table1',
997
    key1 => {end => sub { $_[0] * 3 } },
998
    key2 => {end => 'five_times'}
999
);
1000
$result = $dbi->select(table => 'table1');
1001
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
added tests
Yuki Kimoto authored on 2011-06-08
1002
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1003
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
1004

            
1005
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1006
$dbi->apply_filter('table1',
1007
    key1 => {end => sub { $_[0] * 3 } },
1008
    key2 => {end => 'five_times'}
1009
);
1010
$result = $dbi->select(table => 'table1');
1011
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1012
$result->filter(key1 => undef);
1013
$result->end_filter(key1 => undef);
added tests
Yuki Kimoto authored on 2011-06-08
1014
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1015
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1016

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1017
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1018
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1019
$dbi->execute($CREATE_TABLE->{0});
1020
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1021
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1022
$row = $result
1023
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1024
       ->remove_filter
1025
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1026
       ->remove_end_filter
1027
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1028
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1029

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1030
test 'empty where select';
1031
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1032
$dbi->execute($CREATE_TABLE->{0});
1033
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1034
$result = $dbi->select(table => 'table1', where => {});
added tests
Yuki Kimoto authored on 2011-06-08
1035
$row = $result->one;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1036
is_deeply($row, {key1 => 1, key2 => 2});
1037

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1038
test 'select query option';
1039
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1040
$dbi->execute($CREATE_TABLE->{0});
1041
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1042
is(ref $query, 'DBIx::Custom::Query');
1043
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1044
is(ref $query, 'DBIx::Custom::Query');
1045
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1046
is(ref $query, 'DBIx::Custom::Query');
1047
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1048
is(ref $query, 'DBIx::Custom::Query');
1049

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1050
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1051
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1052
$dbi->execute($CREATE_TABLE->{0});
1053
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1054
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1055
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
1056
is("$where", "where ( {= key1} and {= key2} )", 'no param');
1057

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1058
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1059
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1060
             ->param({key1 => 1});
added test
Yuki Kimoto authored on 2011-01-19
1061

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1062
$result = $dbi->select(
1063
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1064
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1065
);
1066
$row = $result->fetch_hash_all;
1067
is_deeply($row, [{key1 => 1, key2 => 2}]);
1068

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1069
$result = $dbi->select(
1070
    table => 'table1',
1071
    where => [
1072
        ['and', '{= key1}', '{= key2}'],
1073
        {key1 => 1}
1074
    ]
1075
);
1076
$row = $result->fetch_hash_all;
1077
is_deeply($row, [{key1 => 1, key2 => 2}]);
1078

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1079
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1080
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1081
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1082
$result = $dbi->select(
1083
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1084
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1085
);
1086
$row = $result->fetch_hash_all;
1087
is_deeply($row, [{key1 => 1, key2 => 2}]);
1088

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1089
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1090
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1091
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1092
$result = $dbi->select(
1093
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1094
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1095
);
1096
$row = $result->fetch_hash_all;
1097
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1098

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1099
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-07
1100
             ->clause(['and', ['or', 'key1 > :key1', 'key1 < :key1'], 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1101
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1102
$result = $dbi->select(
1103
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1104
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1105
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1106
$row = $result->fetch_hash_all;
1107
is_deeply($row, [{key1 => 1, key2 => 2}]);
1108

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1109
$where = $dbi->where;
1110
$result = $dbi->select(
1111
    table => 'table1',
1112
    where => $where
1113
);
1114
$row = $result->fetch_hash_all;
1115
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1116

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1117
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1118
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1119
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1120
$result = $dbi->select(
1121
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1122
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1123
);
1124
};
1125
ok($@);
1126

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1127
$where = $dbi->where;
1128
is("$where", '');
1129

            
added test
Yuki Kimoto authored on 2011-01-19
1130
$where = $dbi->where
1131
             ->clause(['or', ('{= key1}') x 2])
1132
             ->param({key1 => [1, 3]});
1133
$result = $dbi->select(
1134
    table => 'table1',
1135
    where => $where,
1136
);
1137
$row = $result->fetch_hash_all;
1138
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1139

            
1140
$where = $dbi->where
1141
             ->clause(['or', ('{= key1}') x 2])
1142
             ->param({key1 => [1]});
1143
$result = $dbi->select(
1144
    table => 'table1',
1145
    where => $where,
1146
);
1147
$row = $result->fetch_hash_all;
1148
is_deeply($row, [{key1 => 1, key2 => 2}]);
1149

            
1150
$where = $dbi->where
1151
             ->clause(['or', ('{= key1}') x 2])
1152
             ->param({key1 => 1});
1153
$result = $dbi->select(
1154
    table => 'table1',
1155
    where => $where,
1156
);
1157
$row = $result->fetch_hash_all;
1158
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1159

            
many changed
Yuki Kimoto authored on 2011-01-23
1160
$where = $dbi->where
1161
             ->clause('{= key1}')
1162
             ->param({key1 => 1});
1163
$result = $dbi->select(
1164
    table => 'table1',
1165
    where => $where,
1166
);
1167
$row = $result->fetch_hash_all;
1168
is_deeply($row, [{key1 => 1, key2 => 2}]);
1169

            
1170
$where = $dbi->where
1171
             ->clause('{= key1} {= key2}')
1172
             ->param({key1 => 1});
1173
eval{$where->to_string};
1174
like($@, qr/one column/);
1175

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1176
$where = $dbi->where
1177
             ->clause('{= key1}')
1178
             ->param([]);
1179
eval{$where->to_string};
1180
like($@, qr/Parameter/);
1181

            
1182
$where = $dbi->where
1183
             ->clause(['or', ('{= key1}') x 3])
1184
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1185
$result = $dbi->select(
1186
    table => 'table1',
1187
    where => $where,
1188
);
1189
$row = $result->fetch_hash_all;
1190
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1191

            
1192
$where = $dbi->where
1193
             ->clause(['or', ('{= key1}') x 3])
1194
             ->param({key1 => [1, $dbi->not_exists, 3]});
1195
$result = $dbi->select(
1196
    table => 'table1',
1197
    where => $where,
1198
);
1199
$row = $result->fetch_hash_all;
1200
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1201

            
1202
$where = $dbi->where
1203
             ->clause(['or', ('{= key1}') x 3])
1204
             ->param({key1 => [1, 3, $dbi->not_exists]});
1205
$result = $dbi->select(
1206
    table => 'table1',
1207
    where => $where,
1208
);
1209
$row = $result->fetch_hash_all;
1210
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1211

            
1212
$where = $dbi->where
1213
             ->clause(['or', ('{= key1}') x 3])
1214
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1215
$result = $dbi->select(
1216
    table => 'table1',
1217
    where => $where,
1218
);
1219
$row = $result->fetch_hash_all;
1220
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1221

            
1222
$where = $dbi->where
1223
             ->clause(['or', ('{= key1}') x 3])
1224
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1225
$result = $dbi->select(
1226
    table => 'table1',
1227
    where => $where,
1228
);
1229
$row = $result->fetch_hash_all;
1230
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1231

            
1232
$where = $dbi->where
1233
             ->clause(['or', ('{= key1}') x 3])
1234
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1235
$result = $dbi->select(
1236
    table => 'table1',
1237
    where => $where,
1238
);
1239
$row = $result->fetch_hash_all;
1240
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1241

            
1242
$where = $dbi->where
1243
             ->clause(['or', ('{= key1}') x 3])
1244
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1245
$result = $dbi->select(
1246
    table => 'table1',
1247
    where => $where,
1248
);
1249
$row = $result->fetch_hash_all;
1250
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1251

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1252
$where = $dbi->where
1253
             ->clause(['or', ('{= key1}') x 3])
1254
             ->param({key1 => []});
1255
$result = $dbi->select(
1256
    table => 'table1',
1257
    where => $where,
1258
);
1259
$row = $result->fetch_hash_all;
1260
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1261

            
1262
$where = $dbi->where
1263
             ->clause(['and', '{> key1}', '{< key1}' ])
1264
             ->param({key1 => [2, $dbi->not_exists]});
1265
$result = $dbi->select(
1266
    table => 'table1',
1267
    where => $where,
1268
);
1269
$row = $result->fetch_hash_all;
1270
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1271

            
1272
$where = $dbi->where
1273
             ->clause(['and', '{> key1}', '{< key1}' ])
1274
             ->param({key1 => [$dbi->not_exists, 2]});
1275
$result = $dbi->select(
1276
    table => 'table1',
1277
    where => $where,
1278
);
1279
$row = $result->fetch_hash_all;
1280
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1281

            
1282
$where = $dbi->where
1283
             ->clause(['and', '{> key1}', '{< key1}' ])
1284
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1285
$result = $dbi->select(
1286
    table => 'table1',
1287
    where => $where,
1288
);
1289
$row = $result->fetch_hash_all;
1290
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1291

            
1292
$where = $dbi->where
1293
             ->clause(['and', '{> key1}', '{< key1}' ])
1294
             ->param({key1 => [0, 2]});
1295
$result = $dbi->select(
1296
    table => 'table1',
1297
    where => $where,
1298
);
1299
$row = $result->fetch_hash_all;
1300
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1301

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1302
$where = $dbi->where
1303
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1304
$result = $dbi->select(
1305
    table => 'table1',
1306
    where => $where,
1307
);
1308
$row = $result->fetch_hash_all;
1309
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1310

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1311
eval {$dbi->where(ppp => 1) };
1312
like($@, qr/invalid/);
1313

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1314
test 'dbi_option default';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1315
$dbi = DBIx::Custom->new;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1316
is_deeply($dbi->dbi_option, {});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1317

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1318
test 'register_tag_processor';
1319
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1320
$dbi->register_tag_processor(
1321
    a => sub { 1 }
1322
);
1323
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1324

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1325
test 'register_tag';
1326
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1327
$dbi->register_tag(
1328
    b => sub { 2 }
1329
);
1330
is($dbi->query_builder->tags->{b}->(), 2);
1331

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1332
test 'table not specify exception';
1333
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1334
eval {$dbi->insert};
1335
like($@, qr/table/);
1336
eval {$dbi->update};
1337
like($@, qr/table/);
1338
eval {$dbi->delete};
1339
like($@, qr/table/);
1340
eval {$dbi->select};
1341
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1342

            
1343

            
1344
test 'more tests';
1345
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1346
eval{$dbi->apply_filter('table', 'column', [])};
1347
like($@, qr/apply_filter/);
1348

            
1349
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1350
like($@, qr/apply_filter/);
1351

            
1352
$dbi->apply_filter(
1353

            
1354
);
1355
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1356
$dbi->execute($CREATE_TABLE->{0});
1357
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1358
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1359
$dbi->apply_filter('table1', 'key2', 
1360
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1361
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1362
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1363

            
1364
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1365
$dbi->execute($CREATE_TABLE->{0});
1366
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1367
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1368
$dbi->apply_filter('table1', 'key2', {});
1369
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1370
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1371

            
1372
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1373
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1374
like($@, qr/not registered/);
1375
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1376
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1377
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1378
is($dbi->one, 1);
1379

            
1380
eval{DBIx::Custom->connect()};
cleanup
Yuki Kimoto authored on 2011-04-25
1381
like($@, qr/_connect/);
many changed
Yuki Kimoto authored on 2011-01-23
1382

            
1383
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1384
$dbi->execute($CREATE_TABLE->{0});
1385
$dbi->register_filter(twice => sub { $_[0] * 2 });
1386
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1387
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1388
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1389
is_deeply($row, {key1 => 2, key2 => 2});
1390
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1391
             filter => {key1 => 'no'}) };
1392
like($@, qr//);
1393

            
1394
$dbi->register_filter(one => sub { });
1395
$dbi->default_fetch_filter('one');
1396
ok($dbi->default_fetch_filter);
1397
$dbi->default_bind_filter('one');
1398
ok($dbi->default_bind_filter);
1399
eval{$dbi->default_fetch_filter('no')};
1400
like($@, qr/not registered/);
1401
eval{$dbi->default_bind_filter('no')};
1402
like($@, qr/not registered/);
1403
$dbi->default_bind_filter(undef);
1404
ok(!defined $dbi->default_bind_filter);
1405
$dbi->default_fetch_filter(undef);
1406
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1407
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1408
like($@, qr/Tag not finished/);
1409

            
1410
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1411
$dbi->execute($CREATE_TABLE->{0});
1412
$dbi->register_filter(one => sub { 1 });
1413
$result = $dbi->select(table => 'table1');
1414
eval {$result->filter(key1 => 'no')};
1415
like($@, qr/not registered/);
1416
eval {$result->end_filter(key1 => 'no')};
1417
like($@, qr/not registered/);
1418
$result->default_filter(undef);
1419
ok(!defined $result->default_filter);
1420
$result->default_filter('one');
1421
is($result->default_filter->(), 1);
1422

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1423
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1424
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1425
                             dbi_option => {PrintError => 1});
1426
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1427
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1428
                             dbi_options => {PrintError => 1});
1429
ok($dbi->dbh->{PrintError});
1430

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1431
test 'DBIx::Custom::Result stash()';
1432
$result = DBIx::Custom::Result->new;
1433
is_deeply($result->stash, {}, 'default');
1434
$result->stash->{foo} = 1;
1435
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1436

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1437
test 'filter __ expression';
1438
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1439
$dbi->execute('create table company (id, name, location_id)');
1440
$dbi->execute('create table location (id, name)');
1441
$dbi->apply_filter('location',
1442
  name => {in => sub { uc $_[0] } }
1443
);
1444

            
1445
$dbi->insert(table => 'company', param => {id => 1, name => 'a', location_id => 2});
1446
$dbi->insert(table => 'location', param => {id => 2, name => 'b'});
1447

            
1448
$result = $dbi->select(
1449
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1450
    column => ['location.name as location__name']
1451
);
1452
is($result->fetch_first->[0], 'B');
1453

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1454
$result = $dbi->select(
1455
    table => 'company', relation => {'company.location_id' => 'location.id'},
1456
    column => ['location.name as location__name']
1457
);
1458
is($result->fetch_first->[0], 'B');
1459

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1460
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1461
use MyDBI1;
1462
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1463
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1464
$model = $dbi->model('book');
1465
$model->insert({title => 'a', author => 'b'});
1466
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1467
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1468
$model = $dbi->model('company');
1469
$model->insert({name => 'a'});
1470
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1471
is($dbi->models->{'book'}, $dbi->model('book'));
1472
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1473

            
1474
{
1475
    package MyDBI4;
1476

            
1477
    use strict;
1478
    use warnings;
1479

            
1480
    use base 'DBIx::Custom';
1481

            
1482
    sub connect {
1483
        my $self = shift->SUPER::connect(@_);
1484
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1485
        $self->include_model(
1486
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1487
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1488
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1489
            ]
1490
        );
1491
    }
1492

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1493
    package MyModel2::Base1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1494

            
1495
    use strict;
1496
    use warnings;
1497

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1498
    use base 'DBIx::Custom::Model';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1499

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1500
    package MyModel2::book;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1501

            
1502
    use strict;
1503
    use warnings;
1504

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1505
    use base 'MyModel2::Base1';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1506

            
1507
    sub insert {
1508
        my ($self, $param) = @_;
1509
        
1510
        return $self->SUPER::insert(param => $param);
1511
    }
1512

            
1513
    sub list { shift->select; }
1514

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1515
    package MyModel2::Company;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1516

            
1517
    use strict;
1518
    use warnings;
1519

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1520
    use base 'MyModel2::Base1';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1521

            
1522
    sub insert {
1523
        my ($self, $param) = @_;
1524
        
1525
        return $self->SUPER::insert(param => $param);
1526
    }
1527

            
1528
    sub list { shift->select; }
1529
}
1530
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1531
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1532
$model = $dbi->model('book');
1533
$model->insert({title => 'a', author => 'b'});
1534
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1535
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1536
$model = $dbi->model('company');
1537
$model->insert({name => 'a'});
1538
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1539

            
1540
{
1541
     package MyDBI5;
1542

            
1543
    use strict;
1544
    use warnings;
1545

            
1546
    use base 'DBIx::Custom';
1547

            
1548
    sub connect {
1549
        my $self = shift->SUPER::connect(@_);
1550
        
1551
        $self->include_model('MyModel4');
1552
    }
1553
}
1554
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1555
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1556
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1557
$model = $dbi->model('company');
1558
$model->insert({name => 'a'});
1559
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1560
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1561
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1562
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1563

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1564
test 'primary_key';
1565
use MyDBI1;
1566
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1567
$model = $dbi->model('book');
1568
$model->primary_key(['id', 'number']);
1569
is_deeply($model->primary_key, ['id', 'number']);
1570

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1571
test 'columns';
1572
use MyDBI1;
1573
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1574
$model = $dbi->model('book');
1575
$model->columns(['id', 'number']);
1576
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1577

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1578
test 'setup_model';
1579
use MyDBI1;
1580
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1581
$dbi->execute('create table book (id)');
1582
$dbi->execute('create table company (id, name);');
1583
$dbi->execute('create table test (id, name, primary key (id, name));');
1584
$dbi->setup_model;
1585
is_deeply($dbi->model('book')->columns, ['id']);
1586
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1587

            
1588
test 'delete_at';
1589
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1590
$dbi->execute($CREATE_TABLE->{1});
1591
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1592
$dbi->delete_at(
1593
    table => 'table1',
1594
    primary_key => ['key1', 'key2'],
1595
    where => [1, 2],
1596
);
1597
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1598

            
1599
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1600
$dbi->delete_at(
1601
    table => 'table1',
1602
    primary_key => 'key1',
1603
    where => 1,
1604
);
1605
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1606

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1607
test 'insert_at';
1608
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1609
$dbi->execute($CREATE_TABLE->{1});
1610
$dbi->insert_at(
1611
    primary_key => ['key1', 'key2'], 
1612
    table => 'table1',
1613
    where => [1, 2],
1614
    param => {key3 => 3}
1615
);
added tests
Yuki Kimoto authored on 2011-06-08
1616
is($dbi->select(table => 'table1')->one->{key1}, 1);
1617
is($dbi->select(table => 'table1')->one->{key2}, 2);
1618
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1619

            
1620
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1621
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1622
$dbi->insert_at(
1623
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1624
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1625
    where => 1,
1626
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1627
);
1628

            
added tests
Yuki Kimoto authored on 2011-06-08
1629
is($dbi->select(table => 'table1')->one->{key1}, 1);
1630
is($dbi->select(table => 'table1')->one->{key2}, 2);
1631
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1632

            
1633
eval {
1634
    $dbi->insert_at(
1635
        table => 'table1',
1636
        primary_key => ['key1', 'key2'],
1637
        where => {},
1638
        param => {key1 => 1, key2 => 2, key3 => 3},
1639
    );
1640
};
1641
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1642

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1643
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1644
$dbi->execute($CREATE_TABLE->{1});
1645
$dbi->insert_at(
1646
    {key3 => 3},
1647
    primary_key => ['key1', 'key2'], 
1648
    table => 'table1',
1649
    where => [1, 2],
1650
);
added tests
Yuki Kimoto authored on 2011-06-08
1651
is($dbi->select(table => 'table1')->one->{key1}, 1);
1652
is($dbi->select(table => 'table1')->one->{key2}, 2);
1653
is($dbi->select(table => 'table1')->one->{key3}, 3);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1654

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1655
test 'update_at';
1656
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1657
$dbi->execute($CREATE_TABLE->{1});
1658
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1659
$dbi->update_at(
1660
    table => 'table1',
1661
    primary_key => ['key1', 'key2'],
1662
    where => [1, 2],
1663
    param => {key3 => 4}
1664
);
added tests
Yuki Kimoto authored on 2011-06-08
1665
is($dbi->select(table => 'table1')->one->{key1}, 1);
1666
is($dbi->select(table => 'table1')->one->{key2}, 2);
1667
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1668

            
1669
$dbi->delete_all(table => 'table1');
1670
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1671
$dbi->update_at(
1672
    table => 'table1',
1673
    primary_key => 'key1',
1674
    where => 1,
1675
    param => {key3 => 4}
1676
);
added tests
Yuki Kimoto authored on 2011-06-08
1677
is($dbi->select(table => 'table1')->one->{key1}, 1);
1678
is($dbi->select(table => 'table1')->one->{key2}, 2);
1679
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1680

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1681
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1682
$dbi->execute($CREATE_TABLE->{1});
1683
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1684
$dbi->update_at(
1685
    {key3 => 4},
1686
    table => 'table1',
1687
    primary_key => ['key1', 'key2'],
1688
    where => [1, 2]
1689
);
added tests
Yuki Kimoto authored on 2011-06-08
1690
is($dbi->select(table => 'table1')->one->{key1}, 1);
1691
is($dbi->select(table => 'table1')->one->{key2}, 2);
1692
is($dbi->select(table => 'table1')->one->{key3}, 4);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1693

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1694
test 'select_at';
1695
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1696
$dbi->execute($CREATE_TABLE->{1});
1697
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1698
$result = $dbi->select_at(
1699
    table => 'table1',
1700
    primary_key => ['key1', 'key2'],
1701
    where => [1, 2]
1702
);
added tests
Yuki Kimoto authored on 2011-06-08
1703
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1704
is($row->{key1}, 1);
1705
is($row->{key2}, 2);
1706
is($row->{key3}, 3);
1707

            
1708
$dbi->delete_all(table => 'table1');
1709
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1710
$result = $dbi->select_at(
1711
    table => 'table1',
1712
    primary_key => 'key1',
1713
    where => 1,
1714
);
added tests
Yuki Kimoto authored on 2011-06-08
1715
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1716
is($row->{key1}, 1);
1717
is($row->{key2}, 2);
1718
is($row->{key3}, 3);
1719

            
1720
$dbi->delete_all(table => 'table1');
1721
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1722
$result = $dbi->select_at(
1723
    table => 'table1',
1724
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1725
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1726
);
added tests
Yuki Kimoto authored on 2011-06-08
1727
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1728
is($row->{key1}, 1);
1729
is($row->{key2}, 2);
1730
is($row->{key3}, 3);
1731

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1732
eval {
1733
    $result = $dbi->select_at(
1734
        table => 'table1',
1735
        primary_key => ['key1', 'key2'],
1736
        where => {},
1737
    );
1738
};
1739
like($@, qr/must be/);
1740

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1741
eval {
1742
    $result = $dbi->select_at(
1743
        table => 'table1',
1744
        primary_key => ['key1', 'key2'],
1745
        where => [1],
1746
    );
1747
};
1748
like($@, qr/same/);
1749

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1750
eval {
1751
    $result = $dbi->update_at(
1752
        table => 'table1',
1753
        primary_key => ['key1', 'key2'],
1754
        where => {},
1755
        param => {key1 => 1, key2 => 2},
1756
    );
1757
};
1758
like($@, qr/must be/);
1759

            
1760
eval {
1761
    $result = $dbi->delete_at(
1762
        table => 'table1',
1763
        primary_key => ['key1', 'key2'],
1764
        where => {},
1765
    );
1766
};
1767
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1768

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1769
test 'columns';
1770
use MyDBI1;
1771
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1772
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1773

            
1774

            
1775
test 'model delete_at';
1776
{
1777
    package MyDBI6;
1778
    
1779
    use base 'DBIx::Custom';
1780
    
1781
    sub connect {
1782
        my $self = shift->SUPER::connect(@_);
1783
        
1784
        $self->include_model('MyModel5');
1785
        
1786
        return $self;
1787
    }
1788
}
1789
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1790
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1791
$dbi->execute("create table table2 (key1, key2, key3)");
1792
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1793
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1794
$dbi->model('table1')->delete_at(where => [1, 2]);
1795
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1796
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1797
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1798
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1799
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1800
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1801
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1802

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1803
test 'model insert_at';
1804
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1805
$dbi->execute($CREATE_TABLE->{1});
1806
$dbi->model('table1')->insert_at(
1807
    where => [1, 2],
1808
    param => {key3 => 3}
1809
);
1810
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1811
$row = $result->one;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1812
is($row->{key1}, 1);
1813
is($row->{key2}, 2);
1814
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1815

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1816
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1817
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1818
$dbi->execute($CREATE_TABLE->{1});
1819
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1820
$dbi->model('table1')->update_at(
1821
    where => [1, 2],
1822
    param => {key3 => 4}
1823
);
1824
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1825
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1826
is($row->{key1}, 1);
1827
is($row->{key2}, 2);
1828
is($row->{key3}, 4);
1829

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1830
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1831
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1832
$dbi->execute($CREATE_TABLE->{1});
1833
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1834
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1835
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1836
is($row->{key1}, 1);
1837
is($row->{key2}, 2);
1838
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1839

            
1840

            
cleanup
Yuki Kimoto authored on 2011-03-21
1841
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1842
{
1843
    package MyDBI7;
1844
    
1845
    use base 'DBIx::Custom';
1846
    
1847
    sub connect {
1848
        my $self = shift->SUPER::connect(@_);
1849
        
1850
        $self->include_model('MyModel6');
1851
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1852
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1853
        return $self;
1854
    }
1855
}
1856
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1857
$dbi->execute($CREATE_TABLE->{0});
1858
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1859
$dbi->setup_model;
1860
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1861
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1862
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1863
$result = $model->select(
1864
    column => [$model->mycolumn, $model->column('table2')],
1865
    where => {'table1.key1' => 1}
1866
);
added tests
Yuki Kimoto authored on 2011-06-08
1867
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1868
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1869

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1870
test 'update_param';
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1871
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1872
$dbi->execute($CREATE_TABLE->{1});
1873
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1874
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1875

            
1876
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1877
$update_param = $dbi->update_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1878
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1879
update table1 $update_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1880
where key1 = 1
1881
EOS
1882
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1883
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1884
$rows   = $result->fetch_hash_all;
1885
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1886
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1887
                  "basic");
1888

            
1889

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1890
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1891
$dbi->execute($CREATE_TABLE->{1});
1892
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1893
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1894

            
1895
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1896
$update_param = $dbi->update_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1897
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1898
update table1 $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1899
where key1 = 1
1900
EOS
1901
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1902
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1903
$rows   = $result->fetch_hash_all;
1904
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1905
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1906
                  "basic");
1907

            
1908
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1909
$dbi->execute($CREATE_TABLE->{1});
1910
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1911
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1912

            
1913
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1914
$update_param = $dbi->update_param($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1915
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1916
update table1 set $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1917
where key1 = 1
1918
EOS
1919
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1920
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1921
$rows   = $result->fetch_hash_all;
1922
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1923
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1924
                  "update param no_set");
1925

            
1926
            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1927
eval { $dbi->update_param({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1928
like($@, qr/not safety/);
1929

            
1930

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1931
test 'update_param';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1932
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1933
$dbi->execute($CREATE_TABLE->{1});
1934
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1935
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1936

            
1937
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1938
$update_param = $dbi->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1939
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1940
update table1 set $update_param
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1941
where key1 = 1
1942
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1943
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1944
$result = $dbi->execute($SELECT_SOURCES->{0});
1945
$rows   = $result->fetch_hash_all;
1946
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1947
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1948
                  "basic");
1949

            
1950

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1951
test 'insert_param';
1952
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1953
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1954
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1955
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1956
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1957
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1958
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1959
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
1960
is($dbi->select(table => 'table1')->one->{key1}, 1);
1961
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1962

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1963
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1964
$dbi->reserved_word_quote('"');
1965
$dbi->execute($CREATE_TABLE->{1});
1966
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1967
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1968
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1969
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1970
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1971
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
1972
is($dbi->select(table => 'table1')->one->{key1}, 1);
1973
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1974

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1975
eval { $dbi->insert_param({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1976
like($@, qr/not safety/);
cleanup
Yuki Kimoto authored on 2011-03-08
1977

            
1978

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1979
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1980
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1981
$dbi->execute($CREATE_TABLE->{0});
1982
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1983
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1984
$dbi->execute($CREATE_TABLE->{2});
1985
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1986
$dbi->execute($CREATE_TABLE->{4});
1987
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1988
$rows = $dbi->select(
1989
    table => 'table1',
1990
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1991
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1992
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1993
)->fetch_hash_all;
1994
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1995

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1996
$rows = $dbi->select(
1997
    table => 'table1',
1998
    where   => {'key1' => 1},
1999
    join  => ['left outer join table2 on table1.key1 = table2.key1']
2000
)->fetch_hash_all;
2001
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2002

            
cleanup
Yuki Kimoto authored on 2011-03-08
2003
eval {
2004
    $rows = $dbi->select(
2005
        table => 'table1',
2006
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2007
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2008
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2009
    );
2010
};
2011
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2012

            
2013
$rows = $dbi->select(
2014
    table => 'table1',
2015
    where   => {'key1' => 1},
2016
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2017
              'left outer join table3 on table2.key3 = table3.key3']
2018
)->fetch_hash_all;
2019
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2020

            
2021
$rows = $dbi->select(
2022
    column => 'table3.key4 as table3__key4',
2023
    table => 'table1',
2024
    where   => {'table1.key1' => 1},
2025
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2026
              'left outer join table3 on table2.key3 = table3.key3']
2027
)->fetch_hash_all;
2028
is_deeply($rows, [{table3__key4 => 4}]);
2029

            
2030
$rows = $dbi->select(
2031
    column => 'table1.key1 as table1__key1',
2032
    table => 'table1',
2033
    where   => {'table3.key4' => 4},
2034
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2035
              'left outer join table3 on table2.key3 = table3.key3']
2036
)->fetch_hash_all;
2037
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2038

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2039
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2040
$dbi->reserved_word_quote('"');
2041
$dbi->execute($CREATE_TABLE->{0});
2042
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2043
$dbi->execute($CREATE_TABLE->{2});
2044
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2045
$rows = $dbi->select(
2046
    table => 'table1',
2047
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2048
    where   => {'table1.key2' => 2},
2049
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
2050
)->fetch_hash_all;
2051
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
2052
          'reserved_word_quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2053

            
2054
{
2055
    package MyDBI8;
2056
    
2057
    use base 'DBIx::Custom';
2058
    
2059
    sub connect {
2060
        my $self = shift->SUPER::connect(@_);
2061
        
2062
        $self->include_model('MyModel7');
2063
        
2064
        return $self;
2065
    }
2066
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2067

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2068
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2069
$dbi->execute($CREATE_TABLE->{0});
2070
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2071
$sql = <<"EOS";
2072
left outer join (
2073
  select * from table1 as t1
2074
  where t1.key2 = (
2075
    select max(t2.key2) from table1 as t2
2076
    where t1.key1 = t2.key1
2077
  )
2078
) as latest_table1 on table1.key1 = latest_table1.key1
2079
EOS
2080
$join = [$sql];
2081
$rows = $dbi->select(
2082
    table => 'table1',
2083
    column => 'latest_table1.key1 as latest_table1__key1',
2084
    join  => $join
2085
)->fetch_hash_all;
2086
is_deeply($rows, [{latest_table1__key1 => 1}]);
2087

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2088
test 'mycolumn';
2089
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2090
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2091
$dbi->execute($CREATE_TABLE->{2});
2092
$dbi->setup_model;
2093
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2094
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2095
$model = $dbi->model('table1');
2096
$result = $model->select_at(
2097
    column => [
2098
        $model->mycolumn,
2099
        $model->column('table2')
2100
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2101
);
added tests
Yuki Kimoto authored on 2011-06-08
2102
is_deeply($result->one,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2103
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2104

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2105
$result = $model->select_at(
2106
    column => [
2107
        $model->mycolumn(['key1']),
2108
        $model->column(table2 => ['key1'])
2109
    ]
2110
);
added tests
Yuki Kimoto authored on 2011-06-08
2111
is_deeply($result->one,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2112
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2113

            
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2114
$result = $model->select_at(
2115
    column => [
2116
        $model->mycolumn(['key1']),
2117
        {table2 => ['key1']}
2118
    ]
2119
);
added tests
Yuki Kimoto authored on 2011-06-08
2120
is_deeply($result->one,
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2121
          {key1 => 1, table2__key1 => 1});
2122

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2123
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2124
{
2125
    package MyDBI9;
2126
    
2127
    use base 'DBIx::Custom';
2128
    
2129
    sub connect {
2130
        my $self = shift->SUPER::connect(@_);
2131
        
2132
        $self->include_model('MyModel8')->setup_model;
2133
        
2134
        return $self;
2135
    }
2136
}
2137
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2138
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2139
$model = $dbi->model('table1');
2140
eval{$model->execute('select * from table1')};
2141
ok(!$@);
2142

            
2143
test 'table_alias';
2144
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2145
$dbi->execute($CREATE_TABLE->{0});
2146
$dbi->execute($CREATE_TABLE->{2});
2147
$dbi->setup_model;
2148
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2149
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2150
$model = $dbi->model('table1');
2151
$result = $model->select(
2152
    column => [
2153
        $model->column('table2_alias')
2154
    ],
2155
    where => {'table2_alias.key3' => 2}
2156
);
added tests
Yuki Kimoto authored on 2011-06-08
2157
is_deeply($result->one, 
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2158
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
2159

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2160
test 'type() option';
2161
$dbi = DBIx::Custom->connect(
2162
    data_source => 'dbi:SQLite:dbname=:memory:',
2163
    dbi_option => {
2164
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2165
    }
2166
);
2167
my $binary = pack("I3", 1, 2, 3);
2168
$dbi->execute('create table table1(key1, key2)');
2169
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2170
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2171
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2172
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2173
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2174
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2175
is($row->{key1_length}, length $binary);
2176

            
2177
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2178
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2179
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2180
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2181
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2182
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2183
is($row->{key1_length}, length $binary);
2184

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2185
test 'create_model';
2186
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2187
$dbi->execute($CREATE_TABLE->{0});
2188
$dbi->execute($CREATE_TABLE->{2});
2189

            
2190
$dbi->create_model(
2191
    table => 'table1',
2192
    join => [
2193
       'left outer join table2 on table1.key1 = table2.key1'
2194
    ],
2195
    primary_key => ['key1']
2196
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2197
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2198
    table => 'table2'
2199
);
2200
$dbi->create_model(
2201
    table => 'table3',
2202
    filter => [
2203
        key1 => {in => sub { uc $_[0] }}
2204
    ]
2205
);
2206
$dbi->setup_model;
2207
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2208
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2209
$model = $dbi->model('table1');
2210
$result = $model->select(
2211
    column => [$model->mycolumn, $model->column('table2')],
2212
    where => {'table1.key1' => 1}
2213
);
added tests
Yuki Kimoto authored on 2011-06-08
2214
is_deeply($result->one,
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2215
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2216
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2217

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2218
test 'model method';
2219
test 'create_model';
2220
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2221
$dbi->execute($CREATE_TABLE->{2});
2222
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2223
$model = $dbi->create_model(
2224
    table => 'table2'
2225
);
2226
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2227
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2228

            
2229
test 'merge_param';
2230
{
2231
    my $dbi = DBIx::Custom->new;
2232
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2233
    my $param2 = {key1 => 1, key2 => 2};
2234
    my $param3 = {key1 => 1};
2235
    my $param = $dbi->merge_param($param1, $param2, $param3);
2236
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2237
}
2238

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2239
{
2240
    my $dbi = DBIx::Custom->new;
2241
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2242
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2243
    my $param = $dbi->merge_param($param1, $param2);
2244
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2245
}
2246

            
cleanup
Yuki Kimoto authored on 2011-04-01
2247
test 'select() param option';
2248
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2249
$dbi->execute($CREATE_TABLE->{0});
2250
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2251
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2252
$dbi->execute($CREATE_TABLE->{2});
2253
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2254
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2255
$rows = $dbi->select(
2256
    table => 'table1',
2257
    column => 'table1.key1 as table1_key1, key2, key3',
2258
    where   => {'table1.key2' => 3},
2259
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2260
              ' as table2 on table1.key1 = table2.key1'],
2261
    param => {'table2.key3' => 5}
2262
)->fetch_hash_all;
2263
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2264

            
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2265

            
2266
test 'select() wrap option';
2267
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2268
$dbi->execute($CREATE_TABLE->{0});
2269
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2270
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2271
$rows = $dbi->select(
2272
    table => 'table1',
2273
    column => 'key1',
2274
    wrap => ['select * from (', ') as t where key1 = 1']
2275
)->fetch_hash_all;
2276
is_deeply($rows, [{key1 => 1}]);
2277

            
2278
eval {
2279
$dbi->select(
2280
    table => 'table1',
2281
    column => 'key1',
2282
    wrap => 'select * from ('
2283
)
2284
};
cleanup
Yuki Kimoto authored on 2011-04-25
2285
like($@, qr/array/);
2286

            
2287
test 'select() string where';
2288
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2289
$dbi->execute($CREATE_TABLE->{0});
2290
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2291
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2292
$rows = $dbi->select(
2293
    table => 'table1',
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2294
    where => '{= key1} and {= key2}',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2295
    where_param => {key1 => 1, key2 => 2}
cleanup
Yuki Kimoto authored on 2011-04-25
2296
)->fetch_hash_all;
2297
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2298

            
2299
test 'delete() string where';
2300
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2301
$dbi->execute($CREATE_TABLE->{0});
2302
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2303
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2304
$dbi->delete(
2305
    table => 'table1',
2306
    where => '{= key1} and {= key2}',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2307
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2308
);
2309
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
2310
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2311

            
2312

            
2313
test 'update() string where';
2314
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2315
$dbi->execute($CREATE_TABLE->{0});
2316
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2317
$dbi->update(
2318
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2319
    param => {key1 => 5},
2320
    where => '{= key1} and {= key2}',
2321
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2322
);
2323
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
2324
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2325

            
cleanup
Yuki Kimoto authored on 2011-06-08
2326

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2327
test 'insert id and primary_key option';
2328
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2329
$dbi->execute($CREATE_TABLE->{1});
2330
$dbi->insert(
2331
    primary_key => ['key1', 'key2'], 
2332
    table => 'table1',
2333
    id => [1, 2],
2334
    param => {key3 => 3}
2335
);
2336
is($dbi->select(table => 'table1')->one->{key1}, 1);
2337
is($dbi->select(table => 'table1')->one->{key2}, 2);
2338
is($dbi->select(table => 'table1')->one->{key3}, 3);
2339

            
2340
$dbi->delete_all(table => 'table1');
2341
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2342
$dbi->insert(
2343
    primary_key => 'key1', 
2344
    table => 'table1',
2345
    id => 1,
2346
    param => {key2 => 2, key3 => 3}
2347
);
2348

            
2349
is($dbi->select(table => 'table1')->one->{key1}, 1);
2350
is($dbi->select(table => 'table1')->one->{key2}, 2);
2351
is($dbi->select(table => 'table1')->one->{key3}, 3);
2352

            
2353
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2354
$dbi->execute($CREATE_TABLE->{1});
2355
$dbi->insert(
2356
    {key3 => 3},
2357
    primary_key => ['key1', 'key2'], 
2358
    table => 'table1',
2359
    id => [1, 2],
2360
);
2361
is($dbi->select(table => 'table1')->one->{key1}, 1);
2362
is($dbi->select(table => 'table1')->one->{key2}, 2);
2363
is($dbi->select(table => 'table1')->one->{key3}, 3);
2364

            
cleanup
Yuki Kimoto authored on 2011-06-08
2365

            
added tests
Yuki Kimoto authored on 2011-06-08
2366
test 'model insert id and primary_key option';
2367
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2368
$dbi->execute($CREATE_TABLE->{1});
2369
$dbi->model('table1')->insert(
2370
    id => [1, 2],
2371
    param => {key3 => 3}
2372
);
2373
$result = $dbi->model('table1')->select;
2374
$row = $result->one;
2375
is($row->{key1}, 1);
2376
is($row->{key2}, 2);
2377
is($row->{key3}, 3);
2378

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2379
test 'update and id option';
2380
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2381
$dbi->execute($CREATE_TABLE->{1});
2382
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2383
$dbi->update(
2384
    table => 'table1',
2385
    primary_key => ['key1', 'key2'],
2386
    id => [1, 2],
2387
    param => {key3 => 4}
2388
);
2389
is($dbi->select(table => 'table1')->one->{key1}, 1);
2390
is($dbi->select(table => 'table1')->one->{key2}, 2);
2391
is($dbi->select(table => 'table1')->one->{key3}, 4);
2392

            
2393
$dbi->delete_all(table => 'table1');
2394
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2395
$dbi->update(
2396
    table => 'table1',
2397
    primary_key => 'key1',
2398
    id => 1,
2399
    param => {key3 => 4}
2400
);
2401
is($dbi->select(table => 'table1')->one->{key1}, 1);
2402
is($dbi->select(table => 'table1')->one->{key2}, 2);
2403
is($dbi->select(table => 'table1')->one->{key3}, 4);
2404

            
2405
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2406
$dbi->execute($CREATE_TABLE->{1});
2407
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2408
$dbi->update(
2409
    {key3 => 4},
2410
    table => 'table1',
2411
    primary_key => ['key1', 'key2'],
2412
    id => [1, 2]
2413
);
2414
is($dbi->select(table => 'table1')->one->{key1}, 1);
2415
is($dbi->select(table => 'table1')->one->{key2}, 2);
2416
is($dbi->select(table => 'table1')->one->{key3}, 4);
2417

            
2418

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2419
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2420
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2421
$dbi->execute($CREATE_TABLE->{1});
2422
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2423
$dbi->model('table1')->update(
2424
    id => [1, 2],
2425
    param => {key3 => 4}
2426
);
2427
$result = $dbi->model('table1')->select;
2428
$row = $result->one;
2429
is($row->{key1}, 1);
2430
is($row->{key2}, 2);
2431
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2432

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2433

            
2434
test 'delete and id option';
2435
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2436
$dbi->execute($CREATE_TABLE->{1});
2437
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2438
$dbi->delete(
2439
    table => 'table1',
2440
    primary_key => ['key1', 'key2'],
2441
    id => [1, 2],
2442
);
2443
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2444

            
2445
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2446
$dbi->delete(
2447
    table => 'table1',
2448
    primary_key => 'key1',
2449
    id => 1,
2450
);
2451
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2452

            
2453

            
2454
test 'model delete and id option';
2455
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2456
$dbi->execute($CREATE_TABLE->{1});
2457
$dbi->execute("create table table2 (key1, key2, key3)");
2458
$dbi->execute("create table table3 (key1, key2, key3)");
2459
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2460
$dbi->model('table1')->delete(id => [1, 2]);
2461
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2462
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2463
$dbi->model('table1_1')->delete(id => [1, 2]);
2464
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2465
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2466
$dbi->model('table1_3')->delete(id => [1, 2]);
2467
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2468

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2469

            
2470
test 'select and id option';
2471
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2472
$dbi->execute($CREATE_TABLE->{1});
2473
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2474
$result = $dbi->select(
2475
    table => 'table1',
2476
    primary_key => ['key1', 'key2'],
2477
    id => [1, 2]
2478
);
2479
$row = $result->one;
2480
is($row->{key1}, 1);
2481
is($row->{key2}, 2);
2482
is($row->{key3}, 3);
2483

            
2484
$dbi->delete_all(table => 'table1');
2485
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2486
$result = $dbi->select(
2487
    table => 'table1',
2488
    primary_key => 'key1',
2489
    id => 1,
2490
);
2491
$row = $result->one;
2492
is($row->{key1}, 1);
2493
is($row->{key2}, 2);
2494
is($row->{key3}, 3);
2495

            
2496
$dbi->delete_all(table => 'table1');
2497
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2498
$result = $dbi->select(
2499
    table => 'table1',
2500
    primary_key => ['key1', 'key2'],
2501
    id => [1, 2]
2502
);
2503
$row = $result->one;
2504
is($row->{key1}, 1);
2505
is($row->{key2}, 2);
2506
is($row->{key3}, 3);
2507

            
2508

            
2509
test 'model select_at';
2510
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2511
$dbi->execute($CREATE_TABLE->{1});
2512
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2513
$result = $dbi->model('table1')->select(id => [1, 2]);
2514
$row = $result->one;
2515
is($row->{key1}, 1);
2516
is($row->{key2}, 2);
2517
is($row->{key3}, 3);
2518

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2519
=cut