DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
2119 lines | 71.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-04-02
602
like($@, qr/name/, "invald SQL");
add tests
yuki-kimoto authored on 2010-08-10
603

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

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

            
620

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

            
625
$dbi->begin_work;
626

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

            
633
$dbi->rollback if $@;
634

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

            
639
$dbi->begin_work;
640

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

            
646
$dbi->commit unless $@;
647

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1290

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

            
1296
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1297
like($@, qr/apply_filter/);
1298

            
1299
$dbi->apply_filter(
1300

            
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
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1308
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1309
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1310

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

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

            
1327
eval{DBIx::Custom->connect()};
1328
like($@, qr/connect/);
1329

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

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

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

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

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

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

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

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

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

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

            
1421
{
1422
    package MyDBI4;
1423

            
1424
    use strict;
1425
    use warnings;
1426

            
1427
    use base 'DBIx::Custom';
1428

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

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

            
1442
    use strict;
1443
    use warnings;
1444

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

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

            
1449
    use strict;
1450
    use warnings;
1451

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

            
1454
    sub insert {
1455
        my ($self, $param) = @_;
1456
        
1457
        return $self->SUPER::insert(param => $param);
1458
    }
1459

            
1460
    sub list { shift->select; }
1461

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

            
1464
    use strict;
1465
    use warnings;
1466

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

            
1469
    sub insert {
1470
        my ($self, $param) = @_;
1471
        
1472
        return $self->SUPER::insert(param => $param);
1473
    }
1474

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

            
1487
{
1488
     package MyDBI5;
1489

            
1490
    use strict;
1491
    use warnings;
1492

            
1493
    use base 'DBIx::Custom';
1494

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1663
eval {
1664
    $result = $dbi->update_at(
1665
        table => 'table1',
1666
        primary_key => ['key1', 'key2'],
1667
        where => {},
1668
        param => {key1 => 1, key2 => 2},
1669
    );
1670
};
1671
like($@, qr/must be/);
1672

            
1673
eval {
1674
    $result = $dbi->delete_at(
1675
        table => 'table1',
1676
        primary_key => ['key1', 'key2'],
1677
        where => {},
1678
    );
1679
};
1680
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1681

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1682
test 'columns';
1683
use MyDBI1;
1684
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1685
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1686

            
1687

            
1688
test 'model delete_at';
1689
{
1690
    package MyDBI6;
1691
    
1692
    use base 'DBIx::Custom';
1693
    
1694
    sub connect {
1695
        my $self = shift->SUPER::connect(@_);
1696
        
1697
        $self->include_model('MyModel5');
1698
        
1699
        return $self;
1700
    }
1701
}
1702
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1703
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1704
$dbi->execute("create table table2 (key1, key2, key3)");
1705
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1706
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1707
$dbi->model('table1')->delete_at(where => [1, 2]);
1708
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1709
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1710
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1711
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1712
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1713
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1714
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1715

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

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

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

            
1753

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

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

            
1789
$param = {key2 => 11};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1790
$update_param = $dbi->update_param_tag($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1791
$sql = <<"EOS";
1792
update {table table1} $update_param
1793
where key1 = 1
1794
EOS
1795
$dbi->execute($sql, param => $param);
1796
$result = $dbi->execute($SELECT_SOURCES->{0});
1797
$rows   = $result->fetch_hash_all;
1798
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1799
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1800
                  "basic");
1801

            
1802

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

            
1808
$param = {key2 => 11, key3 => 33};
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1809
$update_param = $dbi->update_param_tag($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1810
$sql = <<"EOS";
1811
update {table table1} $update_param
1812
where key1 = 1
1813
EOS
1814
$dbi->execute($sql, param => $param);
1815
$result = $dbi->execute($SELECT_SOURCES->{0});
1816
$rows   = $result->fetch_hash_all;
1817
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1818
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1819
                  "basic");
1820

            
1821
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1822
$dbi->execute($CREATE_TABLE->{1});
1823
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1824
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1825

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

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

            
1843

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

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

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

            
1871

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1872
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1873
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1874
$dbi->execute($CREATE_TABLE->{0});
1875
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1876
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1877
$dbi->execute($CREATE_TABLE->{2});
1878
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1879
$dbi->execute($CREATE_TABLE->{4});
1880
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1881
$rows = $dbi->select(
1882
    table => 'table1',
1883
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1884
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1885
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1886
)->fetch_hash_all;
1887
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1888

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1889
$rows = $dbi->select(
1890
    table => 'table1',
1891
    where   => {'key1' => 1},
1892
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1893
)->fetch_hash_all;
1894
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1895

            
cleanup
Yuki Kimoto authored on 2011-03-08
1896
eval {
1897
    $rows = $dbi->select(
1898
        table => 'table1',
1899
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1900
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1901
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1902
    );
1903
};
1904
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1905

            
1906
$rows = $dbi->select(
1907
    table => 'table1',
1908
    where   => {'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, [{key1 => 1, key2 => 2}]);
1913

            
1914
$rows = $dbi->select(
1915
    column => 'table3.key4 as table3__key4',
1916
    table => 'table1',
1917
    where   => {'table1.key1' => 1},
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, [{table3__key4 => 4}]);
1922

            
1923
$rows = $dbi->select(
1924
    column => 'table1.key1 as table1__key1',
1925
    table => 'table1',
1926
    where   => {'table3.key4' => 4},
1927
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1928
              'left outer join table3 on table2.key3 = table3.key3']
1929
)->fetch_hash_all;
1930
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1931

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1932
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1933
$dbi->reserved_word_quote('"');
1934
$dbi->execute($CREATE_TABLE->{0});
1935
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1936
$dbi->execute($CREATE_TABLE->{2});
1937
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
1938
$rows = $dbi->select(
1939
    table => 'table1',
1940
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
1941
    where   => {'table1.key2' => 2},
1942
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
1943
)->fetch_hash_all;
1944
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
1945
          'reserved_word_quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1946

            
1947
{
1948
    package MyDBI8;
1949
    
1950
    use base 'DBIx::Custom';
1951
    
1952
    sub connect {
1953
        my $self = shift->SUPER::connect(@_);
1954
        
1955
        $self->include_model('MyModel7');
1956
        
1957
        return $self;
1958
    }
1959
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1960

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

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2048
test 'create_model';
2049
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2050
$dbi->execute($CREATE_TABLE->{0});
2051
$dbi->execute($CREATE_TABLE->{2});
2052

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

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

            
2092
test 'merge_param';
2093
{
2094
    my $dbi = DBIx::Custom->new;
2095
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2096
    my $param2 = {key1 => 1, key2 => 2};
2097
    my $param3 = {key1 => 1};
2098
    my $param = $dbi->merge_param($param1, $param2, $param3);
2099
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2100
}
2101

            
2102
test 'select() param option';
2103
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2104
$dbi->execute($CREATE_TABLE->{0});
2105
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2106
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2107
$dbi->execute($CREATE_TABLE->{2});
2108
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2109
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2110
$rows = $dbi->select(
2111
    table => 'table1',
2112
    column => 'table1.key1 as table1_key1, key2, key3',
2113
    where   => {'table1.key2' => 3},
2114
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2115
              ' as table2 on table1.key1 = table2.key1'],
2116
    param => {'table2.key3' => 5}
2117
)->fetch_hash_all;
2118
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2119