DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
767 lines | 28.519kb
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/;
7

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

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

            
18
# Function for test name
19
my $test;
20
sub test {
21
    $test = shift;
22
}
23

            
24
# Constant varialbes for test
25
my $CREATE_TABLE = {
26
    0 => 'create table table1 (key1 char(255), key2 char(255));',
27
    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
28
    2 => 'create table table2 (key1 char(255), key3 char(255));',
29
    3 => 'create table table1 (key1 Date, key2 datetime);'
removed register_format()
yuki-kimoto authored on 2010-05-26
30
};
31

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

            
36
my $DROP_TABLE = {
37
    0 => 'drop table table1'
38
};
39

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

            
44
# Variables
45
my $dbi;
46
my $sth;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
47
my $source;
48
my @sources;
add tests
yuki-kimoto authored on 2010-08-10
49
my $select_SOURCE;
50
my $insert_SOURCE;
51
my $update_SOURCE;
removed register_format()
yuki-kimoto authored on 2010-05-26
52
my $params;
53
my $sql;
54
my $result;
55
my $row;
56
my @rows;
57
my $rows;
58
my $query;
59
my @queries;
60
my $select_query;
61
my $insert_query;
62
my $update_query;
63
my $ret_val;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
64
my $infos;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
65
my $table;
removed register_format()
yuki-kimoto authored on 2010-05-26
66

            
67
# Prepare table
68
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
69
$dbi->execute($CREATE_TABLE->{0});
70
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
71
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
72

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

            
78
@rows = ();
79
while (my $row = $result->fetch) {
80
    push @rows, [@$row];
81
}
removed reconnect method
yuki-kimoto authored on 2010-05-28
82
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch");
removed register_format()
yuki-kimoto authored on 2010-05-26
83

            
84
$result = $dbi->execute($query);
85
@rows = ();
86
while (my $row = $result->fetch_hash) {
87
    push @rows, {%$row};
88
}
removed reconnect method
yuki-kimoto authored on 2010-05-28
89
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash");
removed register_format()
yuki-kimoto authored on 2010-05-26
90

            
91
$result = $dbi->execute($query);
92
$rows = $result->fetch_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
93
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
94

            
95
$result = $dbi->execute($query);
removed reconnect method
yuki-kimoto authored on 2010-05-28
96
$rows = $result->fetch_hash_all;
97
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash_all");
removed register_format()
yuki-kimoto authored on 2010-05-26
98

            
99
test 'Insert query return value';
100
$dbi->execute($DROP_TABLE->{0});
101
$dbi->execute($CREATE_TABLE->{0});
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
102
$source = "insert into table1 {insert_param key1 key2}";
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
103
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
104
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
105
ok($ret_val, $test);
106

            
107

            
108
test 'Direct query';
109
$dbi->execute($DROP_TABLE->{0});
110
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
111
$insert_SOURCE = "insert into table1 {insert_param key1 key2}";
112
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2});
113
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
114
$rows = $result->fetch_hash_all;
115
is_deeply($rows, [{key1 => 1, key2 => 2}], $test);
116

            
117
test 'Filter basic';
118
$dbi->execute($DROP_TABLE->{0});
119
$dbi->execute($CREATE_TABLE->{0});
120
$dbi->register_filter(twice       => sub { $_[0] * 2}, 
121
                    three_times => sub { $_[0] * 3});
122

            
add tests
yuki-kimoto authored on 2010-08-10
123
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
124
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
125
$insert_query->filter({key1 => 'twice'});
126
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
add tests
yuki-kimoto authored on 2010-08-10
127
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
128
$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all;
129
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : filter fetch_filter");
130
$dbi->execute($DROP_TABLE->{0});
131

            
132
test 'Filter in';
133
$dbi->execute($CREATE_TABLE->{0});
add tests
yuki-kimoto authored on 2010-08-10
134
$insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
135
$insert_query = $dbi->create_query($insert_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
136
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
137
$select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
138
$select_query = $dbi->create_query($select_SOURCE);
removed register_format()
yuki-kimoto authored on 2010-05-26
139
$select_query->filter({'table1.key1' => 'twice'});
140
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
141
$rows = $result->fetch_hash_all;
142
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : filter");
143

            
144
test 'DBIx::Custom::SQLTemplate basic tag';
145
$dbi->execute($DROP_TABLE->{0});
146
$dbi->execute($CREATE_TABLE->{1});
147
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
148
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
149

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
150
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
151
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
152
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
153
$rows = $result->fetch_hash_all;
154
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
155

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
156
$source = "select * from table1 where {<= key1} and {like key2};";
157
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
158
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
159
$rows = $result->fetch_hash_all;
160
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
161

            
162
test 'DIB::Custom::SQLTemplate in tag';
163
$dbi->execute($DROP_TABLE->{0});
164
$dbi->execute($CREATE_TABLE->{1});
165
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
166
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
167

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
168
$source = "select * from table1 where {in key1 2};";
169
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
170
$result = $dbi->execute($query, param => {key1 => [9, 1]});
171
$rows = $result->fetch_hash_all;
172
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
173

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

            
add tests
yuki-kimoto authored on 2010-08-10
179
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
180
$rows = $result->fetch_hash_all;
181
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
182

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

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

            
add tests
yuki-kimoto authored on 2010-08-10
192
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
193
$rows = $result->fetch_hash_all;
194
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
195
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
196

            
197
test 'Error case';
198
eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
199
ok($@, "$test : connect error");
200

            
201
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
202
eval{$dbi->create_query("{p }")};
203
ok($@, "$test : create_query invalid SQL template");
removed register_format()
yuki-kimoto authored on 2010-05-26
204

            
205
test 'insert';
206
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
207
$dbi->execute($CREATE_TABLE->{0});
208
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
209
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
210
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
211
$rows   = $result->fetch_hash_all;
212
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic");
213

            
214
$dbi->execute('delete from table1');
215
$dbi->register_filter(
216
    twice       => sub { $_[0] * 2 },
217
    three_times => sub { $_[0] * 3 }
218
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
219
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
220
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
221
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
222
$rows   = $result->fetch_hash_all;
223
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
224
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
225

            
226
$dbi->execute($DROP_TABLE->{0});
227
$dbi->execute($CREATE_TABLE->{0});
228
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
229
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
230
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
231

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
232
eval{$dbi->insert(table => 'table1', noexist => 1)};
add tests
yuki-kimoto authored on 2010-08-10
233
like($@, qr/noexist/, "$test: invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
234

            
235

            
removed register_format()
yuki-kimoto authored on 2010-05-26
236
test 'update';
237
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
238
$dbi->execute($CREATE_TABLE->{1});
239
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
240
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
241
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
242
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
243
$rows   = $result->fetch_hash_all;
244
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
245
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
246
                  "$test : basic");
247
                  
248
$dbi->execute("delete from table1");
249
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
250
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
251
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
252
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
253
$rows   = $result->fetch_hash_all;
254
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
255
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
256
                  "$test : update key same as search key");
257

            
add tests
yuki-kimoto authored on 2010-08-10
258
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
259
$result = $dbi->execute($SELECT_SOURCES->{0});
260
$rows   = $result->fetch_hash_all;
261
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
262
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
263
                  "$test : update key same as search key : param is array ref");
264

            
removed register_format()
yuki-kimoto authored on 2010-05-26
265
$dbi->execute("delete from table1");
266
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
267
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
268
$dbi->register_filter(twice => sub { $_[0] * 2 });
269
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
270
              filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
271
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
272
$rows   = $result->fetch_hash_all;
273
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
274
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
275
                  "$test : filter");
276

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

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
279
eval{$dbi->update(table => 'table1', noexist => 1)};
add tests
yuki-kimoto authored on 2010-08-10
280
like($@, qr/noexist/, "$test: invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
281

            
282
eval{$dbi->update(table => 'table1')};
283
like($@, qr/where/, "$test: not contain where");
284

            
285

            
removed register_format()
yuki-kimoto authored on 2010-05-26
286
test 'update_all';
287
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
288
$dbi->execute($CREATE_TABLE->{1});
289
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
290
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
291
$dbi->register_filter(twice => sub { $_[0] * 2 });
292
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
293
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
294
$rows   = $result->fetch_hash_all;
295
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
296
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
297
                  "$test : filter");
298

            
299

            
300
test 'delete';
301
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
302
$dbi->execute($CREATE_TABLE->{0});
303
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
304
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
305
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
306
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
307
$rows   = $result->fetch_hash_all;
308
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
309

            
310
$dbi->execute("delete from table1;");
311
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
312
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
313
$dbi->register_filter(twice => sub { $_[0] * 2 });
314
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
315
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
316
$rows   = $result->fetch_hash_all;
317
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : filter");
318

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

            
321
$dbi->delete_all(table => 'table1');
322
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
323
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
324
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
325
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
326
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : delete multi key");
327

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
328
eval{$dbi->delete(table => 'table1', noexist => 1)};
add tests
yuki-kimoto authored on 2010-08-10
329
like($@, qr/noexist/, "$test: invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
330

            
331

            
removed register_format()
yuki-kimoto authored on 2010-05-26
332
test 'delete error';
333
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
334
$dbi->execute($CREATE_TABLE->{0});
335
eval{$dbi->delete(table => 'table1')};
add tests
yuki-kimoto authored on 2010-08-10
336
like($@, qr/"where" argument must be specified and contains the pairs of column name and value/,
removed register_format()
yuki-kimoto authored on 2010-05-26
337
         "$test : where key-value pairs not specified");
338

            
339
test 'delete_all';
340
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
341
$dbi->execute($CREATE_TABLE->{0});
342
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
343
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
344
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
345
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
346
$rows   = $result->fetch_hash_all;
347
is_deeply($rows, [], "$test : basic");
348

            
349

            
350
test 'select';
351
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
352
$dbi->execute($CREATE_TABLE->{0});
353
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
354
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
355
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
356
is_deeply($rows, [{key1 => 1, key2 => 2},
357
                  {key1 => 3, key2 => 4}], "$test : table");
358

            
update document
yuki-kimoto authored on 2010-05-27
359
$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all;
removed register_format()
yuki-kimoto authored on 2010-05-26
360
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "$test : table and columns and where key");
361

            
362
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all;
363
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where key");
364

            
update document
yuki-kimoto authored on 2010-08-07
365
$rows = $dbi->select(table => 'table1', where => ['{= key1} and {= key2}', {key1 => 1, key2 => 2}])->fetch_hash_all;
366
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where string");
367

            
update document
yuki-kimoto authored on 2010-05-27
368
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all;
removed register_format()
yuki-kimoto authored on 2010-05-26
369
is_deeply($rows, [{key1 => 3}], "$test : table and columns and where key");
370

            
371
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all;
372
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : append statement");
373

            
374
$dbi->register_filter(decrement => sub { $_[0] - 1 });
update document
yuki-kimoto authored on 2010-05-27
375
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
removed register_format()
yuki-kimoto authored on 2010-05-26
376
            ->fetch_hash_all;
377
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : filter");
378

            
379
$dbi->execute($CREATE_TABLE->{2});
380
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
381
$rows = $dbi->select(
382
    table => [qw/table1 table2/],
update document
yuki-kimoto authored on 2010-05-27
383
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
removed register_format()
yuki-kimoto authored on 2010-05-26
384
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
385
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
386
)->fetch_hash_all;
added commit method
yuki-kimoto authored on 2010-05-27
387
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : relation : exists where");
388

            
389
$rows = $dbi->select(
390
    table => [qw/table1 table2/],
391
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
392
    relation  => {'table1.key1' => 'table2.key1'}
393
)->fetch_hash_all;
394
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : relation : no exists where");
removed register_format()
yuki-kimoto authored on 2010-05-26
395

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
396
eval{$dbi->select(table => 'table1', noexist => 1)};
add tests
yuki-kimoto authored on 2010-08-10
397
like($@, qr/noexist/, "$test: invalid argument");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
398

            
399

            
removed register_format()
yuki-kimoto authored on 2010-05-26
400
test 'fetch filter';
401
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
402
$dbi->register_filter(
403
    twice       => sub { $_[0] * 2 },
404
    three_times => sub { $_[0] * 3 }
405
);
406
$dbi->default_fetch_filter('twice');
407
$dbi->execute($CREATE_TABLE->{0});
408
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
409
$result = $dbi->select(table => 'table1');
410
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
411
$row = $result->fetch_hash_first;
removed register_format()
yuki-kimoto authored on 2010-05-26
412
is_deeply($row, {key1 => 3, key2 => 4}, "$test: default_fetch_filter and filter");
413

            
414
test 'filters';
415
$dbi = DBIx::Custom->new;
416

            
update document
yuki-kimoto authored on 2010-05-27
417
is($dbi->filters->{decode_utf8}->(encode_utf8('あ')),
418
   'あ', "$test : decode_utf8");
removed register_format()
yuki-kimoto authored on 2010-05-26
419

            
420
is($dbi->filters->{encode_utf8}->('あ'),
421
   encode_utf8('あ'), "$test : encode_utf8");
422

            
added commit method
yuki-kimoto authored on 2010-05-27
423
test 'transaction';
424
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
425
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
426
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
427
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
428
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
429
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
430
$result = $dbi->select(table => 'table1');
431
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
432
          "$test : commit");
433

            
434
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
435
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
436
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
437
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
438
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
439

            
440
$result = $dbi->select(table => 'table1');
removed reconnect method
yuki-kimoto authored on 2010-05-28
441
ok(! $result->fetch_first, "$test: rollback");
add cache attribute
yuki-kimoto authored on 2010-06-14
442

            
443
test 'cache';
444
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
445
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
446
$source = 'select * from table1 where {= key1} and {= key2};';
447
$dbi->create_query($source);
448
is_deeply($dbi->{_cached}->{$source}, 
add cache attribute
yuki-kimoto authored on 2010-06-14
449
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "$test : cache");
450

            
451
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
452
$dbi->execute($CREATE_TABLE->{0});
453
$dbi->{_cached} = {};
454
$dbi->cache(0);
455
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
456
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
457

            
add tests
yuki-kimoto authored on 2010-08-10
458
test 'execute';
459
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
460
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
461
{
462
    local $Carp::Verbose = 0;
463
    eval{$dbi->execute('select * frm table1')};
464
    like($@, qr/\Qselect * frm table1;/, "$test : fail prepare");
465
    like($@, qr/\.t /, "$test: fail : not verbose");
466
}
467
{
468
    local $Carp::Verbose = 1;
469
    eval{$dbi->execute('select * frm table1')};
470
    like($@, qr/Custom.*\.t /s, "$test : fail : verbose");
471
}
add tests
yuki-kimoto authored on 2010-08-10
472

            
473
eval{$dbi->execute('select * from table1', no_exists => 1)};
474
like($@, qr/\Q"no_exists" is invalid argument/, "$test : invald SQL");
475

            
476
$query = $dbi->create_query('select * from table1 where {= key1}');
477
$dbi->dbh->disconnect;
478
eval{$dbi->execute($query, param => {key1 => {a => 1}})};
479
ok($@, "$test: execute fail");
480

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
481
{
482
    local $Carp::Verbose = 0;
483
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
484
    like($@, qr/\Q.t /, "$test : caller spec : not vebose");
485
}
486
{
487
    local $Carp::Verbose = 1;
488
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
489
    like($@, qr/QueryBuilder.*\.t /s, "$test : caller spec : not vebose");
490
}
cleanup
yuki-kimoto authored on 2010-10-17
491

            
492

            
493
test 'transaction';
494
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
495
$dbi->execute($CREATE_TABLE->{0});
496

            
497
$dbi->begin_work;
498

            
499
eval {
500
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
501
    die "Error";
502
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
503
};
504

            
505
$dbi->rollback if $@;
506

            
507
$result = $dbi->select(table => 'table1');
508
$rows = $result->fetch_hash_all;
509
is_deeply($rows, [], "$test : rollback");
510

            
511
$dbi->begin_work;
512

            
513
eval {
514
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
515
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
516
};
517

            
518
$dbi->commit unless $@;
519

            
520
$result = $dbi->select(table => 'table1');
521
$rows = $result->fetch_hash_all;
522
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit");
523

            
524
$dbi->dbh->{AutoCommit} = 0;
525
eval{ $dbi->begin_work };
526
ok($@, "$test : exception");
527
$dbi->dbh->{AutoCommit} = 1;
528

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

            
530
test 'helper';
531
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
532
$dbi->helper(
533
    one => sub { 1 }
534
);
535
$dbi->helper(
536
    two => sub { 2 }
537
);
538
$dbi->helper({
539
    twice => sub {
540
        my $self = shift;
541
        return $_[0] * 2;
542
    }
543
});
544

            
545
is($dbi->one, 1, "$test : first");
546
is($dbi->two, 2, "$test : second");
547
is($dbi->twice(5), 10 , "$test : second");
548

            
549
eval {$dbi->XXXXXX};
550
like($@, qr/\QCan't locate object method "XXXXXX" via "DBIx::Custom"/, "$test : not exists");
551

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
552
test 'auto bind filter';
553
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
554
$dbi->execute($CREATE_TABLE->{0});
555
$dbi->register_filter(twice => sub { $_[0] * 2 });
556
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
557
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
558
    'table1', ['key1', 'twice', 'twice'], ['key2', 'three_times', 'three_times']);
559
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
560
$result = $dbi->execute($SELECT_SOURCES->{0});
561
$row   = $result->fetch_hash_first;
562
is_deeply($row, {key1 => 2, key2 => 6}, "$test : insert");
563

            
564
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
565
$dbi->execute($CREATE_TABLE->{0});
566
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
567
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
568
    'table1', ['key1', 'twice', 'twice']
569
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
570
$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
571
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
572
$result = $dbi->execute($SELECT_SOURCES->{0});
573
$row   = $result->fetch_hash_first;
574
is_deeply($row, {key1 => 4, key2 => 2}, "$test : update");
575

            
576
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
577
$dbi->execute($CREATE_TABLE->{0});
578
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
579
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
580
    'table1', ['key1', 'twice', 'twice']
581
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
582
$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
583
$dbi->delete(table => 'table1', where => {key1 => 1});
584
$result = $dbi->execute($SELECT_SOURCES->{0});
585
$rows   = $result->fetch_hash_all;
586
is_deeply($rows, [], "$test : delete");
587

            
588
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
589
$dbi->execute($CREATE_TABLE->{0});
590
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
591
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
592
    'table1', ['key1', 'twice', 'twice']
593
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
594
$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
595
$result = $dbi->select(table => 'table1', where => {key1 => 1});
596
$result->filter({'key2' => 'twice'});
597
$rows   = $result->fetch_hash_all;
598
is_deeply($rows, [{key1 => 4, key2 => 4}], "$test : select");
599

            
600
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
601
$dbi->execute($CREATE_TABLE->{0});
602
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
603
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
604
    'table1', ['key1', 'twice', 'twice']
605
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
606
$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
607
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
608
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
609
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
610
$rows   = $result->fetch_hash_all;
611
is_deeply($rows, [{key1 => 4, key2 => 2}], "$test : execute");
612

            
613
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
614
$dbi->execute($CREATE_TABLE->{0});
615
$dbi->execute($CREATE_TABLE->{2});
616
$dbi->register_filter(twice => sub { $_[0] * 2 });
617
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
618
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
619
    'table1', ['key2', 'twice', 'twice']
620
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
621
$dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
622
    'table2', ['key3', 'three_times', 'three_times']
623
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
624
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
625
$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
626
$result = $dbi->select(
627
     table => ['table1', 'table2'],
628
     column => ['key2', 'key3'],
629
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
630

            
631
$result->filter({'key2' => 'twice'});
632
$rows   = $result->fetch_hash_all;
633
is_deeply($rows, [{key2 => 4, key3 => 18}], "$test : select : join");
634

            
635
$result = $dbi->select(
636
     table => ['table1', 'table2'],
637
     column => ['key2', 'key3'],
638
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
639

            
640
$result->filter({'key2' => 'twice'});
641
$rows   = $result->fetch_hash_all;
642
is_deeply($rows, [{key2 => 4, key3 => 18}], "$test : select : join : omit");
643

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
644
test 'apply_filter_easy_build';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
645
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
646
$dbi->execute($CREATE_TABLE->{2});
647
$dbi->execute($CREATE_TABLE->{3});
648

            
649
$infos = [];
650
$dbi->iterate_all_columns(sub {
651
    my ($table, $column, $cinfo) = @_;
652
    
653
    if ($table =~ /^table/) {
654
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
655
         push @$infos, $info;
656
    }
657
});
658
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
659
is_deeply($infos, 
660
    [
661
        ['table1', 'key1', 'key1'],
662
        ['table1', 'key2', 'key2'],
663
        ['table2', 'key1', 'key1'],
664
        ['table2', 'key3', 'key3']
665
    ]
666
    , $test
667
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
668

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
669
test 'table';
670
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
671
$dbi->execute($CREATE_TABLE->{0});
672
$table = $dbi->table('table1');
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
673
$table->insert(param => {key1 => 1, key2 => 2});
674
$table->insert(param => {key1 => 3, key2 => 4});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
675
$rows = $table->select->fetch_hash_all;
676
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}],
677
                 "$test: select");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
678
$rows = $table->select(where => {key2 => 2}, append => 'order by key1',
679
                              column => ['key1', 'key2'])->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
680
is_deeply($rows, [{key1 => 1, key2 => 2}],
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
681
                 "$test: insert insert select");
682
$table->update(param => {key1 => 3}, where => {key2 => 2});
683
$table->update(param => {key1 => 5}, where => {key2 => 4});
684
$rows = $table->select(where => {key2 => 2})->fetch_hash_all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
685
is_deeply($rows, [{key1 => 3, key2 => 2}],
686
                 "$test: update");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
687
$table->delete(where => {key2 => 2});
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
688
$rows = $table->select->fetch_hash_all;
689
is_deeply($rows, [{key1 => 5, key2 => 4}], "$test: delete");
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
690
$table->update_all(param => {key1 => 3});
691
$rows = $table->select->fetch_hash_all;
692
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test: update_all");
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
693
$table->delete_all;
694
$rows = $table->select->fetch_hash_all;
695
is_deeply($rows, [], "$test: delete_all");
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
696

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
697
$dbi->dbh->do($CREATE_TABLE->{2});
698
$dbi->table('table2', ppp => sub {
699
    my $self = shift;
700
    
701
    return $self->name;
702
});
703
is($dbi->table('table2')->ppp, 'table2', "$test : helper");
704

            
add examples
Yuki Kimoto authored on 2011-01-07
705
test 'limit';
706
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
707
$dbi->execute($CREATE_TABLE->{0});
708
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
709
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
710
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
711
$dbi->query_builder->register_tag_processor(
712
    limit => sub {
713
        my ($count, $offset) = @_;
714
        
715
        my $s = '';
716
        $s .= "limit $count";
717
        $s .= " offset $offset" if defined $offset;
718
        
719
        return [$s, []];
720
    }
721
);
722
$rows = $dbi->select(
723
  table => 'table1',
724
  where => {key1 => 1},
725
  append => "order by key2 {limit 1 0}"
726
)->fetch_hash_all;
727
is_deeply($rows, [{key1 => 1, key2 => 2}], $test);
728
$rows = $dbi->select(
729
  table => 'table1',
730
  where => {key1 => 1},
731
  append => "order by key2 {limit 2 1}"
732
)->fetch_hash_all;
733
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}], $test);
734
$rows = $dbi->select(
735
  table => 'table1',
736
  where => {key1 => 1},
737
  append => "order by key2 {limit 1}"
738
)->fetch_hash_all;
739
is_deeply($rows, [{key1 => 1, key2 => 2}], $test);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
740

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
741
test 'connect super';
742
{
743
    package MyDBI;
744
    
745
    use base 'DBIx::Custom';
746
    sub connect {
747
        my $self = shift->SUPER::connect(@_);
748
        
749
        return $self;
750
    }
751
    
752
    sub new {
753
        my $self = shift->SUPER::connect(@_);
754
        
755
        return $self;
756
    }
757
}
758

            
759
$dbi = MyDBI->connect($NEW_ARGS->{0});
760
$dbi->execute($CREATE_TABLE->{0});
761
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
762
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1, $test);
763

            
764
$dbi = MyDBI->new($NEW_ARGS->{0});
765
$dbi->execute($CREATE_TABLE->{0});
766
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
767
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1, $test);