DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
1987 lines | 65.517kb
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 experimental selection o...
Yuki Kimoto authored on 2011-02-09
1343
test 'selection';
1344
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1345
$dbi->execute($CREATE_TABLE->{0});
1346
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1347
$result = $dbi->select(selection => '* from {table table1}', where => {key1 => 1});
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1348
is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]);
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1349

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

            
1364
{
1365
    package MyDBI4;
1366

            
1367
    use strict;
1368
    use warnings;
1369

            
1370
    use base 'DBIx::Custom';
1371

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1383
    package MyModel2::Base1;
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 'DBIx::Custom::Model';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1389

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

            
1392
    use strict;
1393
    use warnings;
1394

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

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

            
1403
    sub list { shift->select; }
1404

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

            
1407
    use strict;
1408
    use warnings;
1409

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

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

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

            
1430
{
1431
     package MyDBI5;
1432

            
1433
    use strict;
1434
    use warnings;
1435

            
1436
    use base 'DBIx::Custom';
1437

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1630

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

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

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

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

            
1696

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

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

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

            
1745

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

            
1749

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

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

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

            
1765

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

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

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

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

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

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

            
1826

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

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

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

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

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

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1978
test 'model method';
1979
test 'create_model';
1980
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1981
$dbi->execute($CREATE_TABLE->{2});
1982
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1983
$model = $dbi->create_model(
1984
    table => 'table2'
1985
);
1986
$model->method(foo => sub { shift->select(@_) });
1987
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3});