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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
248
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
249
$dbi->reserved_word_quote('"');
250
$dbi->execute('create table "table" ("select")');
251
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
252
$dbi->insert(table => 'table', param => {select => 1});
253
$result = $dbi->execute('select * from "table"');
254
$rows   = $result->fetch_hash_all;
255
is_deeply($rows, [{select => 2}], "reserved word");
256

            
removed register_format()
yuki-kimoto authored on 2010-05-26
257
test 'update';
258
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
259
$dbi->execute($CREATE_TABLE->{1});
260
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
261
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
262
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
263
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
264
$rows   = $result->fetch_hash_all;
265
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
266
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
267
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
268
                  
269
$dbi->execute("delete from table1");
270
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
271
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
272
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
273
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
274
$rows   = $result->fetch_hash_all;
275
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
276
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
277
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
278

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
286
$dbi->execute("delete from table1");
287
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
288
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
289
$dbi->register_filter(twice => sub { $_[0] * 2 });
290
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
291
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
292
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
293
$rows   = $result->fetch_hash_all;
294
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
295
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
296
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
297

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
306
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
307
$dbi->execute($CREATE_TABLE->{0});
308
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
309
$where = $dbi->where;
310
$where->clause(['and', '{= key1}', '{= key2}']);
311
$where->param({key1 => 1, key2 => 2});
312
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
313
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
314
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
315

            
316
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
317
$dbi->execute($CREATE_TABLE->{0});
318
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
319
$dbi->update(
320
    table => 'table1',
321
    param => {key1 => 3},
322
    where => [
323
        ['and', '{= key1}', '{= key2}'],
324
        {key1 => 1, key2 => 2}
325
    ]
326
);
327
$result = $dbi->select(table => 'table1');
328
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
329

            
330
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
331
$dbi->execute($CREATE_TABLE->{0});
332
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
333
$where = $dbi->where;
334
$where->clause(['and', '{= key2}']);
335
$where->param({key2 => 2});
336
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
337
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
338
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
339

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
346
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
347
$dbi->reserved_word_quote('"');
348
$dbi->execute('create table "table" ("select", "update")');
349
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
350
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
351
$dbi->insert(table => 'table', param => {select => 1});
352
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
353
$result = $dbi->execute('select * from "table"');
354
$rows   = $result->fetch_hash_all;
355
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
356

            
357
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
358
like($@, qr/safety/);
359

            
360
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
361
$dbi->reserved_word_quote('"');
362
$dbi->execute('create table "table" ("select", "update")');
363
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
364
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
365
$dbi->insert(table => 'table', param => {select => 1});
366
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
367
$result = $dbi->execute('select * from "table"');
368
$rows   = $result->fetch_hash_all;
369
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
370

            
removed register_format()
yuki-kimoto authored on 2010-05-26
371
test 'update_all';
372
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
373
$dbi->execute($CREATE_TABLE->{1});
374
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
375
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
376
$dbi->register_filter(twice => sub { $_[0] * 2 });
377
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
378
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
379
$rows   = $result->fetch_hash_all;
380
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
381
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
382
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
383

            
384

            
385
test 'delete';
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(table => 'table1', where => {key1 => 1});
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, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
394

            
395
$dbi->execute("delete from table1;");
396
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
397
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
398
$dbi->register_filter(twice => sub { $_[0] * 2 });
399
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
400
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
401
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
402
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
403

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

            
406
$dbi->delete_all(table => 'table1');
407
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
408
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
409
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
410
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
411
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
412

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
416
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
417
$dbi->execute($CREATE_TABLE->{0});
418
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
419
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
420
$where = $dbi->where;
421
$where->clause(['and', '{= key1}', '{= key2}']);
422
$where->param({ke1 => 1, key2 => 2});
423
$dbi->delete(table => 'table1', where => $where);
424
$result = $dbi->select(table => 'table1');
425
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
426

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
427
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
428
$dbi->execute($CREATE_TABLE->{0});
429
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
430
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
431
$dbi->delete(
432
    table => 'table1',
433
    where => [
434
        ['and', '{= key1}', '{= key2}'],
435
        {ke1 => 1, key2 => 2}
436
    ]
437
);
438
$result = $dbi->select(table => 'table1');
439
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
440

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
451
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
452
$dbi->reserved_word_quote('"');
453
$dbi->execute('create table "table" ("select", "update")');
454
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
455
$dbi->insert(table => 'table', param => {select => 1});
456
$dbi->delete(table => 'table', where => {select => 1});
457
$result = $dbi->execute('select * from "table"');
458
$rows   = $result->fetch_hash_all;
459
is_deeply($rows, [], "reserved word");
460

            
removed register_format()
yuki-kimoto authored on 2010-05-26
461
test 'delete_all';
462
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
463
$dbi->execute($CREATE_TABLE->{0});
464
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
465
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
466
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
467
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
468
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
469
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
470

            
471

            
472
test 'select';
473
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
474
$dbi->execute($CREATE_TABLE->{0});
475
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
476
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
477
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
478
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
479
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
480

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

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

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

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

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

            
498
$dbi->execute($CREATE_TABLE->{2});
499
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
500
$rows = $dbi->select(
501
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
502
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
503
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
504
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
505
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
506
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
507

            
508
$rows = $dbi->select(
509
    table => [qw/table1 table2/],
510
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
511
    relation  => {'table1.key1' => 'table2.key1'}
512
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
513
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
514

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
518
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
519
$dbi->reserved_word_quote('"');
520
$dbi->execute('create table "table" ("select", "update")');
521
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
522
$dbi->insert(table => 'table', param => {select => 1, update => 2});
523
$result = $dbi->select(table => 'table', where => {select => 1});
524
$rows   = $result->fetch_hash_all;
525
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
526

            
removed register_format()
yuki-kimoto authored on 2010-05-26
527
test 'fetch filter';
528
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
529
$dbi->register_filter(
530
    twice       => sub { $_[0] * 2 },
531
    three_times => sub { $_[0] * 3 }
532
);
533
$dbi->default_fetch_filter('twice');
534
$dbi->execute($CREATE_TABLE->{0});
535
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
536
$result = $dbi->select(table => 'table1');
537
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
538
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
539
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
540

            
541
test 'filters';
542
$dbi = DBIx::Custom->new;
543

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
550
test 'transaction';
551
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
552
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
553
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
554
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
555
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
556
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
557
$result = $dbi->select(table => 'table1');
558
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
559
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
560

            
561
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
562
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
563
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
564
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
565
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
566

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

            
570
test 'cache';
571
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
572
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
573
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
574
$source = 'select * from table1 where {= key1} and {= key2};';
575
$dbi->create_query($source);
576
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
577
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
578

            
579
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
580
$dbi->execute($CREATE_TABLE->{0});
581
$dbi->{_cached} = {};
582
$dbi->cache(0);
583
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
584
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
585

            
add tests
yuki-kimoto authored on 2010-08-10
586
test 'execute';
587
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
588
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
589
{
590
    local $Carp::Verbose = 0;
591
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
592
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
593
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
594
}
595
{
596
    local $Carp::Verbose = 1;
597
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
598
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
599
}
add tests
yuki-kimoto authored on 2010-08-10
600

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
609
{
610
    local $Carp::Verbose = 0;
611
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
612
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
613
}
614
{
615
    local $Carp::Verbose = 1;
616
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
617
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
618
}
cleanup
yuki-kimoto authored on 2010-10-17
619

            
620

            
621
test 'transaction';
622
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
623
$dbi->execute($CREATE_TABLE->{0});
624

            
625
$dbi->begin_work;
626

            
627
eval {
628
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
629
    die "Error";
630
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
631
};
632

            
633
$dbi->rollback if $@;
634

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

            
639
$dbi->begin_work;
640

            
641
eval {
642
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
643
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
644
};
645

            
646
$dbi->commit unless $@;
647

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

            
652
$dbi->dbh->{AutoCommit} = 0;
653
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
654
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
655
$dbi->dbh->{AutoCommit} = 1;
656

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
658
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
659
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
660
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
661
    one => sub { 1 }
662
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
663
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
664
    two => sub { 2 }
665
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
666
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
667
    twice => sub {
668
        my $self = shift;
669
        return $_[0] * 2;
670
    }
671
});
672

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
680
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
681
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
682
$dbi->execute($CREATE_TABLE->{0});
683
$dbi->register_filter(twice => sub { $_[0] * 2 });
684
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
685
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
686
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
687
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
688
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
689
$result = $dbi->execute($SELECT_SOURCES->{0});
690
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
691
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
692
$result = $dbi->select(table => 'table1');
693
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
694
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
695

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
696
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
697
$dbi->execute($CREATE_TABLE->{0});
698
$dbi->register_filter(twice => sub { $_[0] * 2 });
699
$dbi->register_filter(three_times => sub { $_[0] * 3});
700
$dbi->apply_filter(
701
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
702
              'key2' => {out => 'three_times', in => 'twice'});
703
$dbi->apply_filter(
704
    'table1', 'key1' => {out => undef}
705
); 
706
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
707
$result = $dbi->execute($SELECT_SOURCES->{0});
708
$row   = $result->fetch_hash_first;
709
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
710

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
711
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
712
$dbi->execute($CREATE_TABLE->{0});
713
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
714
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
715
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
716
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
717
$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
718
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
719
$result = $dbi->execute($SELECT_SOURCES->{0});
720
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
721
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
722

            
723
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
724
$dbi->execute($CREATE_TABLE->{0});
725
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
726
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
727
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
728
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
729
$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
730
$dbi->delete(table => 'table1', where => {key1 => 1});
731
$result = $dbi->execute($SELECT_SOURCES->{0});
732
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
733
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
734

            
735
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
736
$dbi->execute($CREATE_TABLE->{0});
737
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
738
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
739
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
740
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
741
$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
742
$result = $dbi->select(table => 'table1', where => {key1 => 1});
743
$result->filter({'key2' => 'twice'});
744
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
745
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
746

            
747
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
748
$dbi->execute($CREATE_TABLE->{0});
749
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
750
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
751
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
752
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
753
$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
754
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
755
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
756
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
757
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
758
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
759

            
add table tag
Yuki Kimoto authored on 2011-02-09
760
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
761
$dbi->execute($CREATE_TABLE->{0});
762
$dbi->register_filter(twice => sub { $_[0] * 2 });
763
$dbi->apply_filter(
764
    'table1', 'key1' => {out => 'twice', in => 'twice'}
765
);
766
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
767
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
768
                        param => {key1 => 1, key2 => 2});
769
$rows   = $result->fetch_hash_all;
770
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
771

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
772
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
773
$dbi->execute($CREATE_TABLE->{0});
774
$dbi->execute($CREATE_TABLE->{2});
775
$dbi->register_filter(twice => sub { $_[0] * 2 });
776
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
777
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
778
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
779
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
780
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
781
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
782
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
783
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
784
$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
785
$result = $dbi->select(
786
     table => ['table1', 'table2'],
787
     column => ['key2', 'key3'],
788
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
789

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

            
794
$result = $dbi->select(
795
     table => ['table1', 'table2'],
796
     column => ['key2', 'key3'],
797
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
798

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
803
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
804
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
805
$dbi->execute($CREATE_TABLE->{2});
806
$dbi->execute($CREATE_TABLE->{3});
807

            
808
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
809
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
810
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
811
    
812
    if ($table =~ /^table/) {
813
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
814
         push @$infos, $info;
815
    }
816
});
817
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
818
is_deeply($infos, 
819
    [
820
        ['table1', 'key1', 'key1'],
821
        ['table1', 'key2', 'key2'],
822
        ['table2', 'key1', 'key1'],
823
        ['table2', 'key3', 'key3']
824
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
825
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
826
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
827

            
add examples
Yuki Kimoto authored on 2011-01-07
828
test 'limit';
829
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
830
$dbi->execute($CREATE_TABLE->{0});
831
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
832
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
833
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
834
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
835
    limit => sub {
836
        my ($count, $offset) = @_;
837
        
838
        my $s = '';
839
        $s .= "limit $count";
840
        $s .= " offset $offset" if defined $offset;
841
        
842
        return [$s, []];
843
    }
844
);
845
$rows = $dbi->select(
846
  table => 'table1',
847
  where => {key1 => 1},
848
  append => "order by key2 {limit 1 0}"
849
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
850
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
851
$rows = $dbi->select(
852
  table => 'table1',
853
  where => {key1 => 1},
854
  append => "order by key2 {limit 2 1}"
855
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
856
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
857
$rows = $dbi->select(
858
  table => 'table1',
859
  where => {key1 => 1},
860
  append => "order by key2 {limit 1}"
861
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
862
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
863

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
864
test 'connect super';
865
{
866
    package MyDBI;
867
    
868
    use base 'DBIx::Custom';
869
    sub connect {
870
        my $self = shift->SUPER::connect(@_);
871
        
872
        return $self;
873
    }
874
    
875
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
876
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
877
        
878
        return $self;
879
    }
880
}
881

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
893
{
894
    package MyDBI2;
895
    
896
    use base 'DBIx::Custom';
897
    sub connect {
898
        my $self = shift->SUPER::new(@_);
899
        $self->connect;
900
        
901
        return $self;
902
    }
903
}
904

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

            
910
test 'end_filter';
911
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
912
$dbi->execute($CREATE_TABLE->{0});
913
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
914
$result = $dbi->select(table => 'table1');
915
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
916
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
917
$row = $result->fetch_first;
918
is_deeply($row, [6, 40]);
919

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
920
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
921
$dbi->execute($CREATE_TABLE->{0});
922
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
923
$result = $dbi->select(table => 'table1');
924
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
925
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
926
$row = $result->fetch_first;
927
is_deeply($row, [6, 12]);
928

            
929
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
930
$dbi->execute($CREATE_TABLE->{0});
931
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
932
$result = $dbi->select(table => 'table1');
933
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
934
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
935
$row = $result->fetch_first;
936
is_deeply($row, [6, 12]);
937

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
945
$dbi->register_filter(five_times => sub { $_[0] * 5 });
946
$dbi->apply_filter('table1',
947
    key1 => {end => sub { $_[0] * 3 } },
948
    key2 => {end => 'five_times'}
949
);
950
$result = $dbi->select(table => 'table1');
951
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
952
$row = $result->fetch_hash_first;
953
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
954

            
955
$dbi->register_filter(five_times => sub { $_[0] * 5 });
956
$dbi->apply_filter('table1',
957
    key1 => {end => sub { $_[0] * 3 } },
958
    key2 => {end => 'five_times'}
959
);
960
$result = $dbi->select(table => 'table1');
961
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
962
$result->filter(key1 => undef);
963
$result->end_filter(key1 => undef);
964
$row = $result->fetch_hash_first;
965
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
966

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
967
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
968
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
969
$dbi->execute($CREATE_TABLE->{0});
970
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
971
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
972
$row = $result
973
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
974
       ->remove_filter
975
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
976
       ->remove_end_filter
977
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
978
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
979

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
980
test 'empty where select';
981
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
982
$dbi->execute($CREATE_TABLE->{0});
983
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
984
$result = $dbi->select(table => 'table1', where => {});
985
$row = $result->fetch_hash_first;
986
is_deeply($row, {key1 => 1, key2 => 2});
987

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
988
test 'select query option';
989
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
990
$dbi->execute($CREATE_TABLE->{0});
991
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
992
is(ref $query, 'DBIx::Custom::Query');
993
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
994
is(ref $query, 'DBIx::Custom::Query');
995
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
996
is(ref $query, 'DBIx::Custom::Query');
997
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
998
is(ref $query, 'DBIx::Custom::Query');
999

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1000
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1001
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1002
$dbi->execute($CREATE_TABLE->{0});
1003
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1004
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1005
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
1006
is("$where", "where ( {= key1} and {= key2} )", 'no param');
1007

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1012
$result = $dbi->select(
1013
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1014
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1015
);
1016
$row = $result->fetch_hash_all;
1017
is_deeply($row, [{key1 => 1, key2 => 2}]);
1018

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1019
$result = $dbi->select(
1020
    table => 'table1',
1021
    where => [
1022
        ['and', '{= key1}', '{= key2}'],
1023
        {key1 => 1}
1024
    ]
1025
);
1026
$row = $result->fetch_hash_all;
1027
is_deeply($row, [{key1 => 1, key2 => 2}]);
1028

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1029
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1030
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1031
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1032
$result = $dbi->select(
1033
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1034
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1035
);
1036
$row = $result->fetch_hash_all;
1037
is_deeply($row, [{key1 => 1, key2 => 2}]);
1038

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1039
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1040
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1041
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1042
$result = $dbi->select(
1043
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1044
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1045
);
1046
$row = $result->fetch_hash_all;
1047
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1048

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1049
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1050
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1051
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1052
$result = $dbi->select(
1053
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1054
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1055
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1056
$row = $result->fetch_hash_all;
1057
is_deeply($row, [{key1 => 1, key2 => 2}]);
1058

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1059
$where = $dbi->where;
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}]);
1066

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1067
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1068
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1069
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1070
$result = $dbi->select(
1071
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1072
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1073
);
1074
};
1075
ok($@);
1076

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

            
added test
Yuki Kimoto authored on 2011-01-19
1080
$where = $dbi->where
1081
             ->clause(['or', ('{= key1}') x 2])
1082
             ->param({key1 => [1, 3]});
1083
$result = $dbi->select(
1084
    table => 'table1',
1085
    where => $where,
1086
);
1087
$row = $result->fetch_hash_all;
1088
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1089

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

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

            
many changed
Yuki Kimoto authored on 2011-01-23
1110
$where = $dbi->where
1111
             ->clause('{= key1}')
1112
             ->param({key1 => 1});
1113
$result = $dbi->select(
1114
    table => 'table1',
1115
    where => $where,
1116
);
1117
$row = $result->fetch_hash_all;
1118
is_deeply($row, [{key1 => 1, key2 => 2}]);
1119

            
1120
$where = $dbi->where
1121
             ->clause('{= key1} {= key2}')
1122
             ->param({key1 => 1});
1123
eval{$where->to_string};
1124
like($@, qr/one column/);
1125

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1126
$where = $dbi->where
1127
             ->clause('{= key1}')
1128
             ->param([]);
1129
eval{$where->to_string};
1130
like($@, qr/Parameter/);
1131

            
1132
$where = $dbi->where
1133
             ->clause(['or', ('{= key1}') x 3])
1134
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1135
$result = $dbi->select(
1136
    table => 'table1',
1137
    where => $where,
1138
);
1139
$row = $result->fetch_hash_all;
1140
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1141

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

            
1152
$where = $dbi->where
1153
             ->clause(['or', ('{= key1}') x 3])
1154
             ->param({key1 => [1, 3, $dbi->not_exists]});
1155
$result = $dbi->select(
1156
    table => 'table1',
1157
    where => $where,
1158
);
1159
$row = $result->fetch_hash_all;
1160
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1161

            
1162
$where = $dbi->where
1163
             ->clause(['or', ('{= key1}') x 3])
1164
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1165
$result = $dbi->select(
1166
    table => 'table1',
1167
    where => $where,
1168
);
1169
$row = $result->fetch_hash_all;
1170
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1171

            
1172
$where = $dbi->where
1173
             ->clause(['or', ('{= key1}') x 3])
1174
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1175
$result = $dbi->select(
1176
    table => 'table1',
1177
    where => $where,
1178
);
1179
$row = $result->fetch_hash_all;
1180
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1181

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

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

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1202
$where = $dbi->where
1203
             ->clause(['or', ('{= key1}') x 3])
1204
             ->param({key1 => []});
1205
$result = $dbi->select(
1206
    table => 'table1',
1207
    where => $where,
1208
);
1209
$row = $result->fetch_hash_all;
1210
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1211

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

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

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

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

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1252
$where = $dbi->where
1253
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1254
$result = $dbi->select(
1255
    table => 'table1',
1256
    where => $where,
1257
);
1258
$row = $result->fetch_hash_all;
1259
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1260

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

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1268
test 'register_tag_processor';
1269
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1270
$dbi->register_tag_processor(
1271
    a => sub { 1 }
1272
);
1273
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1274

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1275
test 'register_tag';
1276
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1277
$dbi->register_tag(
1278
    b => sub { 2 }
1279
);
1280
is($dbi->query_builder->tags->{b}->(), 2);
1281

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1282
test 'table not specify exception';
1283
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1284
eval {$dbi->insert};
1285
like($@, qr/table/);
1286
eval {$dbi->update};
1287
like($@, qr/table/);
1288
eval {$dbi->delete};
1289
like($@, qr/table/);
1290
eval {$dbi->select};
1291
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1292

            
1293

            
1294
test 'more tests';
1295
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1296
eval{$dbi->apply_filter('table', 'column', [])};
1297
like($@, qr/apply_filter/);
1298

            
1299
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1300
like($@, qr/apply_filter/);
1301

            
1302
$dbi->apply_filter(
1303

            
1304
);
1305
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1306
$dbi->execute($CREATE_TABLE->{0});
1307
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1308
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1309
$dbi->apply_filter('table1', 'key2', 
1310
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1311
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1312
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1313

            
1314
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1315
$dbi->execute($CREATE_TABLE->{0});
1316
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1317
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1318
$dbi->apply_filter('table1', 'key2', {});
1319
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1320
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1321

            
1322
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1323
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1324
like($@, qr/not registered/);
1325
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1326
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1327
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1328
is($dbi->one, 1);
1329

            
1330
eval{DBIx::Custom->connect()};
improved error messages
Yuki Kimoto authored on 2011-04-18
1331
like($@, qr/dbh/);
many changed
Yuki Kimoto authored on 2011-01-23
1332

            
1333
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1334
$dbi->execute($CREATE_TABLE->{0});
1335
$dbi->register_filter(twice => sub { $_[0] * 2 });
1336
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1337
             filter => {key1 => 'twice'});
1338
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1339
is_deeply($row, {key1 => 2, key2 => 2});
1340
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1341
             filter => {key1 => 'no'}) };
1342
like($@, qr//);
1343

            
1344
$dbi->register_filter(one => sub { });
1345
$dbi->default_fetch_filter('one');
1346
ok($dbi->default_fetch_filter);
1347
$dbi->default_bind_filter('one');
1348
ok($dbi->default_bind_filter);
1349
eval{$dbi->default_fetch_filter('no')};
1350
like($@, qr/not registered/);
1351
eval{$dbi->default_bind_filter('no')};
1352
like($@, qr/not registered/);
1353
$dbi->default_bind_filter(undef);
1354
ok(!defined $dbi->default_bind_filter);
1355
$dbi->default_fetch_filter(undef);
1356
ok(!defined $dbi->default_fetch_filter);
1357
eval {$dbi->execute('select * from table1 {= author') };
1358
like($@, qr/Tag not finished/);
1359

            
1360
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1361
$dbi->execute($CREATE_TABLE->{0});
1362
$dbi->register_filter(one => sub { 1 });
1363
$result = $dbi->select(table => 'table1');
1364
eval {$result->filter(key1 => 'no')};
1365
like($@, qr/not registered/);
1366
eval {$result->end_filter(key1 => 'no')};
1367
like($@, qr/not registered/);
1368
$result->default_filter(undef);
1369
ok(!defined $result->default_filter);
1370
$result->default_filter('one');
1371
is($result->default_filter->(), 1);
1372

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1373
test 'dbi_option';
1374
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1375
                             dbi_option => {PrintError => 1});
1376
ok($dbi->dbh->{PrintError});
1377
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1378
                             dbi_options => {PrintError => 1});
1379
ok($dbi->dbh->{PrintError});
1380

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1381
test 'DBIx::Custom::Result stash()';
1382
$result = DBIx::Custom::Result->new;
1383
is_deeply($result->stash, {}, 'default');
1384
$result->stash->{foo} = 1;
1385
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1386

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1387
test 'filter __ expression';
1388
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1389
$dbi->execute('create table company (id, name, location_id)');
1390
$dbi->execute('create table location (id, name)');
1391
$dbi->apply_filter('location',
1392
  name => {in => sub { uc $_[0] } }
1393
);
1394

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

            
1398
$result = $dbi->select(
1399
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1400
    column => ['location.name as location__name']
1401
);
1402
is($result->fetch_first->[0], 'B');
1403

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1404
$result = $dbi->select(
1405
    table => 'company', relation => {'company.location_id' => 'location.id'},
1406
    column => ['location.name as location__name']
1407
);
1408
is($result->fetch_first->[0], 'B');
1409

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1410
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1411
use MyDBI1;
1412
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1413
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1414
$model = $dbi->model('book');
1415
$model->insert({title => 'a', author => 'b'});
1416
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1417
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1418
$model = $dbi->model('company');
1419
$model->insert({name => 'a'});
1420
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1421
is($dbi->models->{'book'}, $dbi->model('book'));
1422
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1423

            
1424
{
1425
    package MyDBI4;
1426

            
1427
    use strict;
1428
    use warnings;
1429

            
1430
    use base 'DBIx::Custom';
1431

            
1432
    sub connect {
1433
        my $self = shift->SUPER::connect(@_);
1434
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1435
        $self->include_model(
1436
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1437
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1438
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1439
            ]
1440
        );
1441
    }
1442

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

            
1445
    use strict;
1446
    use warnings;
1447

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

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

            
1452
    use strict;
1453
    use warnings;
1454

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

            
1457
    sub insert {
1458
        my ($self, $param) = @_;
1459
        
1460
        return $self->SUPER::insert(param => $param);
1461
    }
1462

            
1463
    sub list { shift->select; }
1464

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

            
1467
    use strict;
1468
    use warnings;
1469

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

            
1472
    sub insert {
1473
        my ($self, $param) = @_;
1474
        
1475
        return $self->SUPER::insert(param => $param);
1476
    }
1477

            
1478
    sub list { shift->select; }
1479
}
1480
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1481
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1482
$model = $dbi->model('book');
1483
$model->insert({title => 'a', author => 'b'});
1484
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1485
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1486
$model = $dbi->model('company');
1487
$model->insert({name => 'a'});
1488
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1489

            
1490
{
1491
     package MyDBI5;
1492

            
1493
    use strict;
1494
    use warnings;
1495

            
1496
    use base 'DBIx::Custom';
1497

            
1498
    sub connect {
1499
        my $self = shift->SUPER::connect(@_);
1500
        
1501
        $self->include_model('MyModel4');
1502
    }
1503
}
1504
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1505
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1506
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1507
$model = $dbi->model('company');
1508
$model->insert({name => 'a'});
1509
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1510
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1511
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1512
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1513

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1514
test 'primary_key';
1515
use MyDBI1;
1516
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1517
$model = $dbi->model('book');
1518
$model->primary_key(['id', 'number']);
1519
is_deeply($model->primary_key, ['id', 'number']);
1520

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1521
test 'columns';
1522
use MyDBI1;
1523
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1524
$model = $dbi->model('book');
1525
$model->columns(['id', 'number']);
1526
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1527

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1528
test 'setup_model';
1529
use MyDBI1;
1530
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1531
$dbi->execute('create table book (id)');
1532
$dbi->execute('create table company (id, name);');
1533
$dbi->execute('create table test (id, name, primary key (id, name));');
1534
$dbi->setup_model;
1535
is_deeply($dbi->model('book')->columns, ['id']);
1536
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1537

            
1538
test 'delete_at';
1539
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1540
$dbi->execute($CREATE_TABLE->{1});
1541
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1542
$dbi->delete_at(
1543
    table => 'table1',
1544
    primary_key => ['key1', 'key2'],
1545
    where => [1, 2],
1546
);
1547
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1548

            
1549
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1550
$dbi->delete_at(
1551
    table => 'table1',
1552
    primary_key => 'key1',
1553
    where => 1,
1554
);
1555
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1556

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1557
test 'insert_at';
1558
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1559
$dbi->execute($CREATE_TABLE->{1});
1560
$dbi->insert_at(
1561
    primary_key => ['key1', 'key2'], 
1562
    table => 'table1',
1563
    where => [1, 2],
1564
    param => {key3 => 3}
1565
);
1566
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1567
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1568
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1569

            
1570
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1571
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1572
$dbi->insert_at(
1573
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1574
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1575
    where => 1,
1576
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1577
);
1578

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

            
1583
eval {
1584
    $dbi->insert_at(
1585
        table => 'table1',
1586
        primary_key => ['key1', 'key2'],
1587
        where => {},
1588
        param => {key1 => 1, key2 => 2, key3 => 3},
1589
    );
1590
};
1591
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1592

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

            
1607
$dbi->delete_all(table => 'table1');
1608
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1609
$dbi->update_at(
1610
    table => 'table1',
1611
    primary_key => 'key1',
1612
    where => 1,
1613
    param => {key3 => 4}
1614
);
1615
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1616
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1617
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1618

            
1619
test 'select_at';
1620
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1621
$dbi->execute($CREATE_TABLE->{1});
1622
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1623
$result = $dbi->select_at(
1624
    table => 'table1',
1625
    primary_key => ['key1', 'key2'],
1626
    where => [1, 2]
1627
);
1628
$row = $result->fetch_hash_first;
1629
is($row->{key1}, 1);
1630
is($row->{key2}, 2);
1631
is($row->{key3}, 3);
1632

            
1633
$dbi->delete_all(table => 'table1');
1634
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1635
$result = $dbi->select_at(
1636
    table => 'table1',
1637
    primary_key => 'key1',
1638
    where => 1,
1639
);
1640
$row = $result->fetch_hash_first;
1641
is($row->{key1}, 1);
1642
is($row->{key2}, 2);
1643
is($row->{key3}, 3);
1644

            
1645
$dbi->delete_all(table => 'table1');
1646
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1647
$result = $dbi->select_at(
1648
    table => 'table1',
1649
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1650
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1651
);
1652
$row = $result->fetch_hash_first;
1653
is($row->{key1}, 1);
1654
is($row->{key2}, 2);
1655
is($row->{key3}, 3);
1656

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1657
eval {
1658
    $result = $dbi->select_at(
1659
        table => 'table1',
1660
        primary_key => ['key1', 'key2'],
1661
        where => {},
1662
    );
1663
};
1664
like($@, qr/must be/);
1665

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1666
eval {
1667
    $result = $dbi->select_at(
1668
        table => 'table1',
1669
        primary_key => ['key1', 'key2'],
1670
        where => [1],
1671
    );
1672
};
1673
like($@, qr/same/);
1674

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1675
eval {
1676
    $result = $dbi->update_at(
1677
        table => 'table1',
1678
        primary_key => ['key1', 'key2'],
1679
        where => {},
1680
        param => {key1 => 1, key2 => 2},
1681
    );
1682
};
1683
like($@, qr/must be/);
1684

            
1685
eval {
1686
    $result = $dbi->delete_at(
1687
        table => 'table1',
1688
        primary_key => ['key1', 'key2'],
1689
        where => {},
1690
    );
1691
};
1692
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1693

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1694
test 'columns';
1695
use MyDBI1;
1696
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1697
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1698

            
1699

            
1700
test 'model delete_at';
1701
{
1702
    package MyDBI6;
1703
    
1704
    use base 'DBIx::Custom';
1705
    
1706
    sub connect {
1707
        my $self = shift->SUPER::connect(@_);
1708
        
1709
        $self->include_model('MyModel5');
1710
        
1711
        return $self;
1712
    }
1713
}
1714
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1715
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1716
$dbi->execute("create table table2 (key1, key2, key3)");
1717
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1718
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1719
$dbi->model('table1')->delete_at(where => [1, 2]);
1720
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1721
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1722
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1723
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1724
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1725
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1726
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1727

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1728
test 'model insert_at';
1729
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1730
$dbi->execute($CREATE_TABLE->{1});
1731
$dbi->model('table1')->insert_at(
1732
    where => [1, 2],
1733
    param => {key3 => 3}
1734
);
1735
$result = $dbi->model('table1')->select;
1736
$row = $result->fetch_hash_first;
1737
is($row->{key1}, 1);
1738
is($row->{key2}, 2);
1739
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1740

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1741
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1742
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1743
$dbi->execute($CREATE_TABLE->{1});
1744
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1745
$dbi->model('table1')->update_at(
1746
    where => [1, 2],
1747
    param => {key3 => 4}
1748
);
1749
$result = $dbi->model('table1')->select;
1750
$row = $result->fetch_hash_first;
1751
is($row->{key1}, 1);
1752
is($row->{key2}, 2);
1753
is($row->{key3}, 4);
1754

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1755
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1756
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1757
$dbi->execute($CREATE_TABLE->{1});
1758
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1759
$result = $dbi->model('table1')->select_at(where => [1, 2]);
1760
$row = $result->fetch_hash_first;
1761
is($row->{key1}, 1);
1762
is($row->{key2}, 2);
1763
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1764

            
1765

            
cleanup
Yuki Kimoto authored on 2011-03-21
1766
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1767
{
1768
    package MyDBI7;
1769
    
1770
    use base 'DBIx::Custom';
1771
    
1772
    sub connect {
1773
        my $self = shift->SUPER::connect(@_);
1774
        
1775
        $self->include_model('MyModel6');
1776
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1777
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1778
        return $self;
1779
    }
1780
}
1781
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1782
$dbi->execute($CREATE_TABLE->{0});
1783
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1784
$dbi->setup_model;
1785
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1786
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1787
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1788
$result = $model->select(
1789
    column => [$model->mycolumn, $model->column('table2')],
1790
    where => {'table1.key1' => 1}
1791
);
1792
is_deeply($result->fetch_hash_first,
1793
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1794

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

            
1801
$param = {key2 => 11};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1802
$update_param = $dbi->update_param_tag($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1803
$sql = <<"EOS";
1804
update {table table1} $update_param
1805
where key1 = 1
1806
EOS
1807
$dbi->execute($sql, param => $param);
1808
$result = $dbi->execute($SELECT_SOURCES->{0});
1809
$rows   = $result->fetch_hash_all;
1810
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1811
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1812
                  "basic");
1813

            
1814

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

            
1820
$param = {key2 => 11, key3 => 33};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1821
$update_param = $dbi->update_param_tag($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1822
$sql = <<"EOS";
1823
update {table table1} $update_param
1824
where key1 = 1
1825
EOS
1826
$dbi->execute($sql, param => $param);
1827
$result = $dbi->execute($SELECT_SOURCES->{0});
1828
$rows   = $result->fetch_hash_all;
1829
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1830
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1831
                  "basic");
1832

            
1833
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1834
$dbi->execute($CREATE_TABLE->{1});
1835
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1836
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1837

            
1838
$param = {key2 => 11, key3 => 33};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1839
$update_param = $dbi->update_param_tag($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1840
$sql = <<"EOS";
1841
update {table table1} set $update_param
1842
where key1 = 1
1843
EOS
1844
$dbi->execute($sql, param => $param);
1845
$result = $dbi->execute($SELECT_SOURCES->{0});
1846
$rows   = $result->fetch_hash_all;
1847
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1848
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1849
                  "update param no_set");
1850

            
1851
            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1852
eval { $dbi->update_param_tag({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1853
like($@, qr/not safety/);
1854

            
1855

            
1856
test 'insert_param';
1857
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1858
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1859
$param = {key1 => 1, key2 => 2};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1860
$insert_param = $dbi->insert_param_tag($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1861
$sql = <<"EOS";
1862
insert into {table table1} $insert_param
1863
EOS
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1864
$dbi->execute($sql, param => $param);
1865
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1866
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1867

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1868
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1869
$dbi->reserved_word_quote('"');
1870
$dbi->execute($CREATE_TABLE->{1});
1871
$param = {key1 => 1, key2 => 2};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1872
$insert_param = $dbi->insert_param_tag($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1873
$sql = <<"EOS";
1874
insert into {table table1} $insert_param
1875
EOS
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1876
$dbi->execute($sql, param => $param);
1877
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1878
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1879

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1880
eval { $dbi->insert_param_tag({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1881
like($@, qr/not safety/);
cleanup
Yuki Kimoto authored on 2011-03-08
1882

            
1883

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1884
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1885
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1886
$dbi->execute($CREATE_TABLE->{0});
1887
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1888
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1889
$dbi->execute($CREATE_TABLE->{2});
1890
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1891
$dbi->execute($CREATE_TABLE->{4});
1892
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1893
$rows = $dbi->select(
1894
    table => 'table1',
1895
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1896
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1897
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1898
)->fetch_hash_all;
1899
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1900

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1901
$rows = $dbi->select(
1902
    table => 'table1',
1903
    where   => {'key1' => 1},
1904
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1905
)->fetch_hash_all;
1906
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1907

            
cleanup
Yuki Kimoto authored on 2011-03-08
1908
eval {
1909
    $rows = $dbi->select(
1910
        table => 'table1',
1911
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1912
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1913
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1914
    );
1915
};
1916
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1917

            
1918
$rows = $dbi->select(
1919
    table => 'table1',
1920
    where   => {'key1' => 1},
1921
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1922
              'left outer join table3 on table2.key3 = table3.key3']
1923
)->fetch_hash_all;
1924
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1925

            
1926
$rows = $dbi->select(
1927
    column => 'table3.key4 as table3__key4',
1928
    table => 'table1',
1929
    where   => {'table1.key1' => 1},
1930
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1931
              'left outer join table3 on table2.key3 = table3.key3']
1932
)->fetch_hash_all;
1933
is_deeply($rows, [{table3__key4 => 4}]);
1934

            
1935
$rows = $dbi->select(
1936
    column => 'table1.key1 as table1__key1',
1937
    table => 'table1',
1938
    where   => {'table3.key4' => 4},
1939
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1940
              'left outer join table3 on table2.key3 = table3.key3']
1941
)->fetch_hash_all;
1942
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1943

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1944
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1945
$dbi->reserved_word_quote('"');
1946
$dbi->execute($CREATE_TABLE->{0});
1947
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1948
$dbi->execute($CREATE_TABLE->{2});
1949
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
1950
$rows = $dbi->select(
1951
    table => 'table1',
1952
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
1953
    where   => {'table1.key2' => 2},
1954
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
1955
)->fetch_hash_all;
1956
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
1957
          'reserved_word_quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1958

            
1959
{
1960
    package MyDBI8;
1961
    
1962
    use base 'DBIx::Custom';
1963
    
1964
    sub connect {
1965
        my $self = shift->SUPER::connect(@_);
1966
        
1967
        $self->include_model('MyModel7');
1968
        
1969
        return $self;
1970
    }
1971
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1972

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1973
test 'mycolumn';
1974
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1975
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1976
$dbi->execute($CREATE_TABLE->{2});
1977
$dbi->setup_model;
1978
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1979
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1980
$model = $dbi->model('table1');
1981
$result = $model->select_at(
1982
    column => [
1983
        $model->mycolumn,
1984
        $model->column('table2')
1985
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1986
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1987
is_deeply($result->fetch_hash_first,
1988
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1989
$result = $model->select_at(
1990
    column => [
1991
        $model->mycolumn(['key1']),
1992
        $model->column(table2 => ['key1'])
1993
    ]
1994
);
1995
is_deeply($result->fetch_hash_first,
1996
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1997

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1998
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1999
{
2000
    package MyDBI9;
2001
    
2002
    use base 'DBIx::Custom';
2003
    
2004
    sub connect {
2005
        my $self = shift->SUPER::connect(@_);
2006
        
2007
        $self->include_model('MyModel8')->setup_model;
2008
        
2009
        return $self;
2010
    }
2011
}
2012
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2013
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2014
$model = $dbi->model('table1');
2015
eval{$model->execute('select * from table1')};
2016
ok(!$@);
2017

            
2018
test 'table_alias';
2019
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2020
$dbi->execute($CREATE_TABLE->{0});
2021
$dbi->execute($CREATE_TABLE->{2});
2022
$dbi->setup_model;
2023
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2024
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2025
$model = $dbi->model('table1');
2026
$result = $model->select(
2027
    column => [
2028
        $model->column('table2_alias')
2029
    ],
2030
    where => {'table2_alias.key3' => 2}
2031
);
2032
is_deeply($result->fetch_hash_first, 
2033
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
2034

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2035
test 'type() option';
2036
$dbi = DBIx::Custom->connect(
2037
    data_source => 'dbi:SQLite:dbname=:memory:',
2038
    dbi_option => {
2039
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2040
    }
2041
);
2042
my $binary = pack("I3", 1, 2, 3);
2043
$dbi->execute('create table table1(key1, key2)');
2044
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2045
$result = $dbi->select(table => 'table1');
2046
$row   = $result->fetch_hash_first;
2047
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2048
$result = $dbi->execute('select length(key1) as key1_length from table1');
2049
$row = $result->fetch_hash_first;
2050
is($row->{key1_length}, length $binary);
2051

            
2052
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2053
$result = $dbi->select(table => 'table1');
2054
$row   = $result->fetch_hash_first;
2055
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2056
$result = $dbi->execute('select length(key1) as key1_length from table1');
2057
$row = $result->fetch_hash_first;
2058
is($row->{key1_length}, length $binary);
2059

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2060
test 'create_model';
2061
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2062
$dbi->execute($CREATE_TABLE->{0});
2063
$dbi->execute($CREATE_TABLE->{2});
2064

            
2065
$dbi->create_model(
2066
    table => 'table1',
2067
    join => [
2068
       'left outer join table2 on table1.key1 = table2.key1'
2069
    ],
2070
    primary_key => ['key1']
2071
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2072
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2073
    table => 'table2'
2074
);
2075
$dbi->create_model(
2076
    table => 'table3',
2077
    filter => [
2078
        key1 => {in => sub { uc $_[0] }}
2079
    ]
2080
);
2081
$dbi->setup_model;
2082
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2083
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2084
$model = $dbi->model('table1');
2085
$result = $model->select(
2086
    column => [$model->mycolumn, $model->column('table2')],
2087
    where => {'table1.key1' => 1}
2088
);
2089
is_deeply($result->fetch_hash_first,
2090
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
create_model() return model
Yuki Kimoto authored on 2011-03-29
2091
is_deeply($model2->select->fetch_hash_first, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2092

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2093
test 'model method';
2094
test 'create_model';
2095
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2096
$dbi->execute($CREATE_TABLE->{2});
2097
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2098
$model = $dbi->create_model(
2099
    table => 'table2'
2100
);
2101
$model->method(foo => sub { shift->select(@_) });
2102
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2103

            
2104
test 'merge_param';
2105
{
2106
    my $dbi = DBIx::Custom->new;
2107
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2108
    my $param2 = {key1 => 1, key2 => 2};
2109
    my $param3 = {key1 => 1};
2110
    my $param = $dbi->merge_param($param1, $param2, $param3);
2111
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2112
}
2113

            
2114
test 'select() param option';
2115
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2116
$dbi->execute($CREATE_TABLE->{0});
2117
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2118
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2119
$dbi->execute($CREATE_TABLE->{2});
2120
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2121
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2122
$rows = $dbi->select(
2123
    table => 'table1',
2124
    column => 'table1.key1 as table1_key1, key2, key3',
2125
    where   => {'table1.key2' => 3},
2126
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2127
              ' as table2 on table1.key1 = table2.key1'],
2128
    param => {'table2.key3' => 5}
2129
)->fetch_hash_all;
2130
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2131