DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
1975 lines | 65.066kb
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});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
516
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
517
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
518
$source = 'select * from table1 where {= key1} and {= key2};';
519
$dbi->create_query($source);
520
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
521
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
522

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

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

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

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

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

            
564

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

            
569
$dbi->begin_work;
570

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

            
577
$dbi->rollback if $@;
578

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

            
583
$dbi->begin_work;
584

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

            
590
$dbi->commit unless $@;
591

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1225

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

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

            
1234
$dbi->apply_filter(
1235

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1363
{
1364
    package MyDBI4;
1365

            
1366
    use strict;
1367
    use warnings;
1368

            
1369
    use base 'DBIx::Custom';
1370

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

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

            
1384
    use strict;
1385
    use warnings;
1386

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

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

            
1391
    use strict;
1392
    use warnings;
1393

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

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

            
1402
    sub list { shift->select; }
1403

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

            
1406
    use strict;
1407
    use warnings;
1408

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

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

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

            
1429
{
1430
     package MyDBI5;
1431

            
1432
    use strict;
1433
    use warnings;
1434

            
1435
    use base 'DBIx::Custom';
1436

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

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

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

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

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

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

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

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

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

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

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

            
1546
$dbi->delete_all(table => 'table1');
1547
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1548
$dbi->update_at(
1549
    table => 'table1',
1550
    primary_key => 'key1',
1551
    where => 1,
1552
    param => {key3 => 4}
1553
);
1554
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1555
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1556
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1557

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

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

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

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

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

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

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

            
1629

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

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

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

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

            
1695

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

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

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

            
1744

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

            
1748

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

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

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

            
1764

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

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

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

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

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

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

            
1825

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

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

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

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

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

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

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

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