DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
2520 lines | 83.36kb
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

            
fixed DEPRECATED messages
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}";
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
113
$DB::single = 1;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
114
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
115
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
116
ok($ret_val);
removed register_format()
yuki-kimoto authored on 2010-05-26
117

            
118

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

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

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
167
$source = "select * from table1 where {<= key1} and {like key2};";
168
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
169
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
170
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
171
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
172

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

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

            
185
test 'DBIx::Custom::SQLTemplate insert tag';
186
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
187
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
188
$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
189

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

            
194
test 'DBIx::Custom::SQLTemplate update tag';
195
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
196
$insert_SOURCE = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
197
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
198
$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
199

            
add tests
yuki-kimoto authored on 2010-08-10
200
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
201
$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
202

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
435

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

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

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

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

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

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

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

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

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

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

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

            
522

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

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

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

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

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

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

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

            
559
$rows = $dbi->select(
560
    table => [qw/table1 table2/],
561
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
562
    relation  => {'table1.key1' => 'table2.key1'}
563
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
564
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
565

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
671

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

            
676
$dbi->begin_work;
677

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

            
684
$dbi->rollback if $@;
685

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

            
690
$dbi->begin_work;
691

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

            
697
$dbi->commit unless $@;
698

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1344

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

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

            
1353
$dbi->apply_filter(
1354

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1475
{
1476
    package MyDBI4;
1477

            
1478
    use strict;
1479
    use warnings;
1480

            
1481
    use base 'DBIx::Custom';
1482

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

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

            
1496
    use strict;
1497
    use warnings;
1498

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

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

            
1503
    use strict;
1504
    use warnings;
1505

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

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

            
1514
    sub list { shift->select; }
1515

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

            
1518
    use strict;
1519
    use warnings;
1520

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

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

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

            
1541
{
1542
     package MyDBI5;
1543

            
1544
    use strict;
1545
    use warnings;
1546

            
1547
    use base 'DBIx::Custom';
1548

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1775

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

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

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

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

            
1841

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

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

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

            
1890

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

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

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

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

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

            
1931

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

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

            
1951

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

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

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

            
1979

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2313

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
2327

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
2366

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

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

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

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

            
2419

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

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

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

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

            
2454

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

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

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

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

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

            
2509

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

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