DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
1980 lines | 65.205kb
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;
create_model() return model
Yuki Kimoto authored on 2011-03-29
69
my $model2;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
70
my $where;
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
71
my $update_param;
72
my $insert_param;
removed register_format()
yuki-kimoto authored on 2010-05-26
73

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

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

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

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

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

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

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

            
114

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
347

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

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

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

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

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

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

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

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

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

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

            
424

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

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

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

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

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

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

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

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

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

            
471

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

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

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

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

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

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

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

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

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

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

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

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

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

            
565

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

            
570
$dbi->begin_work;
571

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

            
578
$dbi->rollback if $@;
579

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

            
584
$dbi->begin_work;
585

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

            
591
$dbi->commit unless $@;
592

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1226

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

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

            
1235
$dbi->apply_filter(
1236

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1357
{
1358
    package MyDBI4;
1359

            
1360
    use strict;
1361
    use warnings;
1362

            
1363
    use base 'DBIx::Custom';
1364

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

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

            
1378
    use strict;
1379
    use warnings;
1380

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

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

            
1385
    use strict;
1386
    use warnings;
1387

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

            
1390
    sub insert {
1391
        my ($self, $param) = @_;
1392
        
1393
        return $self->SUPER::insert(param => $param);
1394
    }
1395

            
1396
    sub list { shift->select; }
1397

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

            
1400
    use strict;
1401
    use warnings;
1402

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

            
1405
    sub insert {
1406
        my ($self, $param) = @_;
1407
        
1408
        return $self->SUPER::insert(param => $param);
1409
    }
1410

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

            
1423
{
1424
     package MyDBI5;
1425

            
1426
    use strict;
1427
    use warnings;
1428

            
1429
    use base 'DBIx::Custom';
1430

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

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

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

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

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

            
1482
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1483
$dbi->delete_at(
1484
    table => 'table1',
1485
    primary_key => 'key1',
1486
    where => 1,
1487
);
1488
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1489

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

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

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

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

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

            
1540
$dbi->delete_all(table => 'table1');
1541
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1542
$dbi->update_at(
1543
    table => 'table1',
1544
    primary_key => 'key1',
1545
    where => 1,
1546
    param => {key3 => 4}
1547
);
1548
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1549
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1550
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1551

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

            
1566
$dbi->delete_all(table => 'table1');
1567
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1568
$result = $dbi->select_at(
1569
    table => 'table1',
1570
    primary_key => 'key1',
1571
    where => 1,
1572
);
1573
$row = $result->fetch_hash_first;
1574
is($row->{key1}, 1);
1575
is($row->{key2}, 2);
1576
is($row->{key3}, 3);
1577

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

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

            
1599
eval {
1600
    $result = $dbi->update_at(
1601
        table => 'table1',
1602
        primary_key => ['key1', 'key2'],
1603
        where => {},
1604
        param => {key1 => 1, key2 => 2},
1605
    );
1606
};
1607
like($@, qr/must be/);
1608

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

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1618
test 'columns';
1619
use MyDBI1;
1620
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1621
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1622

            
1623

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

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

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

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

            
1689

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

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

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

            
1738

            
1739
eval { $dbi->update_param({";" => 1}) };
1740
like($@, qr/not safety/);
1741

            
1742

            
1743
test 'insert_param';
1744
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1745
$dbi->execute($CREATE_TABLE->{1});
1746
$param = {key1 => 1};
1747
$insert_param = $dbi->insert_param($param);
1748
$sql = <<"EOS";
1749
insert into {table table1} $insert_param
1750
EOS
1751

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

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

            
1758

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

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

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

            
1793
$rows = $dbi->select(
1794
    table => 'table1',
1795
    where   => {'key1' => 1},
1796
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1797
              'left outer join table3 on table2.key3 = table3.key3']
1798
)->fetch_hash_all;
1799
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1800

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

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

            
1819

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

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

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1938
test 'create_model';
1939
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1940
$dbi->execute($CREATE_TABLE->{0});
1941
$dbi->execute($CREATE_TABLE->{2});
1942

            
1943
$dbi->create_model(
1944
    table => 'table1',
1945
    join => [
1946
       'left outer join table2 on table1.key1 = table2.key1'
1947
    ],
1948
    primary_key => ['key1']
1949
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
1950
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1951
    table => 'table2'
1952
);
1953
$dbi->create_model(
1954
    table => 'table3',
1955
    filter => [
1956
        key1 => {in => sub { uc $_[0] }}
1957
    ]
1958
);
1959
$dbi->setup_model;
1960
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1961
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1962
$model = $dbi->model('table1');
1963
$result = $model->select(
1964
    column => [$model->mycolumn, $model->column('table2')],
1965
    where => {'table1.key1' => 1}
1966
);
1967
is_deeply($result->fetch_hash_first,
1968
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
create_model() return model
Yuki Kimoto authored on 2011-03-29
1969
is_deeply($model2->select->fetch_hash_first, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1970

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1971
test 'model method';
1972
test 'create_model';
1973
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1974
$dbi->execute($CREATE_TABLE->{2});
1975
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1976
$model = $dbi->create_model(
1977
    table => 'table2'
1978
);
1979
$model->method(foo => sub { shift->select(@_) });
1980
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3});