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

            
9
BEGIN {
10
    eval { require DBD::SQLite; 1 }
11
        or plan skip_all => 'DBD::SQLite required';
12
    eval { DBD::SQLite->VERSION >= 1.25 }
13
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
14

            
15
    plan 'no_plan';
16
    use_ok('DBIx::Custom');
17
}
18

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

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

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

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

            
38
my $DROP_TABLE = {
39
    0 => 'drop table table1'
40
};
41

            
42
my $NEW_ARGS = {
43
    0 => {data_source => 'dbi:SQLite:dbname=:memory:'}
44
};
45

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

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

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

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

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

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

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

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

            
113

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

            
123
test 'Filter basic';
124
$dbi->execute($DROP_TABLE->{0});
125
$dbi->execute($CREATE_TABLE->{0});
126
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
127
                    three_times => sub { $_[0] * 3});
128

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

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

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

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

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

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

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

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

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

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

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

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

            
203
test 'Error case';
204
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
cleanup
Yuki Kimoto authored on 2011-01-23
205
ok($@, "connect error");
removed register_format()
yuki-kimoto authored on 2010-05-26
206

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

            
211
test 'insert';
212
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
213
$dbi->execute($CREATE_TABLE->{0});
214
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
215
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
216
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
217
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
218
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
219

            
220
$dbi->execute('delete from table1');
221
$dbi->register_filter(
222
    twice       => sub { $_[0] * 2 },
223
    three_times => sub { $_[0] * 3 }
224
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
225
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
226
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
227
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
228
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
229
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
230
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
231

            
232
$dbi->execute($DROP_TABLE->{0});
233
$dbi->execute($CREATE_TABLE->{0});
234
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
235
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
236
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
237

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
244
test 'update';
245
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
246
$dbi->execute($CREATE_TABLE->{1});
247
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
248
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
249
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
250
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
251
$rows   = $result->fetch_hash_all;
252
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
253
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
254
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
255
                  
256
$dbi->execute("delete from table1");
257
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
258
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
259
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
260
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
261
$rows   = $result->fetch_hash_all;
262
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
263
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
264
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
265

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
273
$dbi->execute("delete from table1");
274
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
275
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
276
$dbi->register_filter(twice => sub { $_[0] * 2 });
277
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
278
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
279
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
280
$rows   = $result->fetch_hash_all;
281
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
282
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
283
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
284

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
293
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
294
$dbi->execute($CREATE_TABLE->{0});
295
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
296
$where = $dbi->where;
297
$where->clause(['and', '{= key1}', '{= key2}']);
298
$where->param({key1 => 1, key2 => 2});
299
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
300
$result = $dbi->select(table => 'table1');
301
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where');
302

            
303
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
304
$dbi->execute($CREATE_TABLE->{0});
305
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
306
$where = $dbi->where;
307
$where->clause(['and', '{= key2}']);
308
$where->param({key2 => 2});
309
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
310
$result = $dbi->select(table => 'table1');
311
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
312

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
319
test 'update_all';
320
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
321
$dbi->execute($CREATE_TABLE->{1});
322
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
323
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
324
$dbi->register_filter(twice => sub { $_[0] * 2 });
325
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
326
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
327
$rows   = $result->fetch_hash_all;
328
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
329
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
330
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
331

            
332

            
333
test 'delete';
334
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
335
$dbi->execute($CREATE_TABLE->{0});
336
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
337
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
338
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
339
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
340
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
341
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
342

            
343
$dbi->execute("delete from table1;");
344
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
345
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
346
$dbi->register_filter(twice => sub { $_[0] * 2 });
347
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
348
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
349
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
350
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
351

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

            
354
$dbi->delete_all(table => 'table1');
355
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
356
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
357
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
358
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
359
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
360

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
364
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
365
$dbi->execute($CREATE_TABLE->{0});
366
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
367
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
368
$where = $dbi->where;
369
$where->clause(['and', '{= key1}', '{= key2}']);
370
$where->param({ke1 => 1, key2 => 2});
371
$dbi->delete(table => 'table1', where => $where);
372
$result = $dbi->select(table => 'table1');
373
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
374

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
385
test 'delete_all';
386
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
387
$dbi->execute($CREATE_TABLE->{0});
388
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
389
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
390
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
391
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
392
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
393
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
394

            
395

            
396
test 'select';
397
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
398
$dbi->execute($CREATE_TABLE->{0});
399
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
400
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
401
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
402
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
403
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
404

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

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

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

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

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

            
422
$dbi->execute($CREATE_TABLE->{2});
423
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
424
$rows = $dbi->select(
425
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
426
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
427
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
428
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
429
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
430
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
431

            
432
$rows = $dbi->select(
433
    table => [qw/table1 table2/],
434
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
435
    relation  => {'table1.key1' => 'table2.key1'}
436
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
437
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
438

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

            
442

            
removed register_format()
yuki-kimoto authored on 2010-05-26
443
test 'fetch filter';
444
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
445
$dbi->register_filter(
446
    twice       => sub { $_[0] * 2 },
447
    three_times => sub { $_[0] * 3 }
448
);
449
$dbi->default_fetch_filter('twice');
450
$dbi->execute($CREATE_TABLE->{0});
451
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
452
$result = $dbi->select(table => 'table1');
453
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
454
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
455
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
456

            
457
test 'filters';
458
$dbi = DBIx::Custom->new;
459

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
466
test 'transaction';
467
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
468
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
469
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
470
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
471
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
472
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
473
$result = $dbi->select(table => 'table1');
474
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
475
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
476

            
477
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
478
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
479
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
480
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
481
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
482

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

            
486
test 'cache';
487
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
488
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
489
$source = 'select * from table1 where {= key1} and {= key2};';
490
$dbi->create_query($source);
491
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
492
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
493

            
494
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
495
$dbi->execute($CREATE_TABLE->{0});
496
$dbi->{_cached} = {};
497
$dbi->cache(0);
498
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
499
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
500

            
add tests
yuki-kimoto authored on 2010-08-10
501
test 'execute';
502
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
503
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
504
{
505
    local $Carp::Verbose = 0;
506
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
507
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
508
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
509
}
510
{
511
    local $Carp::Verbose = 1;
512
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
513
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
514
}
add tests
yuki-kimoto authored on 2010-08-10
515

            
516
eval{$dbi->execute('select * from table1', no_exists => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
517
like($@, qr/invalid/, "invald SQL");
add tests
yuki-kimoto authored on 2010-08-10
518

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
524
{
525
    local $Carp::Verbose = 0;
526
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
527
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
528
}
529
{
530
    local $Carp::Verbose = 1;
531
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
532
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
533
}
cleanup
yuki-kimoto authored on 2010-10-17
534

            
535

            
536
test 'transaction';
537
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
538
$dbi->execute($CREATE_TABLE->{0});
539

            
540
$dbi->begin_work;
541

            
542
eval {
543
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
544
    die "Error";
545
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
546
};
547

            
548
$dbi->rollback if $@;
549

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

            
554
$dbi->begin_work;
555

            
556
eval {
557
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
558
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
559
};
560

            
561
$dbi->commit unless $@;
562

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

            
567
$dbi->dbh->{AutoCommit} = 0;
568
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
569
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
570
$dbi->dbh->{AutoCommit} = 1;
571

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
573
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
574
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
575
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
576
    one => sub { 1 }
577
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
578
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
579
    two => sub { 2 }
580
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
581
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
582
    twice => sub {
583
        my $self = shift;
584
        return $_[0] * 2;
585
    }
586
});
587

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
595
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
596
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
597
$dbi->execute($CREATE_TABLE->{0});
598
$dbi->register_filter(twice => sub { $_[0] * 2 });
599
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
600
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
601
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
602
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
603
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
604
$result = $dbi->execute($SELECT_SOURCES->{0});
605
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
606
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
607
$result = $dbi->select(table => 'table1');
608
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
609
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
610

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
611
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
612
$dbi->execute($CREATE_TABLE->{0});
613
$dbi->register_filter(twice => sub { $_[0] * 2 });
614
$dbi->register_filter(three_times => sub { $_[0] * 3});
615
$dbi->apply_filter(
616
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
617
              'key2' => {out => 'three_times', in => 'twice'});
618
$dbi->apply_filter(
619
    'table1', 'key1' => {out => undef}
620
); 
621
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
622
$result = $dbi->execute($SELECT_SOURCES->{0});
623
$row   = $result->fetch_hash_first;
624
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
625

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
626
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
627
$dbi->execute($CREATE_TABLE->{0});
628
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
629
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
630
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
631
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
632
$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
633
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
634
$result = $dbi->execute($SELECT_SOURCES->{0});
635
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
636
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
637

            
638
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
639
$dbi->execute($CREATE_TABLE->{0});
640
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
641
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
642
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
643
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
644
$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
645
$dbi->delete(table => 'table1', where => {key1 => 1});
646
$result = $dbi->execute($SELECT_SOURCES->{0});
647
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
648
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
649

            
650
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
651
$dbi->execute($CREATE_TABLE->{0});
652
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
653
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
654
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
655
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
656
$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
657
$result = $dbi->select(table => 'table1', where => {key1 => 1});
658
$result->filter({'key2' => 'twice'});
659
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
660
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
661

            
662
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
663
$dbi->execute($CREATE_TABLE->{0});
664
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
665
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
666
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
667
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
668
$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
669
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
670
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
671
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
672
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
673
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
674

            
add table tag
Yuki Kimoto authored on 2011-02-09
675
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
676
$dbi->execute($CREATE_TABLE->{0});
677
$dbi->register_filter(twice => sub { $_[0] * 2 });
678
$dbi->apply_filter(
679
    'table1', 'key1' => {out => 'twice', in => 'twice'}
680
);
681
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
682
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
683
                        param => {key1 => 1, key2 => 2});
684
$rows   = $result->fetch_hash_all;
685
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
686

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
687
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
688
$dbi->execute($CREATE_TABLE->{0});
689
$dbi->execute($CREATE_TABLE->{2});
690
$dbi->register_filter(twice => sub { $_[0] * 2 });
691
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
692
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
693
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
694
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
695
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
696
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
697
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
698
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
699
$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
700
$result = $dbi->select(
701
     table => ['table1', 'table2'],
702
     column => ['key2', 'key3'],
703
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
704

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

            
709
$result = $dbi->select(
710
     table => ['table1', 'table2'],
711
     column => ['key2', 'key3'],
712
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
713

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
718
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
719
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
720
$dbi->execute($CREATE_TABLE->{2});
721
$dbi->execute($CREATE_TABLE->{3});
722

            
723
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
724
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
725
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
726
    
727
    if ($table =~ /^table/) {
728
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
729
         push @$infos, $info;
730
    }
731
});
732
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
733
is_deeply($infos, 
734
    [
735
        ['table1', 'key1', 'key1'],
736
        ['table1', 'key2', 'key2'],
737
        ['table2', 'key1', 'key1'],
738
        ['table2', 'key3', 'key3']
739
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
740
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
741
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
742

            
add examples
Yuki Kimoto authored on 2011-01-07
743
test 'limit';
744
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
745
$dbi->execute($CREATE_TABLE->{0});
746
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
747
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
748
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
749
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
750
    limit => sub {
751
        my ($count, $offset) = @_;
752
        
753
        my $s = '';
754
        $s .= "limit $count";
755
        $s .= " offset $offset" if defined $offset;
756
        
757
        return [$s, []];
758
    }
759
);
760
$rows = $dbi->select(
761
  table => 'table1',
762
  where => {key1 => 1},
763
  append => "order by key2 {limit 1 0}"
764
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
765
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
766
$rows = $dbi->select(
767
  table => 'table1',
768
  where => {key1 => 1},
769
  append => "order by key2 {limit 2 1}"
770
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
771
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
772
$rows = $dbi->select(
773
  table => 'table1',
774
  where => {key1 => 1},
775
  append => "order by key2 {limit 1}"
776
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
777
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
778

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
779
test 'connect super';
780
{
781
    package MyDBI;
782
    
783
    use base 'DBIx::Custom';
784
    sub connect {
785
        my $self = shift->SUPER::connect(@_);
786
        
787
        return $self;
788
    }
789
    
790
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
791
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
792
        
793
        return $self;
794
    }
795
}
796

            
797
$dbi = MyDBI->connect($NEW_ARGS->{0});
798
$dbi->execute($CREATE_TABLE->{0});
799
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
800
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
801

            
802
$dbi = MyDBI->new($NEW_ARGS->{0});
cleanup
Yuki Kimoto authored on 2011-01-25
803
$dbi->connect;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
804
$dbi->execute($CREATE_TABLE->{0});
805
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
cleanup
Yuki Kimoto authored on 2011-01-23
806
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
807

            
cleanup
Yuki Kimoto authored on 2011-01-25
808
{
809
    package MyDBI2;
810
    
811
    use base 'DBIx::Custom';
812
    sub connect {
813
        my $self = shift->SUPER::new(@_);
814
        $self->connect;
815
        
816
        return $self;
817
    }
818
}
819

            
820
$dbi = MyDBI->connect($NEW_ARGS->{0});
821
$dbi->execute($CREATE_TABLE->{0});
822
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
823
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
824

            
825
test 'end_filter';
826
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
827
$dbi->execute($CREATE_TABLE->{0});
828
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
829
$result = $dbi->select(table => 'table1');
830
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
831
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
832
$row = $result->fetch_first;
833
is_deeply($row, [6, 40]);
834

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
835
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
836
$dbi->execute($CREATE_TABLE->{0});
837
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
838
$result = $dbi->select(table => 'table1');
839
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
840
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
841
$row = $result->fetch_first;
842
is_deeply($row, [6, 12]);
843

            
844
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
845
$dbi->execute($CREATE_TABLE->{0});
846
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
847
$result = $dbi->select(table => 'table1');
848
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
849
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
850
$row = $result->fetch_first;
851
is_deeply($row, [6, 12]);
852

            
many changed
Yuki Kimoto authored on 2011-01-23
853
$dbi->register_filter(five_times => sub { $_[0] * 5 });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
854
$result = $dbi->select(table => 'table1');
855
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
many changed
Yuki Kimoto authored on 2011-01-23
856
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
857
$row = $result->fetch_hash_first;
858
is_deeply($row, {key1 => 6, key2 => 40});
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
859

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
860
$dbi->register_filter(five_times => sub { $_[0] * 5 });
861
$dbi->apply_filter('table1',
862
    key1 => {end => sub { $_[0] * 3 } },
863
    key2 => {end => 'five_times'}
864
);
865
$result = $dbi->select(table => 'table1');
866
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
867
$row = $result->fetch_hash_first;
868
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
869

            
870
$dbi->register_filter(five_times => sub { $_[0] * 5 });
871
$dbi->apply_filter('table1',
872
    key1 => {end => sub { $_[0] * 3 } },
873
    key2 => {end => 'five_times'}
874
);
875
$result = $dbi->select(table => 'table1');
876
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
877
$result->filter(key1 => undef);
878
$result->end_filter(key1 => undef);
879
$row = $result->fetch_hash_first;
880
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
881

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
882
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
883
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
884
$dbi->execute($CREATE_TABLE->{0});
885
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
886
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
887
$row = $result
888
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
889
       ->remove_filter
890
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
891
       ->remove_end_filter
892
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
893
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
894

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
895
test 'empty where select';
896
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
897
$dbi->execute($CREATE_TABLE->{0});
898
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
899
$result = $dbi->select(table => 'table1', where => {});
900
$row = $result->fetch_hash_first;
901
is_deeply($row, {key1 => 1, key2 => 2});
902

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
903
test 'select query option';
904
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
905
$dbi->execute($CREATE_TABLE->{0});
906
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
907
is(ref $query, 'DBIx::Custom::Query');
908
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
909
is(ref $query, 'DBIx::Custom::Query');
910
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
911
is(ref $query, 'DBIx::Custom::Query');
912
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
913
is(ref $query, 'DBIx::Custom::Query');
914

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
915
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
916
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
917
$dbi->execute($CREATE_TABLE->{0});
918
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
919
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
920
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
921
is("$where", "where ( {= key1} and {= key2} )", 'no param');
922

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
927
$result = $dbi->select(
928
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
929
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
930
);
931
$row = $result->fetch_hash_all;
932
is_deeply($row, [{key1 => 1, key2 => 2}]);
933

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
934
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
935
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
936
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
937
$result = $dbi->select(
938
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
939
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
940
);
941
$row = $result->fetch_hash_all;
942
is_deeply($row, [{key1 => 1, key2 => 2}]);
943

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
944
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
945
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
946
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
947
$result = $dbi->select(
948
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
949
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
950
);
951
$row = $result->fetch_hash_all;
952
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
953

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
954
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
955
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
956
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
957
$result = $dbi->select(
958
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
959
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
960
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
961
$row = $result->fetch_hash_all;
962
is_deeply($row, [{key1 => 1, key2 => 2}]);
963

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
964
$where = $dbi->where;
965
$result = $dbi->select(
966
    table => 'table1',
967
    where => $where
968
);
969
$row = $result->fetch_hash_all;
970
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
971

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
972
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
973
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
974
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
975
$result = $dbi->select(
976
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
977
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
978
);
979
};
980
ok($@);
981

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

            
added test
Yuki Kimoto authored on 2011-01-19
985
$where = $dbi->where
986
             ->clause(['or', ('{= key1}') x 2])
987
             ->param({key1 => [1, 3]});
988
$result = $dbi->select(
989
    table => 'table1',
990
    where => $where,
991
);
992
$row = $result->fetch_hash_all;
993
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
994

            
995
$where = $dbi->where
996
             ->clause(['or', ('{= key1}') x 2])
997
             ->param({key1 => [1]});
998
$result = $dbi->select(
999
    table => 'table1',
1000
    where => $where,
1001
);
1002
$row = $result->fetch_hash_all;
1003
is_deeply($row, [{key1 => 1, key2 => 2}]);
1004

            
1005
$where = $dbi->where
1006
             ->clause(['or', ('{= key1}') x 2])
1007
             ->param({key1 => 1});
1008
$result = $dbi->select(
1009
    table => 'table1',
1010
    where => $where,
1011
);
1012
$row = $result->fetch_hash_all;
1013
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1014

            
many changed
Yuki Kimoto authored on 2011-01-23
1015
$where = $dbi->where
1016
             ->clause('{= key1}')
1017
             ->param({key1 => 1});
1018
$result = $dbi->select(
1019
    table => 'table1',
1020
    where => $where,
1021
);
1022
$row = $result->fetch_hash_all;
1023
is_deeply($row, [{key1 => 1, key2 => 2}]);
1024

            
1025
$where = $dbi->where
1026
             ->clause('{= key1} {= key2}')
1027
             ->param({key1 => 1});
1028
eval{$where->to_string};
1029
like($@, qr/one column/);
1030

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1031
$where = $dbi->where
1032
             ->clause('{= key1}')
1033
             ->param([]);
1034
eval{$where->to_string};
1035
like($@, qr/Parameter/);
1036

            
1037
$where = $dbi->where
1038
             ->clause(['or', ('{= key1}') x 3])
1039
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1040
$result = $dbi->select(
1041
    table => 'table1',
1042
    where => $where,
1043
);
1044
$row = $result->fetch_hash_all;
1045
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1046

            
1047
$where = $dbi->where
1048
             ->clause(['or', ('{= key1}') x 3])
1049
             ->param({key1 => [1, $dbi->not_exists, 3]});
1050
$result = $dbi->select(
1051
    table => 'table1',
1052
    where => $where,
1053
);
1054
$row = $result->fetch_hash_all;
1055
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1056

            
1057
$where = $dbi->where
1058
             ->clause(['or', ('{= key1}') x 3])
1059
             ->param({key1 => [1, 3, $dbi->not_exists]});
1060
$result = $dbi->select(
1061
    table => 'table1',
1062
    where => $where,
1063
);
1064
$row = $result->fetch_hash_all;
1065
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1066

            
1067
$where = $dbi->where
1068
             ->clause(['or', ('{= key1}') x 3])
1069
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1070
$result = $dbi->select(
1071
    table => 'table1',
1072
    where => $where,
1073
);
1074
$row = $result->fetch_hash_all;
1075
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1076

            
1077
$where = $dbi->where
1078
             ->clause(['or', ('{= key1}') x 3])
1079
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1080
$result = $dbi->select(
1081
    table => 'table1',
1082
    where => $where,
1083
);
1084
$row = $result->fetch_hash_all;
1085
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1086

            
1087
$where = $dbi->where
1088
             ->clause(['or', ('{= key1}') x 3])
1089
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1090
$result = $dbi->select(
1091
    table => 'table1',
1092
    where => $where,
1093
);
1094
$row = $result->fetch_hash_all;
1095
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1096

            
1097
$where = $dbi->where
1098
             ->clause(['or', ('{= key1}') x 3])
1099
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1100
$result = $dbi->select(
1101
    table => 'table1',
1102
    where => $where,
1103
);
1104
$row = $result->fetch_hash_all;
1105
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1106

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1107
$where = $dbi->where
1108
             ->clause(['or', ('{= key1}') x 3])
1109
             ->param({key1 => []});
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}], 'not_exists');
1116

            
1117
$where = $dbi->where
1118
             ->clause(['and', '{> key1}', '{< key1}' ])
1119
             ->param({key1 => [2, $dbi->not_exists]});
1120
$result = $dbi->select(
1121
    table => 'table1',
1122
    where => $where,
1123
);
1124
$row = $result->fetch_hash_all;
1125
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1126

            
1127
$where = $dbi->where
1128
             ->clause(['and', '{> key1}', '{< key1}' ])
1129
             ->param({key1 => [$dbi->not_exists, 2]});
1130
$result = $dbi->select(
1131
    table => 'table1',
1132
    where => $where,
1133
);
1134
$row = $result->fetch_hash_all;
1135
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1136

            
1137
$where = $dbi->where
1138
             ->clause(['and', '{> key1}', '{< key1}' ])
1139
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1140
$result = $dbi->select(
1141
    table => 'table1',
1142
    where => $where,
1143
);
1144
$row = $result->fetch_hash_all;
1145
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1146

            
1147
$where = $dbi->where
1148
             ->clause(['and', '{> key1}', '{< key1}' ])
1149
             ->param({key1 => [0, 2]});
1150
$result = $dbi->select(
1151
    table => 'table1',
1152
    where => $where,
1153
);
1154
$row = $result->fetch_hash_all;
1155
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1156

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1161
test 'register_tag_processor';
1162
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1163
$dbi->register_tag_processor(
1164
    a => sub { 1 }
1165
);
1166
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1167

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1168
test 'register_tag';
1169
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1170
$dbi->register_tag(
1171
    b => sub { 2 }
1172
);
1173
is($dbi->query_builder->tags->{b}->(), 2);
1174

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1175
test 'table not specify exception';
1176
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1177
eval {$dbi->insert};
1178
like($@, qr/table/);
1179
eval {$dbi->update};
1180
like($@, qr/table/);
1181
eval {$dbi->delete};
1182
like($@, qr/table/);
1183
eval {$dbi->select};
1184
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1185

            
1186

            
1187
test 'more tests';
1188
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1189
eval{$dbi->apply_filter('table', 'column', [])};
1190
like($@, qr/apply_filter/);
1191

            
1192
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1193
like($@, qr/apply_filter/);
1194

            
1195
$dbi->apply_filter(
1196

            
1197
);
1198
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1199
$dbi->execute($CREATE_TABLE->{0});
1200
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1201
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1202
$dbi->apply_filter('table1', 'key2', 
1203
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1204
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1205
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1206

            
1207
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1208
$dbi->execute($CREATE_TABLE->{0});
1209
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1210
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1211
$dbi->apply_filter('table1', 'key2', {});
1212
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1213
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1214

            
1215
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1216
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1217
like($@, qr/not registered/);
1218
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1219
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1220
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1221
is($dbi->one, 1);
1222

            
1223
eval{DBIx::Custom->connect()};
1224
like($@, qr/connect/);
1225

            
1226
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1227
$dbi->execute($CREATE_TABLE->{0});
1228
$dbi->register_filter(twice => sub { $_[0] * 2 });
1229
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1230
             filter => {key1 => 'twice'});
1231
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1232
is_deeply($row, {key1 => 2, key2 => 2});
1233
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1234
             filter => {key1 => 'no'}) };
1235
like($@, qr//);
1236

            
1237
$dbi->register_filter(one => sub { });
1238
$dbi->default_fetch_filter('one');
1239
ok($dbi->default_fetch_filter);
1240
$dbi->default_bind_filter('one');
1241
ok($dbi->default_bind_filter);
1242
eval{$dbi->default_fetch_filter('no')};
1243
like($@, qr/not registered/);
1244
eval{$dbi->default_bind_filter('no')};
1245
like($@, qr/not registered/);
1246
$dbi->default_bind_filter(undef);
1247
ok(!defined $dbi->default_bind_filter);
1248
$dbi->default_fetch_filter(undef);
1249
ok(!defined $dbi->default_fetch_filter);
1250
eval {$dbi->execute('select * from table1 {= author') };
1251
like($@, qr/Tag not finished/);
1252

            
1253
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1254
$dbi->execute($CREATE_TABLE->{0});
1255
$dbi->register_filter(one => sub { 1 });
1256
$result = $dbi->select(table => 'table1');
1257
eval {$result->filter(key1 => 'no')};
1258
like($@, qr/not registered/);
1259
eval {$result->end_filter(key1 => 'no')};
1260
like($@, qr/not registered/);
1261
$result->default_filter(undef);
1262
ok(!defined $result->default_filter);
1263
$result->default_filter('one');
1264
is($result->default_filter->(), 1);
1265

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1266
test 'dbi_option';
1267
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1268
                             dbi_option => {PrintError => 1});
1269
ok($dbi->dbh->{PrintError});
1270
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1271
                             dbi_options => {PrintError => 1});
1272
ok($dbi->dbh->{PrintError});
1273

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1274
test 'DBIx::Custom::Result stash()';
1275
$result = DBIx::Custom::Result->new;
1276
is_deeply($result->stash, {}, 'default');
1277
$result->stash->{foo} = 1;
1278
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1279

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1280
test 'filter __ expression';
1281
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1282
$dbi->execute('create table company (id, name, location_id)');
1283
$dbi->execute('create table location (id, name)');
1284
$dbi->apply_filter('location',
1285
  name => {in => sub { uc $_[0] } }
1286
);
1287

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

            
1291
$result = $dbi->select(
1292
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1293
    column => ['location.name as location__name']
1294
);
1295
is($result->fetch_first->[0], 'B');
1296

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1297
$result = $dbi->select(
1298
    table => 'company', relation => {'company.location_id' => 'location.id'},
1299
    column => ['location.name as location__name']
1300
);
1301
is($result->fetch_first->[0], 'B');
1302

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1303
test 'selection';
1304
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1305
$dbi->execute($CREATE_TABLE->{0});
1306
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1307
$result = $dbi->select(selection => '* from {table table1}', where => {key1 => 1});
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1308
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]);
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1309

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1310
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1311
use MyDBI1;
1312
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1313
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1314
$model = $dbi->model('book');
1315
$model->insert({title => 'a', author => 'b'});
1316
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1317
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1318
$model = $dbi->model('company');
1319
$model->insert({name => 'a'});
1320
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1321
is($dbi->models->{'book'}, $dbi->model('book'));
1322
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1323

            
1324
{
1325
    package MyDBI4;
1326

            
1327
    use strict;
1328
    use warnings;
1329

            
1330
    use base 'DBIx::Custom';
1331

            
1332
    sub connect {
1333
        my $self = shift->SUPER::connect(@_);
1334
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1335
        $self->include_model(
1336
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1337
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1338
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1339
            ]
1340
        );
1341
    }
1342

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

            
1345
    use strict;
1346
    use warnings;
1347

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

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

            
1352
    use strict;
1353
    use warnings;
1354

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

            
1357
    sub insert {
1358
        my ($self, $param) = @_;
1359
        
1360
        return $self->SUPER::insert(param => $param);
1361
    }
1362

            
1363
    sub list { shift->select; }
1364

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

            
1367
    use strict;
1368
    use warnings;
1369

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

            
1372
    sub insert {
1373
        my ($self, $param) = @_;
1374
        
1375
        return $self->SUPER::insert(param => $param);
1376
    }
1377

            
1378
    sub list { shift->select; }
1379
}
1380
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1381
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1382
$model = $dbi->model('book');
1383
$model->insert({title => 'a', author => 'b'});
1384
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1385
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1386
$model = $dbi->model('company');
1387
$model->insert({name => 'a'});
1388
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1389

            
1390
{
1391
     package MyDBI5;
1392

            
1393
    use strict;
1394
    use warnings;
1395

            
1396
    use base 'DBIx::Custom';
1397

            
1398
    sub connect {
1399
        my $self = shift->SUPER::connect(@_);
1400
        
1401
        $self->include_model('MyModel4');
1402
    }
1403
}
1404
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1405
$dbi->execute("create table company (name)");
1406
$model = $dbi->model('company');
1407
$model->insert({name => 'a'});
1408
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1409
$model = $dbi->model('book');
1410
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1411

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1412
test 'primary_key';
1413
use MyDBI1;
1414
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1415
$model = $dbi->model('book');
1416
$model->primary_key(['id', 'number']);
1417
is_deeply($model->primary_key, ['id', 'number']);
1418

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1419
test 'columns';
1420
use MyDBI1;
1421
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1422
$model = $dbi->model('book');
1423
$model->columns(['id', 'number']);
1424
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1425

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1426
test 'setup_model';
1427
use MyDBI1;
1428
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1429
$dbi->execute('create table book (id)');
1430
$dbi->execute('create table company (id, name);');
1431
$dbi->execute('create table test (id, name, primary key (id, name));');
1432
$dbi->setup_model;
1433
is_deeply($dbi->model('book')->columns, ['id']);
1434
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1435

            
1436
test 'delete_at';
1437
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1438
$dbi->execute($CREATE_TABLE->{1});
1439
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1440
$dbi->delete_at(
1441
    table => 'table1',
1442
    primary_key => ['key1', 'key2'],
1443
    where => [1, 2],
1444
);
1445
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1446

            
1447
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1448
$dbi->delete_at(
1449
    table => 'table1',
1450
    primary_key => 'key1',
1451
    where => 1,
1452
);
1453
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1454

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1455
test 'insert_at';
1456
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1457
$dbi->execute($CREATE_TABLE->{1});
1458
$dbi->insert_at(
1459
    primary_key => ['key1', 'key2'], 
1460
    table => 'table1',
1461
    where => [1, 2],
1462
    param => {key3 => 3}
1463
);
1464
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1465
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1466
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1467

            
1468
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1469
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1470
$dbi->insert_at(
1471
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1472
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1473
    where => 1,
1474
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1475
);
1476

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1477
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1478
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1479
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1480

            
1481
eval {
1482
    $dbi->insert_at(
1483
        table => 'table1',
1484
        primary_key => ['key1', 'key2'],
1485
        where => {},
1486
        param => {key1 => 1, key2 => 2, key3 => 3},
1487
    );
1488
};
1489
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1490

            
1491
test 'update_at';
1492
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1493
$dbi->execute($CREATE_TABLE->{1});
1494
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1495
$dbi->update_at(
1496
    table => 'table1',
1497
    primary_key => ['key1', 'key2'],
1498
    where => [1, 2],
1499
    param => {key3 => 4}
1500
);
1501
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1502
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1503
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1504

            
1505
$dbi->delete_all(table => 'table1');
1506
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1507
$dbi->update_at(
1508
    table => 'table1',
1509
    primary_key => 'key1',
1510
    where => 1,
1511
    param => {key3 => 4}
1512
);
1513
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1514
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1515
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1516

            
1517
test 'select_at';
1518
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1519
$dbi->execute($CREATE_TABLE->{1});
1520
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1521
$result = $dbi->select_at(
1522
    table => 'table1',
1523
    primary_key => ['key1', 'key2'],
1524
    where => [1, 2]
1525
);
1526
$row = $result->fetch_hash_first;
1527
is($row->{key1}, 1);
1528
is($row->{key2}, 2);
1529
is($row->{key3}, 3);
1530

            
1531
$dbi->delete_all(table => 'table1');
1532
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1533
$result = $dbi->select_at(
1534
    table => 'table1',
1535
    primary_key => 'key1',
1536
    where => 1,
1537
);
1538
$row = $result->fetch_hash_first;
1539
is($row->{key1}, 1);
1540
is($row->{key2}, 2);
1541
is($row->{key3}, 3);
1542

            
1543
$dbi->delete_all(table => 'table1');
1544
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1545
$result = $dbi->select_at(
1546
    table => 'table1',
1547
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1548
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1549
);
1550
$row = $result->fetch_hash_first;
1551
is($row->{key1}, 1);
1552
is($row->{key2}, 2);
1553
is($row->{key3}, 3);
1554

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1555
eval {
1556
    $result = $dbi->select_at(
1557
        table => 'table1',
1558
        primary_key => ['key1', 'key2'],
1559
        where => {},
1560
    );
1561
};
1562
like($@, qr/must be/);
1563

            
1564
eval {
1565
    $result = $dbi->update_at(
1566
        table => 'table1',
1567
        primary_key => ['key1', 'key2'],
1568
        where => {},
1569
        param => {key1 => 1, key2 => 2},
1570
    );
1571
};
1572
like($@, qr/must be/);
1573

            
1574
eval {
1575
    $result = $dbi->delete_at(
1576
        table => 'table1',
1577
        primary_key => ['key1', 'key2'],
1578
        where => {},
1579
    );
1580
};
1581
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1582

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1583
test 'columns';
1584
use MyDBI1;
1585
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1586
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1587

            
1588

            
1589
test 'model delete_at';
1590
{
1591
    package MyDBI6;
1592
    
1593
    use base 'DBIx::Custom';
1594
    
1595
    sub connect {
1596
        my $self = shift->SUPER::connect(@_);
1597
        
1598
        $self->include_model('MyModel5');
1599
        
1600
        return $self;
1601
    }
1602
}
1603
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1604
$dbi->execute($CREATE_TABLE->{1});
1605
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1606
$dbi->model('table1')->delete_at(where => [1, 2]);
1607
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1608
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1609
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1610
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1611
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1612
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1613
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1614

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1615
test 'model insert_at';
1616
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1617
$dbi->execute($CREATE_TABLE->{1});
1618
$dbi->model('table1')->insert_at(
1619
    where => [1, 2],
1620
    param => {key3 => 3}
1621
);
1622
$result = $dbi->model('table1')->select;
1623
$row = $result->fetch_hash_first;
1624
is($row->{key1}, 1);
1625
is($row->{key2}, 2);
1626
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1627

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1628
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1629
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1630
$dbi->execute($CREATE_TABLE->{1});
1631
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1632
$dbi->model('table1')->update_at(
1633
    where => [1, 2],
1634
    param => {key3 => 4}
1635
);
1636
$result = $dbi->model('table1')->select;
1637
$row = $result->fetch_hash_first;
1638
is($row->{key1}, 1);
1639
is($row->{key2}, 2);
1640
is($row->{key3}, 4);
1641

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1642
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1643
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1644
$dbi->execute($CREATE_TABLE->{1});
1645
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1646
$result = $dbi->model('table1')->select_at(where => [1, 2]);
1647
$row = $result->fetch_hash_first;
1648
is($row->{key1}, 1);
1649
is($row->{key2}, 2);
1650
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1651

            
1652

            
cleanup
Yuki Kimoto authored on 2011-03-21
1653
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1654
{
1655
    package MyDBI7;
1656
    
1657
    use base 'DBIx::Custom';
1658
    
1659
    sub connect {
1660
        my $self = shift->SUPER::connect(@_);
1661
        
1662
        $self->include_model('MyModel6');
1663
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1664
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1665
        return $self;
1666
    }
1667
}
1668
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1669
$dbi->execute($CREATE_TABLE->{0});
1670
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1671
$dbi->setup_model;
1672
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1673
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1674
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1675
$result = $model->select(
1676
    column => [$model->mycolumn, $model->column('table2')],
1677
    where => {'table1.key1' => 1}
1678
);
1679
is_deeply($result->fetch_hash_first,
1680
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1681

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1682
test 'update_param';
1683
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1684
$dbi->execute($CREATE_TABLE->{1});
1685
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1686
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1687

            
1688
$param = {key2 => 11};
1689
$update_param = $dbi->update_param($param);
1690
$sql = <<"EOS";
1691
update {table table1} $update_param
1692
where key1 = 1
1693
EOS
1694
$dbi->execute($sql, param => $param);
1695
$result = $dbi->execute($SELECT_SOURCES->{0});
1696
$rows   = $result->fetch_hash_all;
1697
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1698
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1699
                  "basic");
1700

            
1701

            
1702
eval { $dbi->update_param({";" => 1}) };
1703
like($@, qr/not safety/);
1704

            
1705

            
1706
test 'insert_param';
1707
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1708
$dbi->execute($CREATE_TABLE->{1});
1709
$param = {key1 => 1};
1710
$insert_param = $dbi->insert_param($param);
1711
$sql = <<"EOS";
1712
insert into {table table1} $insert_param
1713
EOS
1714

            
1715
$dbi->execute($sql, param => $param);
1716
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1717

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1718
eval { $dbi->insert_param({";" => 1}) };
1719
like($@, qr/not safety/);
cleanup
Yuki Kimoto authored on 2011-03-08
1720

            
1721

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1722
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1723
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1724
$dbi->execute($CREATE_TABLE->{0});
1725
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1726
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1727
$dbi->execute($CREATE_TABLE->{2});
1728
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1729
$dbi->execute($CREATE_TABLE->{4});
1730
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1731
$rows = $dbi->select(
1732
    table => 'table1',
1733
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1734
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1735
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1736
)->fetch_hash_all;
1737
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1738

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1739
$rows = $dbi->select(
1740
    table => 'table1',
1741
    where   => {'key1' => 1},
1742
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1743
)->fetch_hash_all;
1744
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1745

            
cleanup
Yuki Kimoto authored on 2011-03-08
1746
eval {
1747
    $rows = $dbi->select(
1748
        table => 'table1',
1749
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1750
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1751
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1752
    );
1753
};
1754
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1755

            
1756
$rows = $dbi->select(
1757
    table => 'table1',
1758
    where   => {'key1' => 1},
1759
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1760
              'left outer join table3 on table2.key3 = table3.key3']
1761
)->fetch_hash_all;
1762
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1763

            
1764
$rows = $dbi->select(
1765
    column => 'table3.key4 as table3__key4',
1766
    table => 'table1',
1767
    where   => {'table1.key1' => 1},
1768
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1769
              'left outer join table3 on table2.key3 = table3.key3']
1770
)->fetch_hash_all;
1771
is_deeply($rows, [{table3__key4 => 4}]);
1772

            
1773
$rows = $dbi->select(
1774
    column => 'table1.key1 as table1__key1',
1775
    table => 'table1',
1776
    where   => {'table3.key4' => 4},
1777
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1778
              'left outer join table3 on table2.key3 = table3.key3']
1779
)->fetch_hash_all;
1780
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1781

            
1782

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1783
test 'model join and column attribute and all_column option';
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1784
{
1785
    package MyDBI8;
1786
    
1787
    use base 'DBIx::Custom';
1788
    
1789
    sub connect {
1790
        my $self = shift->SUPER::connect(@_);
1791
        
1792
        $self->include_model('MyModel7');
1793
        
1794
        return $self;
1795
    }
1796
}
1797
$dbi = MyDBI8->connect($NEW_ARGS->{0});
1798
$dbi->execute($CREATE_TABLE->{0});
1799
$dbi->execute($CREATE_TABLE->{2});
1800
$dbi->setup_model;
1801
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1802
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1803
$model = $dbi->model('table1');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1804
$result = $model->select_at(
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1805
    column => {table => ['table1', 'table2'], prepend => 'table1.key1 as key1_1,'},
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1806
    where => 1
1807
);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1808
is_deeply($result->fetch_hash_first,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1809
          {key1_1 => 1, key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1810
$result = $model->select(column => {all => 1});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1811
is_deeply($result->fetch_hash_first,
1812
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1813

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1814
test 'mycolumn';
1815
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1816
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1817
$dbi->execute($CREATE_TABLE->{2});
1818
$dbi->setup_model;
1819
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1820
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1821
$model = $dbi->model('table1');
1822
$result = $model->select_at(
1823
    column => [
1824
        $model->mycolumn,
1825
        $model->column('table2')
1826
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1827
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1828
is_deeply($result->fetch_hash_first,
1829
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1830
$result = $model->select_at(
1831
    column => [
1832
        $model->mycolumn(['key1']),
1833
        $model->column(table2 => ['key1'])
1834
    ]
1835
);
1836
is_deeply($result->fetch_hash_first,
1837
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1838

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1839
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1840
{
1841
    package MyDBI9;
1842
    
1843
    use base 'DBIx::Custom';
1844
    
1845
    sub connect {
1846
        my $self = shift->SUPER::connect(@_);
1847
        
1848
        $self->include_model('MyModel8')->setup_model;
1849
        
1850
        return $self;
1851
    }
1852
}
1853
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1854
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1855
$model = $dbi->model('table1');
1856
eval{$model->execute('select * from table1')};
1857
ok(!$@);
1858

            
1859
test 'table_alias';
1860
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1861
$dbi->execute($CREATE_TABLE->{0});
1862
$dbi->execute($CREATE_TABLE->{2});
1863
$dbi->setup_model;
1864
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
1865
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
1866
$model = $dbi->model('table1');
1867
$result = $model->select(
1868
    column => [
1869
        $model->column('table2_alias')
1870
    ],
1871
    where => {'table2_alias.key3' => 2}
1872
);
1873
is_deeply($result->fetch_hash_first, 
1874
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
1875