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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
434

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

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

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

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

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

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

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

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

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

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

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

            
521

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
670

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

            
675
$dbi->begin_work;
676

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

            
683
$dbi->rollback if $@;
684

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

            
689
$dbi->begin_work;
690

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

            
696
$dbi->commit unless $@;
697

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1343

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

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

            
1352
$dbi->apply_filter(
1353

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1460
$result = $dbi->select(
1461
    table => 'company', relation => {'company.location_id' => 'location.id'},
1462
    column => ['location.name as "location.name"']
1463
);
1464
is($result->fetch_first->[0], 'B');
1465

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

            
1480
{
1481
    package MyDBI4;
1482

            
1483
    use strict;
1484
    use warnings;
1485

            
1486
    use base 'DBIx::Custom';
1487

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

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

            
1501
    use strict;
1502
    use warnings;
1503

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

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

            
1508
    use strict;
1509
    use warnings;
1510

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

            
1513
    sub insert {
1514
        my ($self, $param) = @_;
1515
        
1516
        return $self->SUPER::insert(param => $param);
1517
    }
1518

            
1519
    sub list { shift->select; }
1520

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

            
1523
    use strict;
1524
    use warnings;
1525

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

            
1528
    sub insert {
1529
        my ($self, $param) = @_;
1530
        
1531
        return $self->SUPER::insert(param => $param);
1532
    }
1533

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

            
1546
{
1547
     package MyDBI5;
1548

            
1549
    use strict;
1550
    use warnings;
1551

            
1552
    use base 'DBIx::Custom';
1553

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

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

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

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

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

            
1605
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1606
$dbi->delete_at(
1607
    table => 'table1',
1608
    primary_key => 'key1',
1609
    where => 1,
1610
);
1611
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1612

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1775
test 'columns';
1776
use MyDBI1;
1777
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1778
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1779

            
1780

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

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

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

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

            
1846

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

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

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

            
1895

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

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

            
1914
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1915
$dbi->execute($CREATE_TABLE->{1});
1916
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1917
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1918

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

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

            
1936

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

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

            
1956

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

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

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

            
1984

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

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

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

            
2019
$rows = $dbi->select(
2020
    table => 'table1',
2021
    where   => {'key1' => 1},
2022
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2023
              'left outer join table3 on table2.key3 = table3.key3']
2024
)->fetch_hash_all;
2025
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2026

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

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

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

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

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

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

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

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

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2191
test 'create_model';
2192
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2193
$dbi->execute($CREATE_TABLE->{0});
2194
$dbi->execute($CREATE_TABLE->{2});
2195

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

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

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

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

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

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

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

            
2284
eval {
2285
$dbi->select(
2286
    table => 'table1',
2287
    column => 'key1',
2288
    wrap => 'select * from ('
2289
)
2290
};
cleanup
Yuki Kimoto authored on 2011-04-25
2291
like($@, qr/array/);
2292

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

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

            
2318

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
2332

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

            
2346
$dbi->delete_all(table => 'table1');
2347
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2348
$dbi->insert(
2349
    primary_key => 'key1', 
2350
    table => 'table1',
2351
    id => 1,
2352
    param => {key2 => 2, key3 => 3}
2353
);
2354

            
2355
is($dbi->select(table => 'table1')->one->{key1}, 1);
2356
is($dbi->select(table => 'table1')->one->{key2}, 2);
2357
is($dbi->select(table => 'table1')->one->{key3}, 3);
2358

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
2371

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

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

            
2399
$dbi->delete_all(table => 'table1');
2400
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2401
$dbi->update(
2402
    table => 'table1',
2403
    primary_key => 'key1',
2404
    id => 1,
2405
    param => {key3 => 4}
2406
);
2407
is($dbi->select(table => 'table1')->one->{key1}, 1);
2408
is($dbi->select(table => 'table1')->one->{key2}, 2);
2409
is($dbi->select(table => 'table1')->one->{key3}, 4);
2410

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

            
2424

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

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

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

            
2451
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2452
$dbi->delete(
2453
    table => 'table1',
2454
    primary_key => 'key1',
2455
    id => 1,
2456
);
2457
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
2458

            
2459

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

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

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

            
2490
$dbi->delete_all(table => 'table1');
2491
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2492
$result = $dbi->select(
2493
    table => 'table1',
2494
    primary_key => 'key1',
2495
    id => 1,
2496
);
2497
$row = $result->one;
2498
is($row->{key1}, 1);
2499
is($row->{key2}, 2);
2500
is($row->{key3}, 3);
2501

            
2502
$dbi->delete_all(table => 'table1');
2503
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2504
$result = $dbi->select(
2505
    table => 'table1',
2506
    primary_key => ['key1', 'key2'],
2507
    id => [1, 2]
2508
);
2509
$row = $result->one;
2510
is($row->{key1}, 1);
2511
is($row->{key2}, 2);
2512
is($row->{key3}, 3);
2513

            
2514

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

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2525
test 'col';
2526
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2527
$dbi->execute($CREATE_TABLE->{0});
2528
$dbi->execute($CREATE_TABLE->{2});
2529
$dbi->setup_model;
2530
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2531
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2532
$model = $dbi->model('table1');
2533
$result = $model->select(
2534
    column => [$model->col('table2')],
2535
    where => {'table1.key1' => 1}
2536
);
2537
is_deeply($result->one,
2538
          {'table2.key1' => 1, 'table2.key3' => 3});
2539

            
2540
$result = $model->select(
2541
    column => [$model->col('table2' => [qw/key1 key3/])],
2542
    where => {'table1.key1' => 1}
2543
);
2544
is_deeply($result->one,
2545
          {'table2.key1' => 1, 'table2.key3' => 3});
2546

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