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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
114

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
354
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
355
like($@, qr/safety/);
356

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

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

            
381

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

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

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

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

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

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

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

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

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

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

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

            
468

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

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

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

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

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

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

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

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

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

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

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

            
538
test 'filters';
539
$dbi = DBIx::Custom->new;
540

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

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

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

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

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

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

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

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

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

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

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

            
617

            
618
test 'transaction';
619
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
620
$dbi->execute($CREATE_TABLE->{0});
621

            
622
$dbi->begin_work;
623

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

            
630
$dbi->rollback if $@;
631

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

            
636
$dbi->begin_work;
637

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

            
643
$dbi->commit unless $@;
644

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

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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
655
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
656
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
657
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
658
    one => sub { 1 }
659
);
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
    two => sub { 2 }
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
    twice => sub {
665
        my $self = shift;
666
        return $_[0] * 2;
667
    }
668
});
669

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1056
$where = $dbi->where;
1057
$result = $dbi->select(
1058
    table => 'table1',
1059
    where => $where
1060
);
1061
$row = $result->fetch_hash_all;
1062
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1063

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1253
test 'register_tag_processor';
1254
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1255
$dbi->register_tag_processor(
1256
    a => sub { 1 }
1257
);
1258
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1259

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1260
test 'register_tag';
1261
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1262
$dbi->register_tag(
1263
    b => sub { 2 }
1264
);
1265
is($dbi->query_builder->tags->{b}->(), 2);
1266

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1267
test 'table not specify exception';
1268
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1269
eval {$dbi->insert};
1270
like($@, qr/table/);
1271
eval {$dbi->update};
1272
like($@, qr/table/);
1273
eval {$dbi->delete};
1274
like($@, qr/table/);
1275
eval {$dbi->select};
1276
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1277

            
1278

            
1279
test 'more tests';
1280
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1281
eval{$dbi->apply_filter('table', 'column', [])};
1282
like($@, qr/apply_filter/);
1283

            
1284
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1285
like($@, qr/apply_filter/);
1286

            
1287
$dbi->apply_filter(
1288

            
1289
);
1290
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1291
$dbi->execute($CREATE_TABLE->{0});
1292
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1293
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1294
$dbi->apply_filter('table1', 'key2', 
1295
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1296
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1297
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1298

            
1299
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1300
$dbi->execute($CREATE_TABLE->{0});
1301
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1302
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1303
$dbi->apply_filter('table1', 'key2', {});
1304
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1305
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1306

            
1307
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1308
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1309
like($@, qr/not registered/);
1310
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1311
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1312
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1313
is($dbi->one, 1);
1314

            
1315
eval{DBIx::Custom->connect()};
1316
like($@, qr/connect/);
1317

            
1318
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1319
$dbi->execute($CREATE_TABLE->{0});
1320
$dbi->register_filter(twice => sub { $_[0] * 2 });
1321
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1322
             filter => {key1 => 'twice'});
1323
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1324
is_deeply($row, {key1 => 2, key2 => 2});
1325
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1326
             filter => {key1 => 'no'}) };
1327
like($@, qr//);
1328

            
1329
$dbi->register_filter(one => sub { });
1330
$dbi->default_fetch_filter('one');
1331
ok($dbi->default_fetch_filter);
1332
$dbi->default_bind_filter('one');
1333
ok($dbi->default_bind_filter);
1334
eval{$dbi->default_fetch_filter('no')};
1335
like($@, qr/not registered/);
1336
eval{$dbi->default_bind_filter('no')};
1337
like($@, qr/not registered/);
1338
$dbi->default_bind_filter(undef);
1339
ok(!defined $dbi->default_bind_filter);
1340
$dbi->default_fetch_filter(undef);
1341
ok(!defined $dbi->default_fetch_filter);
1342
eval {$dbi->execute('select * from table1 {= author') };
1343
like($@, qr/Tag not finished/);
1344

            
1345
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1346
$dbi->execute($CREATE_TABLE->{0});
1347
$dbi->register_filter(one => sub { 1 });
1348
$result = $dbi->select(table => 'table1');
1349
eval {$result->filter(key1 => 'no')};
1350
like($@, qr/not registered/);
1351
eval {$result->end_filter(key1 => 'no')};
1352
like($@, qr/not registered/);
1353
$result->default_filter(undef);
1354
ok(!defined $result->default_filter);
1355
$result->default_filter('one');
1356
is($result->default_filter->(), 1);
1357

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1358
test 'dbi_option';
1359
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1360
                             dbi_option => {PrintError => 1});
1361
ok($dbi->dbh->{PrintError});
1362
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1363
                             dbi_options => {PrintError => 1});
1364
ok($dbi->dbh->{PrintError});
1365

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1366
test 'DBIx::Custom::Result stash()';
1367
$result = DBIx::Custom::Result->new;
1368
is_deeply($result->stash, {}, 'default');
1369
$result->stash->{foo} = 1;
1370
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1371

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1372
test 'filter __ expression';
1373
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1374
$dbi->execute('create table company (id, name, location_id)');
1375
$dbi->execute('create table location (id, name)');
1376
$dbi->apply_filter('location',
1377
  name => {in => sub { uc $_[0] } }
1378
);
1379

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

            
1383
$result = $dbi->select(
1384
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1385
    column => ['location.name as location__name']
1386
);
1387
is($result->fetch_first->[0], 'B');
1388

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1389
$result = $dbi->select(
1390
    table => 'company', relation => {'company.location_id' => 'location.id'},
1391
    column => ['location.name as location__name']
1392
);
1393
is($result->fetch_first->[0], 'B');
1394

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1395
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1396
use MyDBI1;
1397
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1398
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1399
$model = $dbi->model('book');
1400
$model->insert({title => 'a', author => 'b'});
1401
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1402
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1403
$model = $dbi->model('company');
1404
$model->insert({name => 'a'});
1405
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1406
is($dbi->models->{'book'}, $dbi->model('book'));
1407
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1408

            
1409
{
1410
    package MyDBI4;
1411

            
1412
    use strict;
1413
    use warnings;
1414

            
1415
    use base 'DBIx::Custom';
1416

            
1417
    sub connect {
1418
        my $self = shift->SUPER::connect(@_);
1419
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1420
        $self->include_model(
1421
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1422
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1423
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1424
            ]
1425
        );
1426
    }
1427

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

            
1430
    use strict;
1431
    use warnings;
1432

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

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

            
1437
    use strict;
1438
    use warnings;
1439

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

            
1442
    sub insert {
1443
        my ($self, $param) = @_;
1444
        
1445
        return $self->SUPER::insert(param => $param);
1446
    }
1447

            
1448
    sub list { shift->select; }
1449

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1450
    package MyModel2::Company;
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
}
1465
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1466
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1467
$model = $dbi->model('book');
1468
$model->insert({title => 'a', author => 'b'});
1469
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1470
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1471
$model = $dbi->model('company');
1472
$model->insert({name => 'a'});
1473
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1474

            
1475
{
1476
     package MyDBI5;
1477

            
1478
    use strict;
1479
    use warnings;
1480

            
1481
    use base 'DBIx::Custom';
1482

            
1483
    sub connect {
1484
        my $self = shift->SUPER::connect(@_);
1485
        
1486
        $self->include_model('MyModel4');
1487
    }
1488
}
1489
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1490
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1491
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1492
$model = $dbi->model('company');
1493
$model->insert({name => 'a'});
1494
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1495
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1496
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1497
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1498

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1499
test 'primary_key';
1500
use MyDBI1;
1501
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1502
$model = $dbi->model('book');
1503
$model->primary_key(['id', 'number']);
1504
is_deeply($model->primary_key, ['id', 'number']);
1505

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1506
test 'columns';
1507
use MyDBI1;
1508
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1509
$model = $dbi->model('book');
1510
$model->columns(['id', 'number']);
1511
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1512

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1513
test 'setup_model';
1514
use MyDBI1;
1515
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1516
$dbi->execute('create table book (id)');
1517
$dbi->execute('create table company (id, name);');
1518
$dbi->execute('create table test (id, name, primary key (id, name));');
1519
$dbi->setup_model;
1520
is_deeply($dbi->model('book')->columns, ['id']);
1521
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1522

            
1523
test 'delete_at';
1524
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1525
$dbi->execute($CREATE_TABLE->{1});
1526
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1527
$dbi->delete_at(
1528
    table => 'table1',
1529
    primary_key => ['key1', 'key2'],
1530
    where => [1, 2],
1531
);
1532
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1533

            
1534
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1535
$dbi->delete_at(
1536
    table => 'table1',
1537
    primary_key => 'key1',
1538
    where => 1,
1539
);
1540
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1541

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1542
test 'insert_at';
1543
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1544
$dbi->execute($CREATE_TABLE->{1});
1545
$dbi->insert_at(
1546
    primary_key => ['key1', 'key2'], 
1547
    table => 'table1',
1548
    where => [1, 2],
1549
    param => {key3 => 3}
1550
);
1551
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1552
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1553
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1554

            
1555
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1556
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1557
$dbi->insert_at(
1558
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1559
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1560
    where => 1,
1561
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1562
);
1563

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

            
1568
eval {
1569
    $dbi->insert_at(
1570
        table => 'table1',
1571
        primary_key => ['key1', 'key2'],
1572
        where => {},
1573
        param => {key1 => 1, key2 => 2, key3 => 3},
1574
    );
1575
};
1576
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1577

            
1578
test 'update_at';
1579
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1580
$dbi->execute($CREATE_TABLE->{1});
1581
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1582
$dbi->update_at(
1583
    table => 'table1',
1584
    primary_key => ['key1', 'key2'],
1585
    where => [1, 2],
1586
    param => {key3 => 4}
1587
);
1588
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1589
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1590
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1591

            
1592
$dbi->delete_all(table => 'table1');
1593
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1594
$dbi->update_at(
1595
    table => 'table1',
1596
    primary_key => 'key1',
1597
    where => 1,
1598
    param => {key3 => 4}
1599
);
1600
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1601
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1602
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1603

            
1604
test 'select_at';
1605
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1606
$dbi->execute($CREATE_TABLE->{1});
1607
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1608
$result = $dbi->select_at(
1609
    table => 'table1',
1610
    primary_key => ['key1', 'key2'],
1611
    where => [1, 2]
1612
);
1613
$row = $result->fetch_hash_first;
1614
is($row->{key1}, 1);
1615
is($row->{key2}, 2);
1616
is($row->{key3}, 3);
1617

            
1618
$dbi->delete_all(table => 'table1');
1619
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1620
$result = $dbi->select_at(
1621
    table => 'table1',
1622
    primary_key => 'key1',
1623
    where => 1,
1624
);
1625
$row = $result->fetch_hash_first;
1626
is($row->{key1}, 1);
1627
is($row->{key2}, 2);
1628
is($row->{key3}, 3);
1629

            
1630
$dbi->delete_all(table => 'table1');
1631
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1632
$result = $dbi->select_at(
1633
    table => 'table1',
1634
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1635
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1636
);
1637
$row = $result->fetch_hash_first;
1638
is($row->{key1}, 1);
1639
is($row->{key2}, 2);
1640
is($row->{key3}, 3);
1641

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1642
eval {
1643
    $result = $dbi->select_at(
1644
        table => 'table1',
1645
        primary_key => ['key1', 'key2'],
1646
        where => {},
1647
    );
1648
};
1649
like($@, qr/must be/);
1650

            
1651
eval {
1652
    $result = $dbi->update_at(
1653
        table => 'table1',
1654
        primary_key => ['key1', 'key2'],
1655
        where => {},
1656
        param => {key1 => 1, key2 => 2},
1657
    );
1658
};
1659
like($@, qr/must be/);
1660

            
1661
eval {
1662
    $result = $dbi->delete_at(
1663
        table => 'table1',
1664
        primary_key => ['key1', 'key2'],
1665
        where => {},
1666
    );
1667
};
1668
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1669

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1670
test 'columns';
1671
use MyDBI1;
1672
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1673
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1674

            
1675

            
1676
test 'model delete_at';
1677
{
1678
    package MyDBI6;
1679
    
1680
    use base 'DBIx::Custom';
1681
    
1682
    sub connect {
1683
        my $self = shift->SUPER::connect(@_);
1684
        
1685
        $self->include_model('MyModel5');
1686
        
1687
        return $self;
1688
    }
1689
}
1690
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1691
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1692
$dbi->execute("create table table2 (key1, key2, key3)");
1693
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1694
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1695
$dbi->model('table1')->delete_at(where => [1, 2]);
1696
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1697
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1698
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1699
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1700
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1701
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1702
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1703

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1704
test 'model insert_at';
1705
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1706
$dbi->execute($CREATE_TABLE->{1});
1707
$dbi->model('table1')->insert_at(
1708
    where => [1, 2],
1709
    param => {key3 => 3}
1710
);
1711
$result = $dbi->model('table1')->select;
1712
$row = $result->fetch_hash_first;
1713
is($row->{key1}, 1);
1714
is($row->{key2}, 2);
1715
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1716

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1717
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1718
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1719
$dbi->execute($CREATE_TABLE->{1});
1720
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1721
$dbi->model('table1')->update_at(
1722
    where => [1, 2],
1723
    param => {key3 => 4}
1724
);
1725
$result = $dbi->model('table1')->select;
1726
$row = $result->fetch_hash_first;
1727
is($row->{key1}, 1);
1728
is($row->{key2}, 2);
1729
is($row->{key3}, 4);
1730

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

            
1741

            
cleanup
Yuki Kimoto authored on 2011-03-21
1742
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1743
{
1744
    package MyDBI7;
1745
    
1746
    use base 'DBIx::Custom';
1747
    
1748
    sub connect {
1749
        my $self = shift->SUPER::connect(@_);
1750
        
1751
        $self->include_model('MyModel6');
1752
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1753
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1754
        return $self;
1755
    }
1756
}
1757
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1758
$dbi->execute($CREATE_TABLE->{0});
1759
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1760
$dbi->setup_model;
1761
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1762
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1763
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1764
$result = $model->select(
1765
    column => [$model->mycolumn, $model->column('table2')],
1766
    where => {'table1.key1' => 1}
1767
);
1768
is_deeply($result->fetch_hash_first,
1769
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1770

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

            
1777
$param = {key2 => 11};
1778
$update_param = $dbi->update_param($param);
1779
$sql = <<"EOS";
1780
update {table table1} $update_param
1781
where key1 = 1
1782
EOS
1783
$dbi->execute($sql, param => $param);
1784
$result = $dbi->execute($SELECT_SOURCES->{0});
1785
$rows   = $result->fetch_hash_all;
1786
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1787
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1788
                  "basic");
1789

            
1790

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

            
1796
$param = {key2 => 11, key3 => 33};
1797
$update_param = $dbi->update_param($param);
1798
$sql = <<"EOS";
1799
update {table table1} $update_param
1800
where key1 = 1
1801
EOS
1802
$dbi->execute($sql, param => $param);
1803
$result = $dbi->execute($SELECT_SOURCES->{0});
1804
$rows   = $result->fetch_hash_all;
1805
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1806
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1807
                  "basic");
1808

            
1809
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1810
$dbi->execute($CREATE_TABLE->{1});
1811
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1812
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1813

            
1814
$param = {key2 => 11, key3 => 33};
1815
$update_param = $dbi->update_param($param, {no_set => 1});
1816
$sql = <<"EOS";
1817
update {table table1} set $update_param
1818
where key1 = 1
1819
EOS
1820
$dbi->execute($sql, param => $param);
1821
$result = $dbi->execute($SELECT_SOURCES->{0});
1822
$rows   = $result->fetch_hash_all;
1823
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1824
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1825
                  "update param no_set");
1826

            
1827
            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1828
eval { $dbi->update_param({";" => 1}) };
1829
like($@, qr/not safety/);
1830

            
1831

            
1832
test 'insert_param';
1833
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1834
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1835
$param = {key1 => 1, key2 => 2};
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1836
$insert_param = $dbi->insert_param($param);
1837
$sql = <<"EOS";
1838
insert into {table table1} $insert_param
1839
EOS
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1840
$dbi->execute($sql, param => $param);
1841
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1842
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1843

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1844
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1845
$dbi->reserved_word_quote('"');
1846
$dbi->execute($CREATE_TABLE->{1});
1847
$param = {key1 => 1, key2 => 2};
1848
$insert_param = $dbi->insert_param($param);
1849
$sql = <<"EOS";
1850
insert into {table table1} $insert_param
1851
EOS
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1852
$dbi->execute($sql, param => $param);
1853
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1854
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1855

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

            
1859

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1860
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1861
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1862
$dbi->execute($CREATE_TABLE->{0});
1863
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1864
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1865
$dbi->execute($CREATE_TABLE->{2});
1866
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1867
$dbi->execute($CREATE_TABLE->{4});
1868
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1869
$rows = $dbi->select(
1870
    table => 'table1',
1871
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1872
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1873
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1874
)->fetch_hash_all;
1875
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1876

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1877
$rows = $dbi->select(
1878
    table => 'table1',
1879
    where   => {'key1' => 1},
1880
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1881
)->fetch_hash_all;
1882
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1883

            
cleanup
Yuki Kimoto authored on 2011-03-08
1884
eval {
1885
    $rows = $dbi->select(
1886
        table => 'table1',
1887
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1888
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1889
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1890
    );
1891
};
1892
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1893

            
1894
$rows = $dbi->select(
1895
    table => 'table1',
1896
    where   => {'key1' => 1},
1897
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1898
              'left outer join table3 on table2.key3 = table3.key3']
1899
)->fetch_hash_all;
1900
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1901

            
1902
$rows = $dbi->select(
1903
    column => 'table3.key4 as table3__key4',
1904
    table => 'table1',
1905
    where   => {'table1.key1' => 1},
1906
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1907
              'left outer join table3 on table2.key3 = table3.key3']
1908
)->fetch_hash_all;
1909
is_deeply($rows, [{table3__key4 => 4}]);
1910

            
1911
$rows = $dbi->select(
1912
    column => 'table1.key1 as table1__key1',
1913
    table => 'table1',
1914
    where   => {'table3.key4' => 4},
1915
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1916
              'left outer join table3 on table2.key3 = table3.key3']
1917
)->fetch_hash_all;
1918
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1919

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1920
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1921
$dbi->reserved_word_quote('"');
1922
$dbi->execute($CREATE_TABLE->{0});
1923
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1924
$dbi->execute($CREATE_TABLE->{2});
1925
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
1926
$rows = $dbi->select(
1927
    table => 'table1',
1928
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
1929
    where   => {'table1.key2' => 2},
1930
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
1931
)->fetch_hash_all;
1932
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
1933
          'reserved_word_quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1934

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1935
test 'model join and column attribute and all_column option';
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1936
{
1937
    package MyDBI8;
1938
    
1939
    use base 'DBIx::Custom';
1940
    
1941
    sub connect {
1942
        my $self = shift->SUPER::connect(@_);
1943
        
1944
        $self->include_model('MyModel7');
1945
        
1946
        return $self;
1947
    }
1948
}
1949
$dbi = MyDBI8->connect($NEW_ARGS->{0});
1950
$dbi->execute($CREATE_TABLE->{0});
1951
$dbi->execute($CREATE_TABLE->{2});
1952
$dbi->setup_model;
1953
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1954
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1955
$model = $dbi->model('table1');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1956
$result = $model->select_at(
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1957
    column => {table => ['table1', 'table2'], prepend => 'table1.key1 as key1_1,'},
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1958
    where => 1
1959
);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1960
is_deeply($result->fetch_hash_first,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1961
          {key1_1 => 1, key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1962
$result = $model->select(column => {all => 1});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1963
is_deeply($result->fetch_hash_first,
1964
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1965

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

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

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

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

            
2045
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2046
$result = $dbi->select(table => 'table1');
2047
$row   = $result->fetch_hash_first;
2048
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2049
$result = $dbi->execute('select length(key1) as key1_length from table1');
2050
$row = $result->fetch_hash_first;
2051
is($row->{key1_length}, length $binary);
2052

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2053
test 'create_model';
2054
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2055
$dbi->execute($CREATE_TABLE->{0});
2056
$dbi->execute($CREATE_TABLE->{2});
2057

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

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

            
2097
test 'merge_param';
2098
{
2099
    my $dbi = DBIx::Custom->new;
2100
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2101
    my $param2 = {key1 => 1, key2 => 2};
2102
    my $param3 = {key1 => 1};
2103
    my $param = $dbi->merge_param($param1, $param2, $param3);
2104
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
2105
}