DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
2127 lines | 71.633kb
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;
removed register_format()
yuki-kimoto authored on 2010-05-26
75

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

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

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

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

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

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

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

            
116

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
383

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

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

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

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

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

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

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

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

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

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

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

            
470

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
619

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

            
624
$dbi->begin_work;
625

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

            
632
$dbi->rollback if $@;
633

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

            
638
$dbi->begin_work;
639

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

            
645
$dbi->commit unless $@;
646

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1280

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

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

            
1289
$dbi->apply_filter(
1290

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1411
{
1412
    package MyDBI4;
1413

            
1414
    use strict;
1415
    use warnings;
1416

            
1417
    use base 'DBIx::Custom';
1418

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

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

            
1432
    use strict;
1433
    use warnings;
1434

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

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

            
1439
    use strict;
1440
    use warnings;
1441

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

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

            
1450
    sub list { shift->select; }
1451

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

            
1454
    use strict;
1455
    use warnings;
1456

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

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

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

            
1477
{
1478
     package MyDBI5;
1479

            
1480
    use strict;
1481
    use warnings;
1482

            
1483
    use base 'DBIx::Custom';
1484

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1677

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

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

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

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

            
1743

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

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

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

            
1792

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

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

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

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

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

            
1833

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

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

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

            
1861

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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