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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
384

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

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

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

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

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

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

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

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

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

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

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

            
471

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

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

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

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

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

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

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

            
508
$rows = $dbi->select(
509
    table => [qw/table1 table2/],
510
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
511
    relation  => {'table1.key1' => 'table2.key1'}
512
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
513
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where");
removed register_format()
yuki-kimoto authored on 2010-05-26
514

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
620

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

            
625
$dbi->begin_work;
626

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

            
633
$dbi->rollback if $@;
634

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

            
639
$dbi->begin_work;
640

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

            
646
$dbi->commit unless $@;
647

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1281

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

            
1287
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1288
like($@, qr/apply_filter/);
1289

            
1290
$dbi->apply_filter(
1291

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

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

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

            
1318
eval{DBIx::Custom->connect()};
1319
like($@, qr/connect/);
1320

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

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

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

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

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

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

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

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

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

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

            
1412
{
1413
    package MyDBI4;
1414

            
1415
    use strict;
1416
    use warnings;
1417

            
1418
    use base 'DBIx::Custom';
1419

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

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

            
1433
    use strict;
1434
    use warnings;
1435

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

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

            
1440
    use strict;
1441
    use warnings;
1442

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

            
1445
    sub insert {
1446
        my ($self, $param) = @_;
1447
        
1448
        return $self->SUPER::insert(param => $param);
1449
    }
1450

            
1451
    sub list { shift->select; }
1452

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

            
1455
    use strict;
1456
    use warnings;
1457

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

            
1460
    sub insert {
1461
        my ($self, $param) = @_;
1462
        
1463
        return $self->SUPER::insert(param => $param);
1464
    }
1465

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

            
1478
{
1479
     package MyDBI5;
1480

            
1481
    use strict;
1482
    use warnings;
1483

            
1484
    use base 'DBIx::Custom';
1485

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1678

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

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

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

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

            
1744

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

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

            
1780
$param = {key2 => 11};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1781
$update_param = $dbi->update_param_tag($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1782
$sql = <<"EOS";
1783
update {table table1} $update_param
1784
where key1 = 1
1785
EOS
1786
$dbi->execute($sql, param => $param);
1787
$result = $dbi->execute($SELECT_SOURCES->{0});
1788
$rows   = $result->fetch_hash_all;
1789
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1790
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1791
                  "basic");
1792

            
1793

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

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

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

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

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

            
1834

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

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

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

            
1862

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

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

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

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

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

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

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

            
1938
{
1939
    package MyDBI8;
1940
    
1941
    use base 'DBIx::Custom';
1942
    
1943
    sub connect {
1944
        my $self = shift->SUPER::connect(@_);
1945
        
1946
        $self->include_model('MyModel7');
1947
        
1948
        return $self;
1949
    }
1950
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1951

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1952
test 'mycolumn';
1953
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1954
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1955
$dbi->execute($CREATE_TABLE->{2});
1956
$dbi->setup_model;
1957
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1958
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1959
$model = $dbi->model('table1');
1960
$result = $model->select_at(
1961
    column => [
1962
        $model->mycolumn,
1963
        $model->column('table2')
1964
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1965
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1966
is_deeply($result->fetch_hash_first,
1967
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1968
$result = $model->select_at(
1969
    column => [
1970
        $model->mycolumn(['key1']),
1971
        $model->column(table2 => ['key1'])
1972
    ]
1973
);
1974
is_deeply($result->fetch_hash_first,
1975
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1976

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1977
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1978
{
1979
    package MyDBI9;
1980
    
1981
    use base 'DBIx::Custom';
1982
    
1983
    sub connect {
1984
        my $self = shift->SUPER::connect(@_);
1985
        
1986
        $self->include_model('MyModel8')->setup_model;
1987
        
1988
        return $self;
1989
    }
1990
}
1991
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1992
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1993
$model = $dbi->model('table1');
1994
eval{$model->execute('select * from table1')};
1995
ok(!$@);
1996

            
1997
test 'table_alias';
1998
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1999
$dbi->execute($CREATE_TABLE->{0});
2000
$dbi->execute($CREATE_TABLE->{2});
2001
$dbi->setup_model;
2002
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2003
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2004
$model = $dbi->model('table1');
2005
$result = $model->select(
2006
    column => [
2007
        $model->column('table2_alias')
2008
    ],
2009
    where => {'table2_alias.key3' => 2}
2010
);
2011
is_deeply($result->fetch_hash_first, 
2012
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
2013

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2014
test 'type() option';
2015
$dbi = DBIx::Custom->connect(
2016
    data_source => 'dbi:SQLite:dbname=:memory:',
2017
    dbi_option => {
2018
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2019
    }
2020
);
2021
my $binary = pack("I3", 1, 2, 3);
2022
$dbi->execute('create table table1(key1, key2)');
2023
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2024
$result = $dbi->select(table => 'table1');
2025
$row   = $result->fetch_hash_first;
2026
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2027
$result = $dbi->execute('select length(key1) as key1_length from table1');
2028
$row = $result->fetch_hash_first;
2029
is($row->{key1_length}, length $binary);
2030

            
2031
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2032
$result = $dbi->select(table => 'table1');
2033
$row   = $result->fetch_hash_first;
2034
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2035
$result = $dbi->execute('select length(key1) as key1_length from table1');
2036
$row = $result->fetch_hash_first;
2037
is($row->{key1_length}, length $binary);
2038

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2039
test 'create_model';
2040
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2041
$dbi->execute($CREATE_TABLE->{0});
2042
$dbi->execute($CREATE_TABLE->{2});
2043

            
2044
$dbi->create_model(
2045
    table => 'table1',
2046
    join => [
2047
       'left outer join table2 on table1.key1 = table2.key1'
2048
    ],
2049
    primary_key => ['key1']
2050
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2051
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2052
    table => 'table2'
2053
);
2054
$dbi->create_model(
2055
    table => 'table3',
2056
    filter => [
2057
        key1 => {in => sub { uc $_[0] }}
2058
    ]
2059
);
2060
$dbi->setup_model;
2061
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2062
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2063
$model = $dbi->model('table1');
2064
$result = $model->select(
2065
    column => [$model->mycolumn, $model->column('table2')],
2066
    where => {'table1.key1' => 1}
2067
);
2068
is_deeply($result->fetch_hash_first,
2069
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
create_model() return model
Yuki Kimoto authored on 2011-03-29
2070
is_deeply($model2->select->fetch_hash_first, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2071

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2072
test 'model method';
2073
test 'create_model';
2074
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2075
$dbi->execute($CREATE_TABLE->{2});
2076
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2077
$model = $dbi->create_model(
2078
    table => 'table2'
2079
);
2080
$model->method(foo => sub { shift->select(@_) });
2081
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2082

            
2083
test 'merge_param';
2084
{
2085
    my $dbi = DBIx::Custom->new;
2086
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2087
    my $param2 = {key1 => 1, key2 => 2};
2088
    my $param3 = {key1 => 1};
2089
    my $param = $dbi->merge_param($param1, $param2, $param3);
2090
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2091
}
2092

            
2093
test 'select() param option';
2094
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2095
$dbi->execute($CREATE_TABLE->{0});
2096
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2097
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2098
$dbi->execute($CREATE_TABLE->{2});
2099
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2100
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2101
$rows = $dbi->select(
2102
    table => 'table1',
2103
    column => 'table1.key1 as table1_key1, key2, key3',
2104
    where   => {'table1.key2' => 3},
2105
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2106
              ' as table2 on table1.key1 = table2.key1'],
2107
    param => {'table2.key3' => 5}
2108
)->fetch_hash_all;
2109
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2110

            
2111
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2112
$dbi->reserved_word_quote('"');
2113
$dbi->execute($CREATE_TABLE->{0});
2114
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2115
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2116
$dbi->execute($CREATE_TABLE->{2});
2117
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2118
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2119
$join = ['inner join table2 on "table1"."key1" = "table2"."key1"'];
2120
$join = $dbi->replace(
2121
    $join,
2122
    'inner join table2 on "table1"."key1" = "table2"."key1"',
2123
    'inner join (select * from table2 where {= table2.key3}) as table2'
2124
);
2125

            
cleanup
Yuki Kimoto authored on 2011-04-01
2126
$rows = $dbi->select(
2127
    table => 'table1',
2128
    column => 'table1.key1 as table1_key1, key2, key3',
2129
    where   => {'table1.key2' => 3},
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2130
    join  => ['inner join table2 on "table1"."key1" = "table2"."key1"'],
cleanup
Yuki Kimoto authored on 2011-04-01
2131
    param => {'table2.key3' => 5}
2132
)->fetch_hash_all;
2133
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2134

            
2135
$join = ['inner join table2 on "table1"."key1" = "table2"."key1"'];
2136
eval {
2137
    $join = $dbi->replace(
2138
        $join,
2139
        'pppp inner join table2 on "table1"."key1" = "table2"."key1"',
2140
        'inner join (select * from table2 where {= table2.key3}) as table2'
2141
    );
2142
};
2143
like($@, qr/replace/);