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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
113

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

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

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
162
$source = "select * from table1 where {<= key1} and {like key2};";
163
$query = $dbi->create_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
164
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
165
$rows = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
166
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
removed register_format()
yuki-kimoto authored on 2010-05-26
167

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

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

            
180
test 'DBIx::Custom::SQLTemplate insert tag';
181
$dbi->execute("delete from table1");
add tests
yuki-kimoto authored on 2010-08-10
182
$insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
183
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
184

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

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

            
add tests
yuki-kimoto authored on 2010-08-10
195
$update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
196
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
removed register_format()
yuki-kimoto authored on 2010-05-26
197

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
303
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
304
$dbi->execute($CREATE_TABLE->{0});
305
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
306
$where = $dbi->where;
307
$where->clause(['and', '{= key2}']);
308
$where->param({key2 => 2});
309
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
310
$result = $dbi->select(table => 'table1');
311
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
312

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
319
test 'update_all';
320
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
321
$dbi->execute($CREATE_TABLE->{1});
322
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
323
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
324
$dbi->register_filter(twice => sub { $_[0] * 2 });
325
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
326
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
327
$rows   = $result->fetch_hash_all;
328
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
329
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
330
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
331

            
332

            
333
test 'delete';
334
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
335
$dbi->execute($CREATE_TABLE->{0});
336
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
337
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
338
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
339
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
340
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
341
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
342

            
343
$dbi->execute("delete from table1;");
344
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
345
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
346
$dbi->register_filter(twice => sub { $_[0] * 2 });
347
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
348
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
349
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
350
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
351

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

            
354
$dbi->delete_all(table => 'table1');
355
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
356
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
357
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
358
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
359
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
360

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
364
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
365
$dbi->execute($CREATE_TABLE->{0});
366
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
367
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
368
$where = $dbi->where;
369
$where->clause(['and', '{= key1}', '{= key2}']);
370
$where->param({ke1 => 1, key2 => 2});
371
$dbi->delete(table => 'table1', where => $where);
372
$result = $dbi->select(table => 'table1');
373
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
374

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

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
385
test 'delete_all';
386
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
387
$dbi->execute($CREATE_TABLE->{0});
388
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
389
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
390
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
391
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
392
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
393
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
394

            
395

            
396
test 'select';
397
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
398
$dbi->execute($CREATE_TABLE->{0});
399
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
400
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
401
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
402
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
403
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
404

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

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

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

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

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

            
422
$dbi->execute($CREATE_TABLE->{2});
423
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
424
$rows = $dbi->select(
425
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
426
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
427
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
428
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
429
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
430
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
431

            
432
$rows = $dbi->select(
433
    table => [qw/table1 table2/],
434
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
435
    relation  => {'table1.key1' => 'table2.key1'}
436
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
437
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
438

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

            
442

            
removed register_format()
yuki-kimoto authored on 2010-05-26
443
test 'fetch filter';
444
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
445
$dbi->register_filter(
446
    twice       => sub { $_[0] * 2 },
447
    three_times => sub { $_[0] * 3 }
448
);
449
$dbi->default_fetch_filter('twice');
450
$dbi->execute($CREATE_TABLE->{0});
451
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
452
$result = $dbi->select(table => 'table1');
453
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
454
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
455
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
456

            
457
test 'filters';
458
$dbi = DBIx::Custom->new;
459

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
466
test 'transaction';
467
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
468
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
469
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
470
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
471
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
472
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
473
$result = $dbi->select(table => 'table1');
474
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
475
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
476

            
477
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
478
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
479
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
480
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
481
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
482

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

            
486
test 'cache';
487
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
488
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
489
$source = 'select * from table1 where {= key1} and {= key2};';
490
$dbi->create_query($source);
491
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
492
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
493

            
494
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
495
$dbi->execute($CREATE_TABLE->{0});
496
$dbi->{_cached} = {};
497
$dbi->cache(0);
498
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
499
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
500

            
add tests
yuki-kimoto authored on 2010-08-10
501
test 'execute';
502
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
503
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
504
{
505
    local $Carp::Verbose = 0;
506
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
507
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
508
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
509
}
510
{
511
    local $Carp::Verbose = 1;
512
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
513
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
514
}
add tests
yuki-kimoto authored on 2010-08-10
515

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
524
{
525
    local $Carp::Verbose = 0;
526
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
527
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
528
}
529
{
530
    local $Carp::Verbose = 1;
531
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
532
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
533
}
cleanup
yuki-kimoto authored on 2010-10-17
534

            
535

            
536
test 'transaction';
537
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
538
$dbi->execute($CREATE_TABLE->{0});
539

            
540
$dbi->begin_work;
541

            
542
eval {
543
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
544
    die "Error";
545
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
546
};
547

            
548
$dbi->rollback if $@;
549

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

            
554
$dbi->begin_work;
555

            
556
eval {
557
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
558
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
559
};
560

            
561
$dbi->commit unless $@;
562

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

            
567
$dbi->dbh->{AutoCommit} = 0;
568
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
569
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
570
$dbi->dbh->{AutoCommit} = 1;
571

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
573
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
574
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
575
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
576
    one => sub { 1 }
577
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
578
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
579
    two => sub { 2 }
580
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
581
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
582
    twice => sub {
583
        my $self = shift;
584
        return $_[0] * 2;
585
    }
586
});
587

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
595
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
596
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
597
$dbi->execute($CREATE_TABLE->{0});
598
$dbi->register_filter(twice => sub { $_[0] * 2 });
599
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
600
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
601
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
602
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
603
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
604
$result = $dbi->execute($SELECT_SOURCES->{0});
605
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
606
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
607
$result = $dbi->select(table => 'table1');
608
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
609
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
610

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
611
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
612
$dbi->execute($CREATE_TABLE->{0});
613
$dbi->register_filter(twice => sub { $_[0] * 2 });
614
$dbi->register_filter(three_times => sub { $_[0] * 3});
615
$dbi->apply_filter(
616
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
617
              'key2' => {out => 'three_times', in => 'twice'});
618
$dbi->apply_filter(
619
    'table1', 'key1' => {out => undef}
620
); 
621
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
622
$result = $dbi->execute($SELECT_SOURCES->{0});
623
$row   = $result->fetch_hash_first;
624
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
625

            
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 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
629
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
630
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
631
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
632
$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
633
$dbi->update(table => 'table1', param => {key1 => 2}, where => {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 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
637

            
638
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
639
$dbi->execute($CREATE_TABLE->{0});
640
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
641
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
642
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
643
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
644
$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
645
$dbi->delete(table => 'table1', where => {key1 => 1});
646
$result = $dbi->execute($SELECT_SOURCES->{0});
647
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
648
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
649

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

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

            
add table tag
Yuki Kimoto authored on 2011-02-09
675
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
676
$dbi->execute($CREATE_TABLE->{0});
677
$dbi->register_filter(twice => sub { $_[0] * 2 });
678
$dbi->apply_filter(
679
    'table1', 'key1' => {out => 'twice', in => 'twice'}
680
);
681
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
682
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
683
                        param => {key1 => 1, key2 => 2});
684
$rows   = $result->fetch_hash_all;
685
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
686

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
687
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
688
$dbi->execute($CREATE_TABLE->{0});
689
$dbi->execute($CREATE_TABLE->{2});
690
$dbi->register_filter(twice => sub { $_[0] * 2 });
691
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
692
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
693
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
694
);
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
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
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 => 5, key2 => 2}, filter => {key2 => undef});
699
$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
700
$result = $dbi->select(
701
     table => ['table1', 'table2'],
702
     column => ['key2', 'key3'],
703
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
704

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

            
709
$result = $dbi->select(
710
     table => ['table1', 'table2'],
711
     column => ['key2', 'key3'],
712
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
713

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
718
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
719
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
720
$dbi->execute($CREATE_TABLE->{2});
721
$dbi->execute($CREATE_TABLE->{3});
722

            
723
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
724
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
725
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
726
    
727
    if ($table =~ /^table/) {
728
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
729
         push @$infos, $info;
730
    }
731
});
732
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
733
is_deeply($infos, 
734
    [
735
        ['table1', 'key1', 'key1'],
736
        ['table1', 'key2', 'key2'],
737
        ['table2', 'key1', 'key1'],
738
        ['table2', 'key3', 'key3']
739
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
740
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
741
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
742

            
add examples
Yuki Kimoto authored on 2011-01-07
743
test 'limit';
744
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
745
$dbi->execute($CREATE_TABLE->{0});
746
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
747
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
748
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
749
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
750
    limit => sub {
751
        my ($count, $offset) = @_;
752
        
753
        my $s = '';
754
        $s .= "limit $count";
755
        $s .= " offset $offset" if defined $offset;
756
        
757
        return [$s, []];
758
    }
759
);
760
$rows = $dbi->select(
761
  table => 'table1',
762
  where => {key1 => 1},
763
  append => "order by key2 {limit 1 0}"
764
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
765
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
766
$rows = $dbi->select(
767
  table => 'table1',
768
  where => {key1 => 1},
769
  append => "order by key2 {limit 2 1}"
770
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
771
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
772
$rows = $dbi->select(
773
  table => 'table1',
774
  where => {key1 => 1},
775
  append => "order by key2 {limit 1}"
776
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
777
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
778

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
779
test 'connect super';
780
{
781
    package MyDBI;
782
    
783
    use base 'DBIx::Custom';
784
    sub connect {
785
        my $self = shift->SUPER::connect(@_);
786
        
787
        return $self;
788
    }
789
    
790
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
791
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
792
        
793
        return $self;
794
    }
795
}
796

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
808
{
809
    package MyDBI2;
810
    
811
    use base 'DBIx::Custom';
812
    sub connect {
813
        my $self = shift->SUPER::new(@_);
814
        $self->connect;
815
        
816
        return $self;
817
    }
818
}
819

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

            
825
test 'end_filter';
826
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
827
$dbi->execute($CREATE_TABLE->{0});
828
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
829
$result = $dbi->select(table => 'table1');
830
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
831
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
832
$row = $result->fetch_first;
833
is_deeply($row, [6, 40]);
834

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
835
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
836
$dbi->execute($CREATE_TABLE->{0});
837
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
838
$result = $dbi->select(table => 'table1');
839
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
840
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
841
$row = $result->fetch_first;
842
is_deeply($row, [6, 12]);
843

            
844
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
845
$dbi->execute($CREATE_TABLE->{0});
846
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
847
$result = $dbi->select(table => 'table1');
848
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
849
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
850
$row = $result->fetch_first;
851
is_deeply($row, [6, 12]);
852

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
860
$dbi->register_filter(five_times => sub { $_[0] * 5 });
861
$dbi->apply_filter('table1',
862
    key1 => {end => sub { $_[0] * 3 } },
863
    key2 => {end => 'five_times'}
864
);
865
$result = $dbi->select(table => 'table1');
866
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
867
$row = $result->fetch_hash_first;
868
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
869

            
870
$dbi->register_filter(five_times => sub { $_[0] * 5 });
871
$dbi->apply_filter('table1',
872
    key1 => {end => sub { $_[0] * 3 } },
873
    key2 => {end => 'five_times'}
874
);
875
$result = $dbi->select(table => 'table1');
876
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
877
$result->filter(key1 => undef);
878
$result->end_filter(key1 => undef);
879
$row = $result->fetch_hash_first;
880
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
881

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
882
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
883
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
884
$dbi->execute($CREATE_TABLE->{0});
885
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
886
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
887
$row = $result
888
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
889
       ->remove_filter
890
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
891
       ->remove_end_filter
892
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
893
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
894

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
895
test 'empty where select';
896
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
897
$dbi->execute($CREATE_TABLE->{0});
898
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
899
$result = $dbi->select(table => 'table1', where => {});
900
$row = $result->fetch_hash_first;
901
is_deeply($row, {key1 => 1, key2 => 2});
902

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
903
test 'select query option';
904
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
905
$dbi->execute($CREATE_TABLE->{0});
906
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
907
is(ref $query, 'DBIx::Custom::Query');
908
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
909
is(ref $query, 'DBIx::Custom::Query');
910
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
911
is(ref $query, 'DBIx::Custom::Query');
912
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
913
is(ref $query, 'DBIx::Custom::Query');
914

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
915
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
916
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
917
$dbi->execute($CREATE_TABLE->{0});
918
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
919
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
920
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
921
is("$where", "where ( {= key1} and {= key2} )", 'no param');
922

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
927
$result = $dbi->select(
928
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
929
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
930
);
931
$row = $result->fetch_hash_all;
932
is_deeply($row, [{key1 => 1, key2 => 2}]);
933

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
934
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
935
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
936
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
937
$result = $dbi->select(
938
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
939
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
940
);
941
$row = $result->fetch_hash_all;
942
is_deeply($row, [{key1 => 1, key2 => 2}]);
943

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
944
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
945
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
946
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
947
$result = $dbi->select(
948
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
949
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
950
);
951
$row = $result->fetch_hash_all;
952
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
953

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
954
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
955
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
956
             ->param({key1 => [0, 3], key2 => 2});
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,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
960
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
961
$row = $result->fetch_hash_all;
962
is_deeply($row, [{key1 => 1, key2 => 2}]);
963

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
964
$where = $dbi->where;
965
$result = $dbi->select(
966
    table => 'table1',
967
    where => $where
968
);
969
$row = $result->fetch_hash_all;
970
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
971

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
972
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
973
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
974
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
975
$result = $dbi->select(
976
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
977
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
978
);
979
};
980
ok($@);
981

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

            
added test
Yuki Kimoto authored on 2011-01-19
985
$where = $dbi->where
986
             ->clause(['or', ('{= key1}') x 2])
987
             ->param({key1 => [1, 3]});
988
$result = $dbi->select(
989
    table => 'table1',
990
    where => $where,
991
);
992
$row = $result->fetch_hash_all;
993
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
994

            
995
$where = $dbi->where
996
             ->clause(['or', ('{= key1}') x 2])
997
             ->param({key1 => [1]});
998
$result = $dbi->select(
999
    table => 'table1',
1000
    where => $where,
1001
);
1002
$row = $result->fetch_hash_all;
1003
is_deeply($row, [{key1 => 1, key2 => 2}]);
1004

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

            
many changed
Yuki Kimoto authored on 2011-01-23
1015
$where = $dbi->where
1016
             ->clause('{= key1}')
1017
             ->param({key1 => 1});
1018
$result = $dbi->select(
1019
    table => 'table1',
1020
    where => $where,
1021
);
1022
$row = $result->fetch_hash_all;
1023
is_deeply($row, [{key1 => 1, key2 => 2}]);
1024

            
1025
$where = $dbi->where
1026
             ->clause('{= key1} {= key2}')
1027
             ->param({key1 => 1});
1028
eval{$where->to_string};
1029
like($@, qr/one column/);
1030

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1031
$where = $dbi->where
1032
             ->clause('{= key1}')
1033
             ->param([]);
1034
eval{$where->to_string};
1035
like($@, qr/Parameter/);
1036

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

            
1047
$where = $dbi->where
1048
             ->clause(['or', ('{= key1}') x 3])
1049
             ->param({key1 => [1, $dbi->not_exists, 3]});
1050
$result = $dbi->select(
1051
    table => 'table1',
1052
    where => $where,
1053
);
1054
$row = $result->fetch_hash_all;
1055
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1056

            
1057
$where = $dbi->where
1058
             ->clause(['or', ('{= key1}') x 3])
1059
             ->param({key1 => [1, 3, $dbi->not_exists]});
1060
$result = $dbi->select(
1061
    table => 'table1',
1062
    where => $where,
1063
);
1064
$row = $result->fetch_hash_all;
1065
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1066

            
1067
$where = $dbi->where
1068
             ->clause(['or', ('{= key1}') x 3])
1069
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1070
$result = $dbi->select(
1071
    table => 'table1',
1072
    where => $where,
1073
);
1074
$row = $result->fetch_hash_all;
1075
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1076

            
1077
$where = $dbi->where
1078
             ->clause(['or', ('{= key1}') x 3])
1079
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
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}], 'not_exists');
1086

            
1087
$where = $dbi->where
1088
             ->clause(['or', ('{= key1}') x 3])
1089
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
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}], 'not_exists');
1096

            
1097
$where = $dbi->where
1098
             ->clause(['or', ('{= key1}') x 3])
1099
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $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

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1107
$where = $dbi->where
1108
             ->clause(['or', ('{= key1}') x 3])
1109
             ->param({key1 => []});
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}, {key1 => 3, key2 => 4}], 'not_exists');
1116

            
1117
$where = $dbi->where
1118
             ->clause(['and', '{> key1}', '{< key1}' ])
1119
             ->param({key1 => [2, $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 => 3, key2 => 4}], 'not_exists');
1126

            
1127
$where = $dbi->where
1128
             ->clause(['and', '{> key1}', '{< key1}' ])
1129
             ->param({key1 => [$dbi->not_exists, 2]});
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(['and', '{> key1}', '{< key1}' ])
1139
             ->param({key1 => [$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

            
1147
$where = $dbi->where
1148
             ->clause(['and', '{> key1}', '{< key1}' ])
1149
             ->param({key1 => [0, 2]});
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}], 'not_exists');
1156

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1161
test 'register_tag_processor';
1162
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1163
$dbi->register_tag_processor(
1164
    a => sub { 1 }
1165
);
1166
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1167

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1168
test 'register_tag';
1169
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1170
$dbi->register_tag(
1171
    b => sub { 2 }
1172
);
1173
is($dbi->query_builder->tags->{b}->(), 2);
1174

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1175
test 'table not specify exception';
1176
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1177
eval {$dbi->insert};
1178
like($@, qr/table/);
1179
eval {$dbi->update};
1180
like($@, qr/table/);
1181
eval {$dbi->delete};
1182
like($@, qr/table/);
1183
eval {$dbi->select};
1184
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1185

            
1186

            
1187
test 'more tests';
1188
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1189
eval{$dbi->apply_filter('table', 'column', [])};
1190
like($@, qr/apply_filter/);
1191

            
1192
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1193
like($@, qr/apply_filter/);
1194

            
1195
$dbi->apply_filter(
1196

            
1197
);
1198
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1199
$dbi->execute($CREATE_TABLE->{0});
1200
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1201
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1202
$dbi->apply_filter('table1', 'key2', 
1203
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1204
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1205
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1206

            
1207
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1208
$dbi->execute($CREATE_TABLE->{0});
1209
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1210
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1211
$dbi->apply_filter('table1', 'key2', {});
1212
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1213
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1214

            
1215
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1216
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1217
like($@, qr/not registered/);
1218
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1219
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1220
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1221
is($dbi->one, 1);
1222

            
1223
eval{DBIx::Custom->connect()};
1224
like($@, qr/connect/);
1225

            
1226
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1227
$dbi->execute($CREATE_TABLE->{0});
1228
$dbi->register_filter(twice => sub { $_[0] * 2 });
1229
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1230
             filter => {key1 => 'twice'});
1231
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1232
is_deeply($row, {key1 => 2, key2 => 2});
1233
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1234
             filter => {key1 => 'no'}) };
1235
like($@, qr//);
1236

            
1237
$dbi->register_filter(one => sub { });
1238
$dbi->default_fetch_filter('one');
1239
ok($dbi->default_fetch_filter);
1240
$dbi->default_bind_filter('one');
1241
ok($dbi->default_bind_filter);
1242
eval{$dbi->default_fetch_filter('no')};
1243
like($@, qr/not registered/);
1244
eval{$dbi->default_bind_filter('no')};
1245
like($@, qr/not registered/);
1246
$dbi->default_bind_filter(undef);
1247
ok(!defined $dbi->default_bind_filter);
1248
$dbi->default_fetch_filter(undef);
1249
ok(!defined $dbi->default_fetch_filter);
1250
eval {$dbi->execute('select * from table1 {= author') };
1251
like($@, qr/Tag not finished/);
1252

            
1253
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1254
$dbi->execute($CREATE_TABLE->{0});
1255
$dbi->register_filter(one => sub { 1 });
1256
$result = $dbi->select(table => 'table1');
1257
eval {$result->filter(key1 => 'no')};
1258
like($@, qr/not registered/);
1259
eval {$result->end_filter(key1 => 'no')};
1260
like($@, qr/not registered/);
1261
$result->default_filter(undef);
1262
ok(!defined $result->default_filter);
1263
$result->default_filter('one');
1264
is($result->default_filter->(), 1);
1265

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1266
test 'dbi_option';
1267
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1268
                             dbi_option => {PrintError => 1});
1269
ok($dbi->dbh->{PrintError});
1270
$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1271
                             dbi_options => {PrintError => 1});
1272
ok($dbi->dbh->{PrintError});
1273

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1274
test 'DBIx::Custom::Result stash()';
1275
$result = DBIx::Custom::Result->new;
1276
is_deeply($result->stash, {}, 'default');
1277
$result->stash->{foo} = 1;
1278
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1279

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1280
test 'filter __ expression';
1281
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1282
$dbi->execute('create table company (id, name, location_id)');
1283
$dbi->execute('create table location (id, name)');
1284
$dbi->apply_filter('location',
1285
  name => {in => sub { uc $_[0] } }
1286
);
1287

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

            
1291
$result = $dbi->select(
1292
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1293
    column => ['location.name as location__name']
1294
);
1295
is($result->fetch_first->[0], 'B');
1296

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1297
$result = $dbi->select(
1298
    table => 'company', relation => {'company.location_id' => 'location.id'},
1299
    column => ['location.name as location__name']
1300
);
1301
is($result->fetch_first->[0], 'B');
1302

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1310
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1311
use MyDBI1;
1312
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1313
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1314
$model = $dbi->model('book');
1315
$model->insert({title => 'a', author => 'b'});
1316
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1317
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1318
$model = $dbi->model('company');
1319
$model->insert({name => 'a'});
1320
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1321
is($dbi->models->{'book'}, $dbi->model('book'));
1322
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1323

            
1324
{
1325
    package MyDBI4;
1326

            
1327
    use strict;
1328
    use warnings;
1329

            
1330
    use base 'DBIx::Custom';
1331

            
1332
    sub connect {
1333
        my $self = shift->SUPER::connect(@_);
1334
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1335
        $self->include_model(
1336
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1337
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1338
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1339
            ]
1340
        );
1341
    }
1342

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

            
1345
    use strict;
1346
    use warnings;
1347

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

            
1352
    use strict;
1353
    use warnings;
1354

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

            
1357
    sub insert {
1358
        my ($self, $param) = @_;
1359
        
1360
        return $self->SUPER::insert(param => $param);
1361
    }
1362

            
1363
    sub list { shift->select; }
1364

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

            
1367
    use strict;
1368
    use warnings;
1369

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

            
1372
    sub insert {
1373
        my ($self, $param) = @_;
1374
        
1375
        return $self->SUPER::insert(param => $param);
1376
    }
1377

            
1378
    sub list { shift->select; }
1379
}
1380
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1381
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1382
$model = $dbi->model('book');
1383
$model->insert({title => 'a', author => 'b'});
1384
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1385
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1386
$model = $dbi->model('company');
1387
$model->insert({name => 'a'});
1388
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1389

            
1390
{
1391
     package MyDBI5;
1392

            
1393
    use strict;
1394
    use warnings;
1395

            
1396
    use base 'DBIx::Custom';
1397

            
1398
    sub connect {
1399
        my $self = shift->SUPER::connect(@_);
1400
        
1401
        $self->include_model('MyModel4');
1402
    }
1403
}
1404
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1405
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1406
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1407
$model = $dbi->model('company');
1408
$model->insert({name => 'a'});
1409
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1410
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1411
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1412
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1413

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1414
test 'primary_key';
1415
use MyDBI1;
1416
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1417
$model = $dbi->model('book');
1418
$model->primary_key(['id', 'number']);
1419
is_deeply($model->primary_key, ['id', 'number']);
1420

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1421
test 'columns';
1422
use MyDBI1;
1423
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1424
$model = $dbi->model('book');
1425
$model->columns(['id', 'number']);
1426
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1427

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1428
test 'setup_model';
1429
use MyDBI1;
1430
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1431
$dbi->execute('create table book (id)');
1432
$dbi->execute('create table company (id, name);');
1433
$dbi->execute('create table test (id, name, primary key (id, name));');
1434
$dbi->setup_model;
1435
is_deeply($dbi->model('book')->columns, ['id']);
1436
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1437

            
1438
test 'delete_at';
1439
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1440
$dbi->execute($CREATE_TABLE->{1});
1441
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1442
$dbi->delete_at(
1443
    table => 'table1',
1444
    primary_key => ['key1', 'key2'],
1445
    where => [1, 2],
1446
);
1447
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1448

            
1449
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1450
$dbi->delete_at(
1451
    table => 'table1',
1452
    primary_key => 'key1',
1453
    where => 1,
1454
);
1455
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1456

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1457
test 'insert_at';
1458
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1459
$dbi->execute($CREATE_TABLE->{1});
1460
$dbi->insert_at(
1461
    primary_key => ['key1', 'key2'], 
1462
    table => 'table1',
1463
    where => [1, 2],
1464
    param => {key3 => 3}
1465
);
1466
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1467
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1468
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1469

            
1470
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1471
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1472
$dbi->insert_at(
1473
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1474
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1475
    where => 1,
1476
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1477
);
1478

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

            
1483
eval {
1484
    $dbi->insert_at(
1485
        table => 'table1',
1486
        primary_key => ['key1', 'key2'],
1487
        where => {},
1488
        param => {key1 => 1, key2 => 2, key3 => 3},
1489
    );
1490
};
1491
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1492

            
1493
test 'update_at';
1494
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1495
$dbi->execute($CREATE_TABLE->{1});
1496
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1497
$dbi->update_at(
1498
    table => 'table1',
1499
    primary_key => ['key1', 'key2'],
1500
    where => [1, 2],
1501
    param => {key3 => 4}
1502
);
1503
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1504
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1505
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1506

            
1507
$dbi->delete_all(table => 'table1');
1508
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1509
$dbi->update_at(
1510
    table => 'table1',
1511
    primary_key => 'key1',
1512
    where => 1,
1513
    param => {key3 => 4}
1514
);
1515
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1516
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1517
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1518

            
1519
test 'select_at';
1520
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1521
$dbi->execute($CREATE_TABLE->{1});
1522
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1523
$result = $dbi->select_at(
1524
    table => 'table1',
1525
    primary_key => ['key1', 'key2'],
1526
    where => [1, 2]
1527
);
1528
$row = $result->fetch_hash_first;
1529
is($row->{key1}, 1);
1530
is($row->{key2}, 2);
1531
is($row->{key3}, 3);
1532

            
1533
$dbi->delete_all(table => 'table1');
1534
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1535
$result = $dbi->select_at(
1536
    table => 'table1',
1537
    primary_key => 'key1',
1538
    where => 1,
1539
);
1540
$row = $result->fetch_hash_first;
1541
is($row->{key1}, 1);
1542
is($row->{key2}, 2);
1543
is($row->{key3}, 3);
1544

            
1545
$dbi->delete_all(table => 'table1');
1546
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1547
$result = $dbi->select_at(
1548
    table => 'table1',
1549
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1550
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1551
);
1552
$row = $result->fetch_hash_first;
1553
is($row->{key1}, 1);
1554
is($row->{key2}, 2);
1555
is($row->{key3}, 3);
1556

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1557
eval {
1558
    $result = $dbi->select_at(
1559
        table => 'table1',
1560
        primary_key => ['key1', 'key2'],
1561
        where => {},
1562
    );
1563
};
1564
like($@, qr/must be/);
1565

            
1566
eval {
1567
    $result = $dbi->update_at(
1568
        table => 'table1',
1569
        primary_key => ['key1', 'key2'],
1570
        where => {},
1571
        param => {key1 => 1, key2 => 2},
1572
    );
1573
};
1574
like($@, qr/must be/);
1575

            
1576
eval {
1577
    $result = $dbi->delete_at(
1578
        table => 'table1',
1579
        primary_key => ['key1', 'key2'],
1580
        where => {},
1581
    );
1582
};
1583
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1584

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1585
test 'columns';
1586
use MyDBI1;
1587
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1588
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1589

            
1590

            
1591
test 'model delete_at';
1592
{
1593
    package MyDBI6;
1594
    
1595
    use base 'DBIx::Custom';
1596
    
1597
    sub connect {
1598
        my $self = shift->SUPER::connect(@_);
1599
        
1600
        $self->include_model('MyModel5');
1601
        
1602
        return $self;
1603
    }
1604
}
1605
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1606
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1607
$dbi->execute("create table table2 (key1, key2, key3)");
1608
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1609
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1610
$dbi->model('table1')->delete_at(where => [1, 2]);
1611
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1612
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1613
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1614
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1615
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1616
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1617
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1618

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1619
test 'model insert_at';
1620
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1621
$dbi->execute($CREATE_TABLE->{1});
1622
$dbi->model('table1')->insert_at(
1623
    where => [1, 2],
1624
    param => {key3 => 3}
1625
);
1626
$result = $dbi->model('table1')->select;
1627
$row = $result->fetch_hash_first;
1628
is($row->{key1}, 1);
1629
is($row->{key2}, 2);
1630
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1631

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1632
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1633
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1634
$dbi->execute($CREATE_TABLE->{1});
1635
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1636
$dbi->model('table1')->update_at(
1637
    where => [1, 2],
1638
    param => {key3 => 4}
1639
);
1640
$result = $dbi->model('table1')->select;
1641
$row = $result->fetch_hash_first;
1642
is($row->{key1}, 1);
1643
is($row->{key2}, 2);
1644
is($row->{key3}, 4);
1645

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1646
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1647
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1648
$dbi->execute($CREATE_TABLE->{1});
1649
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1650
$result = $dbi->model('table1')->select_at(where => [1, 2]);
1651
$row = $result->fetch_hash_first;
1652
is($row->{key1}, 1);
1653
is($row->{key2}, 2);
1654
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1655

            
1656

            
cleanup
Yuki Kimoto authored on 2011-03-21
1657
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1658
{
1659
    package MyDBI7;
1660
    
1661
    use base 'DBIx::Custom';
1662
    
1663
    sub connect {
1664
        my $self = shift->SUPER::connect(@_);
1665
        
1666
        $self->include_model('MyModel6');
1667
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1668
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1669
        return $self;
1670
    }
1671
}
1672
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1673
$dbi->execute($CREATE_TABLE->{0});
1674
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1675
$dbi->setup_model;
1676
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1677
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1678
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1679
$result = $model->select(
1680
    column => [$model->mycolumn, $model->column('table2')],
1681
    where => {'table1.key1' => 1}
1682
);
1683
is_deeply($result->fetch_hash_first,
1684
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1685

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

            
1692
$param = {key2 => 11};
1693
$update_param = $dbi->update_param($param);
1694
$sql = <<"EOS";
1695
update {table table1} $update_param
1696
where key1 = 1
1697
EOS
1698
$dbi->execute($sql, param => $param);
1699
$result = $dbi->execute($SELECT_SOURCES->{0});
1700
$rows   = $result->fetch_hash_all;
1701
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1702
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1703
                  "basic");
1704

            
1705

            
1706
eval { $dbi->update_param({";" => 1}) };
1707
like($@, qr/not safety/);
1708

            
1709

            
1710
test 'insert_param';
1711
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1712
$dbi->execute($CREATE_TABLE->{1});
1713
$param = {key1 => 1};
1714
$insert_param = $dbi->insert_param($param);
1715
$sql = <<"EOS";
1716
insert into {table table1} $insert_param
1717
EOS
1718

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

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

            
1725

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1726
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1727
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1728
$dbi->execute($CREATE_TABLE->{0});
1729
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1730
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1731
$dbi->execute($CREATE_TABLE->{2});
1732
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1733
$dbi->execute($CREATE_TABLE->{4});
1734
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1735
$rows = $dbi->select(
1736
    table => 'table1',
1737
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1738
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1739
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1740
)->fetch_hash_all;
1741
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1742

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1743
$rows = $dbi->select(
1744
    table => 'table1',
1745
    where   => {'key1' => 1},
1746
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1747
)->fetch_hash_all;
1748
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1749

            
cleanup
Yuki Kimoto authored on 2011-03-08
1750
eval {
1751
    $rows = $dbi->select(
1752
        table => 'table1',
1753
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1754
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1755
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1756
    );
1757
};
1758
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1759

            
1760
$rows = $dbi->select(
1761
    table => 'table1',
1762
    where   => {'key1' => 1},
1763
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1764
              'left outer join table3 on table2.key3 = table3.key3']
1765
)->fetch_hash_all;
1766
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1767

            
1768
$rows = $dbi->select(
1769
    column => 'table3.key4 as table3__key4',
1770
    table => 'table1',
1771
    where   => {'table1.key1' => 1},
1772
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1773
              'left outer join table3 on table2.key3 = table3.key3']
1774
)->fetch_hash_all;
1775
is_deeply($rows, [{table3__key4 => 4}]);
1776

            
1777
$rows = $dbi->select(
1778
    column => 'table1.key1 as table1__key1',
1779
    table => 'table1',
1780
    where   => {'table3.key4' => 4},
1781
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1782
              'left outer join table3 on table2.key3 = table3.key3']
1783
)->fetch_hash_all;
1784
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1785

            
1786

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1787
test 'model join and column attribute and all_column option';
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1788
{
1789
    package MyDBI8;
1790
    
1791
    use base 'DBIx::Custom';
1792
    
1793
    sub connect {
1794
        my $self = shift->SUPER::connect(@_);
1795
        
1796
        $self->include_model('MyModel7');
1797
        
1798
        return $self;
1799
    }
1800
}
1801
$dbi = MyDBI8->connect($NEW_ARGS->{0});
1802
$dbi->execute($CREATE_TABLE->{0});
1803
$dbi->execute($CREATE_TABLE->{2});
1804
$dbi->setup_model;
1805
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1806
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1807
$model = $dbi->model('table1');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1808
$result = $model->select_at(
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1809
    column => {table => ['table1', 'table2'], prepend => 'table1.key1 as key1_1,'},
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1810
    where => 1
1811
);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1812
is_deeply($result->fetch_hash_first,
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1813
          {key1_1 => 1, key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1814
$result = $model->select(column => {all => 1});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1815
is_deeply($result->fetch_hash_first,
1816
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1817

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1818
test 'mycolumn';
1819
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1820
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1821
$dbi->execute($CREATE_TABLE->{2});
1822
$dbi->setup_model;
1823
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1824
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1825
$model = $dbi->model('table1');
1826
$result = $model->select_at(
1827
    column => [
1828
        $model->mycolumn,
1829
        $model->column('table2')
1830
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1831
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1832
is_deeply($result->fetch_hash_first,
1833
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1834
$result = $model->select_at(
1835
    column => [
1836
        $model->mycolumn(['key1']),
1837
        $model->column(table2 => ['key1'])
1838
    ]
1839
);
1840
is_deeply($result->fetch_hash_first,
1841
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1842

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1843
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1844
{
1845
    package MyDBI9;
1846
    
1847
    use base 'DBIx::Custom';
1848
    
1849
    sub connect {
1850
        my $self = shift->SUPER::connect(@_);
1851
        
1852
        $self->include_model('MyModel8')->setup_model;
1853
        
1854
        return $self;
1855
    }
1856
}
1857
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1858
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
1859
$model = $dbi->model('table1');
1860
eval{$model->execute('select * from table1')};
1861
ok(!$@);
1862

            
1863
test 'table_alias';
1864
$dbi = MyDBI9->connect($NEW_ARGS->{0});
1865
$dbi->execute($CREATE_TABLE->{0});
1866
$dbi->execute($CREATE_TABLE->{2});
1867
$dbi->setup_model;
1868
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
1869
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
1870
$model = $dbi->model('table1');
1871
$result = $model->select(
1872
    column => [
1873
        $model->column('table2_alias')
1874
    ],
1875
    where => {'table2_alias.key3' => 2}
1876
);
1877
is_deeply($result->fetch_hash_first, 
1878
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
1879

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1880
test 'type() option';
1881
$dbi = DBIx::Custom->connect(
1882
    data_source => 'dbi:SQLite:dbname=:memory:',
1883
    dbi_option => {
1884
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
1885
    }
1886
);
1887
my $binary = pack("I3", 1, 2, 3);
1888
$dbi->execute('create table table1(key1, key2)');
1889
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
1890
$result = $dbi->select(table => 'table1');
1891
$row   = $result->fetch_hash_first;
1892
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
1893
$result = $dbi->execute('select length(key1) as key1_length from table1');
1894
$row = $result->fetch_hash_first;
1895
is($row->{key1_length}, length $binary);
1896

            
1897
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
1898
$result = $dbi->select(table => 'table1');
1899
$row   = $result->fetch_hash_first;
1900
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
1901
$result = $dbi->execute('select length(key1) as key1_length from table1');
1902
$row = $result->fetch_hash_first;
1903
is($row->{key1_length}, length $binary);
1904