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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
113

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
273
$dbi->execute("delete from table1");
274
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
275
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
276
$dbi->register_filter(twice => sub { $_[0] * 2 });
277
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
278
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
279
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
280
$rows   = $result->fetch_hash_all;
281
is_deeply($rows, [{key1 => 1, key2 => 22, 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
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
284

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
293
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
294
$dbi->execute($CREATE_TABLE->{0});
295
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
296
$where = $dbi->where;
297
$where->clause(['and', '{= key1}', '{= key2}']);
298
$where->param({key1 => 1, key2 => 2});
299
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
300
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
301
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
302

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

            
317
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
318
$dbi->execute($CREATE_TABLE->{0});
319
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
320
$where = $dbi->where;
321
$where->clause(['and', '{= key2}']);
322
$where->param({key2 => 2});
323
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
324
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
325
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
326

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
333
test 'update_all';
334
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
335
$dbi->execute($CREATE_TABLE->{1});
336
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
337
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
338
$dbi->register_filter(twice => sub { $_[0] * 2 });
339
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
340
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
341
$rows   = $result->fetch_hash_all;
342
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
343
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
344
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
345

            
346

            
347
test 'delete';
348
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
349
$dbi->execute($CREATE_TABLE->{0});
350
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
351
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
352
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
353
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
354
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
355
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
356

            
357
$dbi->execute("delete from table1;");
358
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
359
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
360
$dbi->register_filter(twice => sub { $_[0] * 2 });
361
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
362
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
363
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
364
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
365

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

            
368
$dbi->delete_all(table => 'table1');
369
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
370
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
371
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
372
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
373
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
374

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
378
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
379
$dbi->execute($CREATE_TABLE->{0});
380
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
381
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
382
$where = $dbi->where;
383
$where->clause(['and', '{= key1}', '{= key2}']);
384
$where->param({ke1 => 1, key2 => 2});
385
$dbi->delete(table => 'table1', where => $where);
386
$result = $dbi->select(table => 'table1');
387
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
388

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
389
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
390
$dbi->execute($CREATE_TABLE->{0});
391
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
392
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
393
$dbi->delete(
394
    table => 'table1',
395
    where => [
396
        ['and', '{= key1}', '{= key2}'],
397
        {ke1 => 1, key2 => 2}
398
    ]
399
);
400
$result = $dbi->select(table => 'table1');
401
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
402

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
413
test 'delete_all';
414
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
415
$dbi->execute($CREATE_TABLE->{0});
416
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
417
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
418
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
419
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
420
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
421
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
422

            
423

            
424
test 'select';
425
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
426
$dbi->execute($CREATE_TABLE->{0});
427
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
428
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
429
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
430
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
431
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
432

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

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

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

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

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

            
450
$dbi->execute($CREATE_TABLE->{2});
451
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
452
$rows = $dbi->select(
453
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
454
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
455
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
456
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
457
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
458
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
459

            
460
$rows = $dbi->select(
461
    table => [qw/table1 table2/],
462
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
463
    relation  => {'table1.key1' => 'table2.key1'}
464
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
465
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
466

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

            
470

            
removed register_format()
yuki-kimoto authored on 2010-05-26
471
test 'fetch filter';
472
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
473
$dbi->register_filter(
474
    twice       => sub { $_[0] * 2 },
475
    three_times => sub { $_[0] * 3 }
476
);
477
$dbi->default_fetch_filter('twice');
478
$dbi->execute($CREATE_TABLE->{0});
479
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
480
$result = $dbi->select(table => 'table1');
481
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
482
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
483
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
484

            
485
test 'filters';
486
$dbi = DBIx::Custom->new;
487

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
494
test 'transaction';
495
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
496
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
497
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
498
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
499
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
500
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
501
$result = $dbi->select(table => 'table1');
502
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
503
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
504

            
505
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
506
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
507
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
508
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
509
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
510

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

            
514
test 'cache';
515
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
516
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
517
$source = 'select * from table1 where {= key1} and {= key2};';
518
$dbi->create_query($source);
519
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
520
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
521

            
522
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
523
$dbi->execute($CREATE_TABLE->{0});
524
$dbi->{_cached} = {};
525
$dbi->cache(0);
526
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
527
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
528

            
add tests
yuki-kimoto authored on 2010-08-10
529
test 'execute';
530
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
531
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
532
{
533
    local $Carp::Verbose = 0;
534
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
535
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
536
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
537
}
538
{
539
    local $Carp::Verbose = 1;
540
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
541
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
542
}
add tests
yuki-kimoto authored on 2010-08-10
543

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
552
{
553
    local $Carp::Verbose = 0;
554
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
555
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
556
}
557
{
558
    local $Carp::Verbose = 1;
559
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
560
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
561
}
cleanup
yuki-kimoto authored on 2010-10-17
562

            
563

            
564
test 'transaction';
565
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
566
$dbi->execute($CREATE_TABLE->{0});
567

            
568
$dbi->begin_work;
569

            
570
eval {
571
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
572
    die "Error";
573
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
574
};
575

            
576
$dbi->rollback if $@;
577

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

            
582
$dbi->begin_work;
583

            
584
eval {
585
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
586
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
587
};
588

            
589
$dbi->commit unless $@;
590

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

            
595
$dbi->dbh->{AutoCommit} = 0;
596
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
597
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
598
$dbi->dbh->{AutoCommit} = 1;
599

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
601
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
602
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
603
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
604
    one => sub { 1 }
605
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
606
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
607
    two => sub { 2 }
608
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
609
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
610
    twice => sub {
611
        my $self = shift;
612
        return $_[0] * 2;
613
    }
614
});
615

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
623
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
624
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
625
$dbi->execute($CREATE_TABLE->{0});
626
$dbi->register_filter(twice => sub { $_[0] * 2 });
627
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
628
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
629
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
630
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
631
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
632
$result = $dbi->execute($SELECT_SOURCES->{0});
633
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
634
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
635
$result = $dbi->select(table => 'table1');
636
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
637
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
638

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
639
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
640
$dbi->execute($CREATE_TABLE->{0});
641
$dbi->register_filter(twice => sub { $_[0] * 2 });
642
$dbi->register_filter(three_times => sub { $_[0] * 3});
643
$dbi->apply_filter(
644
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
645
              'key2' => {out => 'three_times', in => 'twice'});
646
$dbi->apply_filter(
647
    'table1', 'key1' => {out => undef}
648
); 
649
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
650
$result = $dbi->execute($SELECT_SOURCES->{0});
651
$row   = $result->fetch_hash_first;
652
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
653

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
654
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
655
$dbi->execute($CREATE_TABLE->{0});
656
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
657
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
658
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
659
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
660
$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
661
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
662
$result = $dbi->execute($SELECT_SOURCES->{0});
663
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
664
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
665

            
666
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
667
$dbi->execute($CREATE_TABLE->{0});
668
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
669
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
670
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
671
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
672
$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
673
$dbi->delete(table => 'table1', where => {key1 => 1});
674
$result = $dbi->execute($SELECT_SOURCES->{0});
675
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
676
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
677

            
678
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
679
$dbi->execute($CREATE_TABLE->{0});
680
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
681
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
682
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
683
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
684
$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
685
$result = $dbi->select(table => 'table1', where => {key1 => 1});
686
$result->filter({'key2' => 'twice'});
687
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
688
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
689

            
690
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
691
$dbi->execute($CREATE_TABLE->{0});
692
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
693
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
694
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
695
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
696
$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
697
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
698
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
699
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
700
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
701
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
702

            
add table tag
Yuki Kimoto authored on 2011-02-09
703
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
704
$dbi->execute($CREATE_TABLE->{0});
705
$dbi->register_filter(twice => sub { $_[0] * 2 });
706
$dbi->apply_filter(
707
    'table1', 'key1' => {out => 'twice', in => 'twice'}
708
);
709
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
710
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
711
                        param => {key1 => 1, key2 => 2});
712
$rows   = $result->fetch_hash_all;
713
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
714

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
715
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
716
$dbi->execute($CREATE_TABLE->{0});
717
$dbi->execute($CREATE_TABLE->{2});
718
$dbi->register_filter(twice => sub { $_[0] * 2 });
719
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
720
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
721
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
722
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
723
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
724
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
725
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
726
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
727
$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
728
$result = $dbi->select(
729
     table => ['table1', 'table2'],
730
     column => ['key2', 'key3'],
731
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
732

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

            
737
$result = $dbi->select(
738
     table => ['table1', 'table2'],
739
     column => ['key2', 'key3'],
740
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
741

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
746
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
747
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
748
$dbi->execute($CREATE_TABLE->{2});
749
$dbi->execute($CREATE_TABLE->{3});
750

            
751
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
752
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
753
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
754
    
755
    if ($table =~ /^table/) {
756
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
757
         push @$infos, $info;
758
    }
759
});
760
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
761
is_deeply($infos, 
762
    [
763
        ['table1', 'key1', 'key1'],
764
        ['table1', 'key2', 'key2'],
765
        ['table2', 'key1', 'key1'],
766
        ['table2', 'key3', 'key3']
767
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
768
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
769
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
770

            
add examples
Yuki Kimoto authored on 2011-01-07
771
test 'limit';
772
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
773
$dbi->execute($CREATE_TABLE->{0});
774
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
775
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
776
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
777
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
778
    limit => sub {
779
        my ($count, $offset) = @_;
780
        
781
        my $s = '';
782
        $s .= "limit $count";
783
        $s .= " offset $offset" if defined $offset;
784
        
785
        return [$s, []];
786
    }
787
);
788
$rows = $dbi->select(
789
  table => 'table1',
790
  where => {key1 => 1},
791
  append => "order by key2 {limit 1 0}"
792
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
793
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
794
$rows = $dbi->select(
795
  table => 'table1',
796
  where => {key1 => 1},
797
  append => "order by key2 {limit 2 1}"
798
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
799
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
800
$rows = $dbi->select(
801
  table => 'table1',
802
  where => {key1 => 1},
803
  append => "order by key2 {limit 1}"
804
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
805
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
806

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
807
test 'connect super';
808
{
809
    package MyDBI;
810
    
811
    use base 'DBIx::Custom';
812
    sub connect {
813
        my $self = shift->SUPER::connect(@_);
814
        
815
        return $self;
816
    }
817
    
818
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
819
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
820
        
821
        return $self;
822
    }
823
}
824

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
836
{
837
    package MyDBI2;
838
    
839
    use base 'DBIx::Custom';
840
    sub connect {
841
        my $self = shift->SUPER::new(@_);
842
        $self->connect;
843
        
844
        return $self;
845
    }
846
}
847

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

            
853
test 'end_filter';
854
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
855
$dbi->execute($CREATE_TABLE->{0});
856
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
857
$result = $dbi->select(table => 'table1');
858
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
859
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
860
$row = $result->fetch_first;
861
is_deeply($row, [6, 40]);
862

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
863
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
864
$dbi->execute($CREATE_TABLE->{0});
865
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
866
$result = $dbi->select(table => 'table1');
867
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
868
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
869
$row = $result->fetch_first;
870
is_deeply($row, [6, 12]);
871

            
872
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
873
$dbi->execute($CREATE_TABLE->{0});
874
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
875
$result = $dbi->select(table => 'table1');
876
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
877
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
878
$row = $result->fetch_first;
879
is_deeply($row, [6, 12]);
880

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
888
$dbi->register_filter(five_times => sub { $_[0] * 5 });
889
$dbi->apply_filter('table1',
890
    key1 => {end => sub { $_[0] * 3 } },
891
    key2 => {end => 'five_times'}
892
);
893
$result = $dbi->select(table => 'table1');
894
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
895
$row = $result->fetch_hash_first;
896
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
897

            
898
$dbi->register_filter(five_times => sub { $_[0] * 5 });
899
$dbi->apply_filter('table1',
900
    key1 => {end => sub { $_[0] * 3 } },
901
    key2 => {end => 'five_times'}
902
);
903
$result = $dbi->select(table => 'table1');
904
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
905
$result->filter(key1 => undef);
906
$result->end_filter(key1 => undef);
907
$row = $result->fetch_hash_first;
908
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
909

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
910
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
911
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
912
$dbi->execute($CREATE_TABLE->{0});
913
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
914
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
915
$row = $result
916
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
917
       ->remove_filter
918
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
919
       ->remove_end_filter
920
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
921
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
922

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
923
test 'empty where select';
924
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
925
$dbi->execute($CREATE_TABLE->{0});
926
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
927
$result = $dbi->select(table => 'table1', where => {});
928
$row = $result->fetch_hash_first;
929
is_deeply($row, {key1 => 1, key2 => 2});
930

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
931
test 'select query option';
932
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
933
$dbi->execute($CREATE_TABLE->{0});
934
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
935
is(ref $query, 'DBIx::Custom::Query');
936
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
937
is(ref $query, 'DBIx::Custom::Query');
938
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
939
is(ref $query, 'DBIx::Custom::Query');
940
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
941
is(ref $query, 'DBIx::Custom::Query');
942

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
943
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
944
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
945
$dbi->execute($CREATE_TABLE->{0});
946
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
947
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
948
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
949
is("$where", "where ( {= key1} and {= key2} )", 'no param');
950

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
955
$result = $dbi->select(
956
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
957
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
958
);
959
$row = $result->fetch_hash_all;
960
is_deeply($row, [{key1 => 1, key2 => 2}]);
961

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
962
$result = $dbi->select(
963
    table => 'table1',
964
    where => [
965
        ['and', '{= key1}', '{= key2}'],
966
        {key1 => 1}
967
    ]
968
);
969
$row = $result->fetch_hash_all;
970
is_deeply($row, [{key1 => 1, key2 => 2}]);
971

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
972
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
973
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
974
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
975
$result = $dbi->select(
976
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
977
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
978
);
979
$row = $result->fetch_hash_all;
980
is_deeply($row, [{key1 => 1, key2 => 2}]);
981

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
982
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
983
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
984
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
985
$result = $dbi->select(
986
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
987
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
988
);
989
$row = $result->fetch_hash_all;
990
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
991

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
992
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
993
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
994
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
995
$result = $dbi->select(
996
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
997
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
998
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
999
$row = $result->fetch_hash_all;
1000
is_deeply($row, [{key1 => 1, key2 => 2}]);
1001

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1002
$where = $dbi->where;
1003
$result = $dbi->select(
1004
    table => 'table1',
1005
    where => $where
1006
);
1007
$row = $result->fetch_hash_all;
1008
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1009

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1010
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1011
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1012
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1013
$result = $dbi->select(
1014
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1015
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1016
);
1017
};
1018
ok($@);
1019

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

            
added test
Yuki Kimoto authored on 2011-01-19
1023
$where = $dbi->where
1024
             ->clause(['or', ('{= key1}') x 2])
1025
             ->param({key1 => [1, 3]});
1026
$result = $dbi->select(
1027
    table => 'table1',
1028
    where => $where,
1029
);
1030
$row = $result->fetch_hash_all;
1031
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1032

            
1033
$where = $dbi->where
1034
             ->clause(['or', ('{= key1}') x 2])
1035
             ->param({key1 => [1]});
1036
$result = $dbi->select(
1037
    table => 'table1',
1038
    where => $where,
1039
);
1040
$row = $result->fetch_hash_all;
1041
is_deeply($row, [{key1 => 1, key2 => 2}]);
1042

            
1043
$where = $dbi->where
1044
             ->clause(['or', ('{= key1}') x 2])
1045
             ->param({key1 => 1});
1046
$result = $dbi->select(
1047
    table => 'table1',
1048
    where => $where,
1049
);
1050
$row = $result->fetch_hash_all;
1051
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1052

            
many changed
Yuki Kimoto authored on 2011-01-23
1053
$where = $dbi->where
1054
             ->clause('{= key1}')
1055
             ->param({key1 => 1});
1056
$result = $dbi->select(
1057
    table => 'table1',
1058
    where => $where,
1059
);
1060
$row = $result->fetch_hash_all;
1061
is_deeply($row, [{key1 => 1, key2 => 2}]);
1062

            
1063
$where = $dbi->where
1064
             ->clause('{= key1} {= key2}')
1065
             ->param({key1 => 1});
1066
eval{$where->to_string};
1067
like($@, qr/one column/);
1068

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1069
$where = $dbi->where
1070
             ->clause('{= key1}')
1071
             ->param([]);
1072
eval{$where->to_string};
1073
like($@, qr/Parameter/);
1074

            
1075
$where = $dbi->where
1076
             ->clause(['or', ('{= key1}') x 3])
1077
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1078
$result = $dbi->select(
1079
    table => 'table1',
1080
    where => $where,
1081
);
1082
$row = $result->fetch_hash_all;
1083
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1084

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

            
1095
$where = $dbi->where
1096
             ->clause(['or', ('{= key1}') x 3])
1097
             ->param({key1 => [1, 3, $dbi->not_exists]});
1098
$result = $dbi->select(
1099
    table => 'table1',
1100
    where => $where,
1101
);
1102
$row = $result->fetch_hash_all;
1103
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1104

            
1105
$where = $dbi->where
1106
             ->clause(['or', ('{= key1}') x 3])
1107
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1108
$result = $dbi->select(
1109
    table => 'table1',
1110
    where => $where,
1111
);
1112
$row = $result->fetch_hash_all;
1113
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1114

            
1115
$where = $dbi->where
1116
             ->clause(['or', ('{= key1}') x 3])
1117
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1118
$result = $dbi->select(
1119
    table => 'table1',
1120
    where => $where,
1121
);
1122
$row = $result->fetch_hash_all;
1123
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1124

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

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

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1145
$where = $dbi->where
1146
             ->clause(['or', ('{= key1}') x 3])
1147
             ->param({key1 => []});
1148
$result = $dbi->select(
1149
    table => 'table1',
1150
    where => $where,
1151
);
1152
$row = $result->fetch_hash_all;
1153
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1154

            
1155
$where = $dbi->where
1156
             ->clause(['and', '{> key1}', '{< key1}' ])
1157
             ->param({key1 => [2, $dbi->not_exists]});
1158
$result = $dbi->select(
1159
    table => 'table1',
1160
    where => $where,
1161
);
1162
$row = $result->fetch_hash_all;
1163
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1164

            
1165
$where = $dbi->where
1166
             ->clause(['and', '{> key1}', '{< key1}' ])
1167
             ->param({key1 => [$dbi->not_exists, 2]});
1168
$result = $dbi->select(
1169
    table => 'table1',
1170
    where => $where,
1171
);
1172
$row = $result->fetch_hash_all;
1173
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1174

            
1175
$where = $dbi->where
1176
             ->clause(['and', '{> key1}', '{< key1}' ])
1177
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1178
$result = $dbi->select(
1179
    table => 'table1',
1180
    where => $where,
1181
);
1182
$row = $result->fetch_hash_all;
1183
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1184

            
1185
$where = $dbi->where
1186
             ->clause(['and', '{> key1}', '{< key1}' ])
1187
             ->param({key1 => [0, 2]});
1188
$result = $dbi->select(
1189
    table => 'table1',
1190
    where => $where,
1191
);
1192
$row = $result->fetch_hash_all;
1193
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1194

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1199
test 'register_tag_processor';
1200
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1201
$dbi->register_tag_processor(
1202
    a => sub { 1 }
1203
);
1204
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1205

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1206
test 'register_tag';
1207
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1208
$dbi->register_tag(
1209
    b => sub { 2 }
1210
);
1211
is($dbi->query_builder->tags->{b}->(), 2);
1212

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1213
test 'table not specify exception';
1214
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1215
eval {$dbi->insert};
1216
like($@, qr/table/);
1217
eval {$dbi->update};
1218
like($@, qr/table/);
1219
eval {$dbi->delete};
1220
like($@, qr/table/);
1221
eval {$dbi->select};
1222
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1223

            
1224

            
1225
test 'more tests';
1226
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1227
eval{$dbi->apply_filter('table', 'column', [])};
1228
like($@, qr/apply_filter/);
1229

            
1230
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1231
like($@, qr/apply_filter/);
1232

            
1233
$dbi->apply_filter(
1234

            
1235
);
1236
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1237
$dbi->execute($CREATE_TABLE->{0});
1238
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1239
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1240
$dbi->apply_filter('table1', 'key2', 
1241
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1242
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1243
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1244

            
1245
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1246
$dbi->execute($CREATE_TABLE->{0});
1247
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1248
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1249
$dbi->apply_filter('table1', 'key2', {});
1250
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1251
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1252

            
1253
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1254
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1255
like($@, qr/not registered/);
1256
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1257
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1258
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1259
is($dbi->one, 1);
1260

            
1261
eval{DBIx::Custom->connect()};
1262
like($@, qr/connect/);
1263

            
1264
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1265
$dbi->execute($CREATE_TABLE->{0});
1266
$dbi->register_filter(twice => sub { $_[0] * 2 });
1267
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1268
             filter => {key1 => 'twice'});
1269
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1270
is_deeply($row, {key1 => 2, key2 => 2});
1271
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1272
             filter => {key1 => 'no'}) };
1273
like($@, qr//);
1274

            
1275
$dbi->register_filter(one => sub { });
1276
$dbi->default_fetch_filter('one');
1277
ok($dbi->default_fetch_filter);
1278
$dbi->default_bind_filter('one');
1279
ok($dbi->default_bind_filter);
1280
eval{$dbi->default_fetch_filter('no')};
1281
like($@, qr/not registered/);
1282
eval{$dbi->default_bind_filter('no')};
1283
like($@, qr/not registered/);
1284
$dbi->default_bind_filter(undef);
1285
ok(!defined $dbi->default_bind_filter);
1286
$dbi->default_fetch_filter(undef);
1287
ok(!defined $dbi->default_fetch_filter);
1288
eval {$dbi->execute('select * from table1 {= author') };
1289
like($@, qr/Tag not finished/);
1290

            
1291
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1292
$dbi->execute($CREATE_TABLE->{0});
1293
$dbi->register_filter(one => sub { 1 });
1294
$result = $dbi->select(table => 'table1');
1295
eval {$result->filter(key1 => 'no')};
1296
like($@, qr/not registered/);
1297
eval {$result->end_filter(key1 => 'no')};
1298
like($@, qr/not registered/);
1299
$result->default_filter(undef);
1300
ok(!defined $result->default_filter);
1301
$result->default_filter('one');
1302
is($result->default_filter->(), 1);
1303

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1304
test 'dbi_option';
1305
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1306
                             dbi_option => {PrintError => 1});
1307
ok($dbi->dbh->{PrintError});
1308
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1309
                             dbi_options => {PrintError => 1});
1310
ok($dbi->dbh->{PrintError});
1311

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1312
test 'DBIx::Custom::Result stash()';
1313
$result = DBIx::Custom::Result->new;
1314
is_deeply($result->stash, {}, 'default');
1315
$result->stash->{foo} = 1;
1316
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1317

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1318
test 'filter __ expression';
1319
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1320
$dbi->execute('create table company (id, name, location_id)');
1321
$dbi->execute('create table location (id, name)');
1322
$dbi->apply_filter('location',
1323
  name => {in => sub { uc $_[0] } }
1324
);
1325

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

            
1329
$result = $dbi->select(
1330
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1331
    column => ['location.name as location__name']
1332
);
1333
is($result->fetch_first->[0], 'B');
1334

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1335
$result = $dbi->select(
1336
    table => 'company', relation => {'company.location_id' => 'location.id'},
1337
    column => ['location.name as location__name']
1338
);
1339
is($result->fetch_first->[0], 'B');
1340

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1341
test 'selection';
1342
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1343
$dbi->execute($CREATE_TABLE->{0});
1344
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1345
$result = $dbi->select(selection => '* from {table table1}', where => {key1 => 1});
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1346
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]);
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1347

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1348
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1349
use MyDBI1;
1350
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1351
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1352
$model = $dbi->model('book');
1353
$model->insert({title => 'a', author => 'b'});
1354
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1355
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1356
$model = $dbi->model('company');
1357
$model->insert({name => 'a'});
1358
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1359
is($dbi->models->{'book'}, $dbi->model('book'));
1360
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1361

            
1362
{
1363
    package MyDBI4;
1364

            
1365
    use strict;
1366
    use warnings;
1367

            
1368
    use base 'DBIx::Custom';
1369

            
1370
    sub connect {
1371
        my $self = shift->SUPER::connect(@_);
1372
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1373
        $self->include_model(
1374
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1375
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1376
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1377
            ]
1378
        );
1379
    }
1380

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

            
1383
    use strict;
1384
    use warnings;
1385

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

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

            
1390
    use strict;
1391
    use warnings;
1392

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

            
1395
    sub insert {
1396
        my ($self, $param) = @_;
1397
        
1398
        return $self->SUPER::insert(param => $param);
1399
    }
1400

            
1401
    sub list { shift->select; }
1402

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

            
1405
    use strict;
1406
    use warnings;
1407

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

            
1410
    sub insert {
1411
        my ($self, $param) = @_;
1412
        
1413
        return $self->SUPER::insert(param => $param);
1414
    }
1415

            
1416
    sub list { shift->select; }
1417
}
1418
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1419
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1420
$model = $dbi->model('book');
1421
$model->insert({title => 'a', author => 'b'});
1422
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1423
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1424
$model = $dbi->model('company');
1425
$model->insert({name => 'a'});
1426
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1427

            
1428
{
1429
     package MyDBI5;
1430

            
1431
    use strict;
1432
    use warnings;
1433

            
1434
    use base 'DBIx::Custom';
1435

            
1436
    sub connect {
1437
        my $self = shift->SUPER::connect(@_);
1438
        
1439
        $self->include_model('MyModel4');
1440
    }
1441
}
1442
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1443
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1444
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1445
$model = $dbi->model('company');
1446
$model->insert({name => 'a'});
1447
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1448
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1449
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1450
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1451

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1452
test 'primary_key';
1453
use MyDBI1;
1454
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1455
$model = $dbi->model('book');
1456
$model->primary_key(['id', 'number']);
1457
is_deeply($model->primary_key, ['id', 'number']);
1458

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1459
test 'columns';
1460
use MyDBI1;
1461
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1462
$model = $dbi->model('book');
1463
$model->columns(['id', 'number']);
1464
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1465

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1466
test 'setup_model';
1467
use MyDBI1;
1468
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1469
$dbi->execute('create table book (id)');
1470
$dbi->execute('create table company (id, name);');
1471
$dbi->execute('create table test (id, name, primary key (id, name));');
1472
$dbi->setup_model;
1473
is_deeply($dbi->model('book')->columns, ['id']);
1474
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1475

            
1476
test 'delete_at';
1477
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1478
$dbi->execute($CREATE_TABLE->{1});
1479
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1480
$dbi->delete_at(
1481
    table => 'table1',
1482
    primary_key => ['key1', 'key2'],
1483
    where => [1, 2],
1484
);
1485
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1486

            
1487
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1488
$dbi->delete_at(
1489
    table => 'table1',
1490
    primary_key => 'key1',
1491
    where => 1,
1492
);
1493
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1494

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1495
test 'insert_at';
1496
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1497
$dbi->execute($CREATE_TABLE->{1});
1498
$dbi->insert_at(
1499
    primary_key => ['key1', 'key2'], 
1500
    table => 'table1',
1501
    where => [1, 2],
1502
    param => {key3 => 3}
1503
);
1504
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1505
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1506
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1507

            
1508
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1509
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1510
$dbi->insert_at(
1511
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1512
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1513
    where => 1,
1514
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1515
);
1516

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

            
1521
eval {
1522
    $dbi->insert_at(
1523
        table => 'table1',
1524
        primary_key => ['key1', 'key2'],
1525
        where => {},
1526
        param => {key1 => 1, key2 => 2, key3 => 3},
1527
    );
1528
};
1529
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1530

            
1531
test 'update_at';
1532
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1533
$dbi->execute($CREATE_TABLE->{1});
1534
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1535
$dbi->update_at(
1536
    table => 'table1',
1537
    primary_key => ['key1', 'key2'],
1538
    where => [1, 2],
1539
    param => {key3 => 4}
1540
);
1541
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1542
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1543
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1544

            
1545
$dbi->delete_all(table => 'table1');
1546
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1547
$dbi->update_at(
1548
    table => 'table1',
1549
    primary_key => 'key1',
1550
    where => 1,
1551
    param => {key3 => 4}
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}, 4);
1556

            
1557
test 'select_at';
1558
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1559
$dbi->execute($CREATE_TABLE->{1});
1560
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1561
$result = $dbi->select_at(
1562
    table => 'table1',
1563
    primary_key => ['key1', 'key2'],
1564
    where => [1, 2]
1565
);
1566
$row = $result->fetch_hash_first;
1567
is($row->{key1}, 1);
1568
is($row->{key2}, 2);
1569
is($row->{key3}, 3);
1570

            
1571
$dbi->delete_all(table => 'table1');
1572
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1573
$result = $dbi->select_at(
1574
    table => 'table1',
1575
    primary_key => 'key1',
1576
    where => 1,
1577
);
1578
$row = $result->fetch_hash_first;
1579
is($row->{key1}, 1);
1580
is($row->{key2}, 2);
1581
is($row->{key3}, 3);
1582

            
1583
$dbi->delete_all(table => 'table1');
1584
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1585
$result = $dbi->select_at(
1586
    table => 'table1',
1587
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1588
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1589
);
1590
$row = $result->fetch_hash_first;
1591
is($row->{key1}, 1);
1592
is($row->{key2}, 2);
1593
is($row->{key3}, 3);
1594

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1595
eval {
1596
    $result = $dbi->select_at(
1597
        table => 'table1',
1598
        primary_key => ['key1', 'key2'],
1599
        where => {},
1600
    );
1601
};
1602
like($@, qr/must be/);
1603

            
1604
eval {
1605
    $result = $dbi->update_at(
1606
        table => 'table1',
1607
        primary_key => ['key1', 'key2'],
1608
        where => {},
1609
        param => {key1 => 1, key2 => 2},
1610
    );
1611
};
1612
like($@, qr/must be/);
1613

            
1614
eval {
1615
    $result = $dbi->delete_at(
1616
        table => 'table1',
1617
        primary_key => ['key1', 'key2'],
1618
        where => {},
1619
    );
1620
};
1621
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1622

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1623
test 'columns';
1624
use MyDBI1;
1625
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1626
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1627

            
1628

            
1629
test 'model delete_at';
1630
{
1631
    package MyDBI6;
1632
    
1633
    use base 'DBIx::Custom';
1634
    
1635
    sub connect {
1636
        my $self = shift->SUPER::connect(@_);
1637
        
1638
        $self->include_model('MyModel5');
1639
        
1640
        return $self;
1641
    }
1642
}
1643
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1644
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1645
$dbi->execute("create table table2 (key1, key2, key3)");
1646
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1647
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1648
$dbi->model('table1')->delete_at(where => [1, 2]);
1649
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1650
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1651
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1652
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1653
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1654
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1655
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1656

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1657
test 'model insert_at';
1658
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1659
$dbi->execute($CREATE_TABLE->{1});
1660
$dbi->model('table1')->insert_at(
1661
    where => [1, 2],
1662
    param => {key3 => 3}
1663
);
1664
$result = $dbi->model('table1')->select;
1665
$row = $result->fetch_hash_first;
1666
is($row->{key1}, 1);
1667
is($row->{key2}, 2);
1668
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1669

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1670
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1671
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1672
$dbi->execute($CREATE_TABLE->{1});
1673
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1674
$dbi->model('table1')->update_at(
1675
    where => [1, 2],
1676
    param => {key3 => 4}
1677
);
1678
$result = $dbi->model('table1')->select;
1679
$row = $result->fetch_hash_first;
1680
is($row->{key1}, 1);
1681
is($row->{key2}, 2);
1682
is($row->{key3}, 4);
1683

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1684
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1685
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1686
$dbi->execute($CREATE_TABLE->{1});
1687
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1688
$result = $dbi->model('table1')->select_at(where => [1, 2]);
1689
$row = $result->fetch_hash_first;
1690
is($row->{key1}, 1);
1691
is($row->{key2}, 2);
1692
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1693

            
1694

            
cleanup
Yuki Kimoto authored on 2011-03-21
1695
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1696
{
1697
    package MyDBI7;
1698
    
1699
    use base 'DBIx::Custom';
1700
    
1701
    sub connect {
1702
        my $self = shift->SUPER::connect(@_);
1703
        
1704
        $self->include_model('MyModel6');
1705
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1706
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1707
        return $self;
1708
    }
1709
}
1710
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1711
$dbi->execute($CREATE_TABLE->{0});
1712
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1713
$dbi->setup_model;
1714
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1715
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1716
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1717
$result = $model->select(
1718
    column => [$model->mycolumn, $model->column('table2')],
1719
    where => {'table1.key1' => 1}
1720
);
1721
is_deeply($result->fetch_hash_first,
1722
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1723

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

            
1730
$param = {key2 => 11};
1731
$update_param = $dbi->update_param($param);
1732
$sql = <<"EOS";
1733
update {table table1} $update_param
1734
where key1 = 1
1735
EOS
1736
$dbi->execute($sql, param => $param);
1737
$result = $dbi->execute($SELECT_SOURCES->{0});
1738
$rows   = $result->fetch_hash_all;
1739
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1740
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1741
                  "basic");
1742

            
1743

            
1744
eval { $dbi->update_param({";" => 1}) };
1745
like($@, qr/not safety/);
1746

            
1747

            
1748
test 'insert_param';
1749
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1750
$dbi->execute($CREATE_TABLE->{1});
1751
$param = {key1 => 1};
1752
$insert_param = $dbi->insert_param($param);
1753
$sql = <<"EOS";
1754
insert into {table table1} $insert_param
1755
EOS
1756

            
1757
$dbi->execute($sql, param => $param);
1758
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1759

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

            
1763

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1764
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1765
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1766
$dbi->execute($CREATE_TABLE->{0});
1767
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1768
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1769
$dbi->execute($CREATE_TABLE->{2});
1770
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1771
$dbi->execute($CREATE_TABLE->{4});
1772
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1773
$rows = $dbi->select(
1774
    table => 'table1',
1775
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1776
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1777
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1778
)->fetch_hash_all;
1779
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1780

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1781
$rows = $dbi->select(
1782
    table => 'table1',
1783
    where   => {'key1' => 1},
1784
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1785
)->fetch_hash_all;
1786
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1787

            
cleanup
Yuki Kimoto authored on 2011-03-08
1788
eval {
1789
    $rows = $dbi->select(
1790
        table => 'table1',
1791
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1792
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1793
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1794
    );
1795
};
1796
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1797

            
1798
$rows = $dbi->select(
1799
    table => 'table1',
1800
    where   => {'key1' => 1},
1801
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1802
              'left outer join table3 on table2.key3 = table3.key3']
1803
)->fetch_hash_all;
1804
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1805

            
1806
$rows = $dbi->select(
1807
    column => 'table3.key4 as table3__key4',
1808
    table => 'table1',
1809
    where   => {'table1.key1' => 1},
1810
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1811
              'left outer join table3 on table2.key3 = table3.key3']
1812
)->fetch_hash_all;
1813
is_deeply($rows, [{table3__key4 => 4}]);
1814

            
1815
$rows = $dbi->select(
1816
    column => 'table1.key1 as table1__key1',
1817
    table => 'table1',
1818
    where   => {'table3.key4' => 4},
1819
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1820
              'left outer join table3 on table2.key3 = table3.key3']
1821
)->fetch_hash_all;
1822
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1823

            
1824

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1825
test 'model join and column attribute and all_column option';
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1826
{
1827
    package MyDBI8;
1828
    
1829
    use base 'DBIx::Custom';
1830
    
1831
    sub connect {
1832
        my $self = shift->SUPER::connect(@_);
1833
        
1834
        $self->include_model('MyModel7');
1835
        
1836
        return $self;
1837
    }
1838
}
1839
$dbi = MyDBI8->connect($NEW_ARGS->{0});
1840
$dbi->execute($CREATE_TABLE->{0});
1841
$dbi->execute($CREATE_TABLE->{2});
1842
$dbi->setup_model;
1843
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1844
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1845
$model = $dbi->model('table1');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1846
$result = $model->select_at(
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1847
    column => {table => ['table1', 'table2'], prepend => 'table1.key1 as key1_1,'},
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1848
    where => 1
1849
);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1850
is_deeply($result->fetch_hash_first,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1851
          {key1_1 => 1, key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1852
$result = $model->select(column => {all => 1});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1853
is_deeply($result->fetch_hash_first,
1854
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1855

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1856
test 'mycolumn';
1857
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1858
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1859
$dbi->execute($CREATE_TABLE->{2});
1860
$dbi->setup_model;
1861
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1862
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1863
$model = $dbi->model('table1');
1864
$result = $model->select_at(
1865
    column => [
1866
        $model->mycolumn,
1867
        $model->column('table2')
1868
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1869
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1870
is_deeply($result->fetch_hash_first,
1871
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1872
$result = $model->select_at(
1873
    column => [
1874
        $model->mycolumn(['key1']),
1875
        $model->column(table2 => ['key1'])
1876
    ]
1877
);
1878
is_deeply($result->fetch_hash_first,
1879
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1880

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1881
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1882
{
1883
    package MyDBI9;
1884
    
1885
    use base 'DBIx::Custom';
1886
    
1887
    sub connect {
1888
        my $self = shift->SUPER::connect(@_);
1889
        
1890
        $self->include_model('MyModel8')->setup_model;
1891
        
1892
        return $self;
1893
    }
1894
}
1895
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1896
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1897
$model = $dbi->model('table1');
1898
eval{$model->execute('select * from table1')};
1899
ok(!$@);
1900

            
1901
test 'table_alias';
1902
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1903
$dbi->execute($CREATE_TABLE->{0});
1904
$dbi->execute($CREATE_TABLE->{2});
1905
$dbi->setup_model;
1906
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
1907
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
1908
$model = $dbi->model('table1');
1909
$result = $model->select(
1910
    column => [
1911
        $model->column('table2_alias')
1912
    ],
1913
    where => {'table2_alias.key3' => 2}
1914
);
1915
is_deeply($result->fetch_hash_first, 
1916
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
1917

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1918
test 'type() option';
1919
$dbi = DBIx::Custom->connect(
1920
    data_source => 'dbi:SQLite:dbname=:memory:',
1921
    dbi_option => {
1922
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
1923
    }
1924
);
1925
my $binary = pack("I3", 1, 2, 3);
1926
$dbi->execute('create table table1(key1, key2)');
1927
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
1928
$result = $dbi->select(table => 'table1');
1929
$row   = $result->fetch_hash_first;
1930
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
1931
$result = $dbi->execute('select length(key1) as key1_length from table1');
1932
$row = $result->fetch_hash_first;
1933
is($row->{key1_length}, length $binary);
1934

            
1935
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
1936
$result = $dbi->select(table => 'table1');
1937
$row   = $result->fetch_hash_first;
1938
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
1939
$result = $dbi->execute('select length(key1) as key1_length from table1');
1940
$row = $result->fetch_hash_first;
1941
is($row->{key1_length}, length $binary);
1942

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1943
test 'create_model';
1944
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1945
$dbi->execute($CREATE_TABLE->{0});
1946
$dbi->execute($CREATE_TABLE->{2});
1947

            
1948
$dbi->create_model(
1949
    table => 'table1',
1950
    join => [
1951
       'left outer join table2 on table1.key1 = table2.key1'
1952
    ],
1953
    primary_key => ['key1']
1954
);
1955
$dbi->create_model(
1956
    table => 'table2'
1957
);
1958
$dbi->create_model(
1959
    table => 'table3',
1960
    filter => [
1961
        key1 => {in => sub { uc $_[0] }}
1962
    ]
1963
);
1964
$dbi->setup_model;
1965
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1966
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1967
$model = $dbi->model('table1');
1968
$result = $model->select(
1969
    column => [$model->mycolumn, $model->column('table2')],
1970
    where => {'table1.key1' => 1}
1971
);
1972
is_deeply($result->fetch_hash_first,
1973
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
1974