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

            
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
9
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
10

            
removed register_format()
yuki-kimoto authored on 2010-05-26
11
BEGIN {
12
    eval { require DBD::SQLite; 1 }
13
        or plan skip_all => 'DBD::SQLite required';
14
    eval { DBD::SQLite->VERSION >= 1.25 }
15
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
16

            
17
    plan 'no_plan';
18
    use_ok('DBIx::Custom');
19
}
20

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

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

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

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

            
40
my $DROP_TABLE = {
41
    0 => 'drop table table1'
42
};
43

            
44
my $NEW_ARGS = {
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
45
    0 => {dsn => 'dbi:SQLite:dbname=:memory:'}
removed register_format()
yuki-kimoto authored on 2010-05-26
46
};
47

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
207

            
208
test 'parameter';
209
$dbi->execute($DROP_TABLE->{0});
210
$dbi->execute($CREATE_TABLE->{1});
211
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
212
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
213

            
214
$source = "select * from table1 where key1 = :key1 and key2 = :key2";
215
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
216
$rows = $result->fetch_hash_all;
217
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
218

            
219
$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2";
220
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
221
$rows = $result->fetch_hash_all;
222
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
223

            
224
$source = "select * from table1 where key1 = :key1 or key1 = :key1";
225
$result = $dbi->execute($source, param => {key1 => [1, 2]});
226
$rows = $result->fetch_hash_all;
227
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
228

            
229
$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2";
230
$result = $dbi->execute(
231
    $source,
232
    param => {'table1.key1' => 1, 'table1.key2' => 1},
233
    filter => {'table1.key2' => sub { $_[0] * 2 }}
234
);
235
$rows = $result->fetch_hash_all;
236
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
237

            
removed register_format()
yuki-kimoto authored on 2010-05-26
238
test 'Error case';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
239
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')};
cleanup
Yuki Kimoto authored on 2011-01-23
240
ok($@, "connect error");
removed register_format()
yuki-kimoto authored on 2010-05-26
241

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

            
246
test 'insert';
247
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
248
$dbi->execute($CREATE_TABLE->{0});
249
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
250
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
251
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
252
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
253
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
254

            
255
$dbi->execute('delete from table1');
256
$dbi->register_filter(
257
    twice       => sub { $_[0] * 2 },
258
    three_times => sub { $_[0] * 3 }
259
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
260
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
261
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
262
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
263
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
264
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
265
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
266

            
267
$dbi->execute($DROP_TABLE->{0});
268
$dbi->execute($CREATE_TABLE->{0});
269
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
270
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
271
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
272

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
279
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
280
$dbi->reserved_word_quote('"');
281
$dbi->execute('create table "table" ("select")');
282
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
283
$dbi->insert(table => 'table', param => {select => 1});
284
$result = $dbi->execute('select * from "table"');
285
$rows   = $result->fetch_hash_all;
286
is_deeply($rows, [{select => 2}], "reserved word");
287

            
removed register_format()
yuki-kimoto authored on 2010-05-26
288
test 'update';
289
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
290
$dbi->execute($CREATE_TABLE->{1});
291
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
292
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
293
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
294
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
295
$rows   = $result->fetch_hash_all;
296
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
297
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
298
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
299
                  
300
$dbi->execute("delete from table1");
301
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
302
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
303
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
304
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
305
$rows   = $result->fetch_hash_all;
306
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
307
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
308
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
309

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
317
$dbi->execute("delete from table1");
318
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
319
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
320
$dbi->register_filter(twice => sub { $_[0] * 2 });
321
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
322
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
323
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
324
$rows   = $result->fetch_hash_all;
325
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
326
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
327
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
328

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
337
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
338
$dbi->execute($CREATE_TABLE->{0});
339
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
340
$where = $dbi->where;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
341
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
342
$where->param({key1 => 1, key2 => 2});
343
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
344
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
345
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
346

            
347
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
348
$dbi->execute($CREATE_TABLE->{0});
349
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
350
$dbi->update(
351
    table => 'table1',
352
    param => {key1 => 3},
353
    where => [
354
        ['and', '{= key1}', '{= key2}'],
355
        {key1 => 1, key2 => 2}
356
    ]
357
);
358
$result = $dbi->select(table => 'table1');
359
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
360

            
361
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
362
$dbi->execute($CREATE_TABLE->{0});
363
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
364
$where = $dbi->where;
365
$where->clause(['and', '{= key2}']);
366
$where->param({key2 => 2});
367
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
368
$result = $dbi->select(table => 'table1');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
369
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
370

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
377
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
378
$dbi->reserved_word_quote('"');
379
$dbi->execute('create table "table" ("select", "update")');
380
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
381
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
382
$dbi->insert(table => 'table', param => {select => 1});
383
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
384
$result = $dbi->execute('select * from "table"');
385
$rows   = $result->fetch_hash_all;
386
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
387

            
388
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
389
like($@, qr/safety/);
390

            
391
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
392
$dbi->reserved_word_quote('"');
393
$dbi->execute('create table "table" ("select", "update")');
394
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
395
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
396
$dbi->insert(table => 'table', param => {select => 1});
397
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
398
$result = $dbi->execute('select * from "table"');
399
$rows   = $result->fetch_hash_all;
400
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
401

            
removed register_format()
yuki-kimoto authored on 2010-05-26
402
test 'update_all';
403
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
404
$dbi->execute($CREATE_TABLE->{1});
405
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
406
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
407
$dbi->register_filter(twice => sub { $_[0] * 2 });
408
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
409
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
410
$rows   = $result->fetch_hash_all;
411
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
412
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
413
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
414

            
415

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

            
426
$dbi->execute("delete from table1;");
427
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
428
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
429
$dbi->register_filter(twice => sub { $_[0] * 2 });
430
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
431
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
432
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
433
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
434

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

            
437
$dbi->delete_all(table => 'table1');
438
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
439
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
440
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
441
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
442
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
443

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
447
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
448
$dbi->execute($CREATE_TABLE->{0});
449
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
450
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
451
$where = $dbi->where;
452
$where->clause(['and', '{= key1}', '{= key2}']);
453
$where->param({ke1 => 1, key2 => 2});
454
$dbi->delete(table => 'table1', where => $where);
455
$result = $dbi->select(table => 'table1');
456
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
457

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
458
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
459
$dbi->execute($CREATE_TABLE->{0});
460
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
461
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
462
$dbi->delete(
463
    table => 'table1',
464
    where => [
465
        ['and', '{= key1}', '{= key2}'],
466
        {ke1 => 1, key2 => 2}
467
    ]
468
);
469
$result = $dbi->select(table => 'table1');
470
is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
471

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
482
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
483
$dbi->reserved_word_quote('"');
484
$dbi->execute('create table "table" ("select", "update")');
485
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
486
$dbi->insert(table => 'table', param => {select => 1});
487
$dbi->delete(table => 'table', where => {select => 1});
488
$result = $dbi->execute('select * from "table"');
489
$rows   = $result->fetch_hash_all;
490
is_deeply($rows, [], "reserved word");
491

            
removed register_format()
yuki-kimoto authored on 2010-05-26
492
test 'delete_all';
493
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
494
$dbi->execute($CREATE_TABLE->{0});
495
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
496
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
497
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
498
$result = $dbi->execute($SELECT_SOURCES->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
499
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
500
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
501

            
502

            
503
test 'select';
504
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
505
$dbi->execute($CREATE_TABLE->{0});
506
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
507
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
508
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
509
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
510
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
511

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

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

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

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

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

            
529
$dbi->execute($CREATE_TABLE->{2});
530
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
531
$rows = $dbi->select(
532
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
533
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
534
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
535
    relation  => {'table1.key1' => 'table2.key1'}
removed register_format()
yuki-kimoto authored on 2010-05-26
536
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
537
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
538

            
539
$rows = $dbi->select(
540
    table => [qw/table1 table2/],
541
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
542
    relation  => {'table1.key1' => 'table2.key1'}
543
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
544
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
545

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
549
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
550
$dbi->reserved_word_quote('"');
551
$dbi->execute('create table "table" ("select", "update")');
552
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
553
$dbi->insert(table => 'table', param => {select => 1, update => 2});
554
$result = $dbi->select(table => 'table', where => {select => 1});
555
$rows   = $result->fetch_hash_all;
556
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
557

            
removed register_format()
yuki-kimoto authored on 2010-05-26
558
test 'fetch filter';
559
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
560
$dbi->register_filter(
561
    twice       => sub { $_[0] * 2 },
562
    three_times => sub { $_[0] * 3 }
563
);
564
$dbi->default_fetch_filter('twice');
565
$dbi->execute($CREATE_TABLE->{0});
566
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
567
$result = $dbi->select(table => 'table1');
568
$result->filter({key1 => 'three_times'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
569
$row = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
570
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
571

            
572
test 'filters';
573
$dbi = DBIx::Custom->new;
574

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
581
test 'transaction';
582
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
583
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
584
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
585
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
586
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
587
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
588
$result = $dbi->select(table => 'table1');
589
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
590
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
591

            
592
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
593
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
594
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
595
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
596
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
597

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

            
601
test 'cache';
602
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
603
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
604
$dbi->execute($CREATE_TABLE->{0});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
605
$source = 'select * from table1 where {= key1} and {= key2};';
606
$dbi->create_query($source);
607
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
608
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
609

            
610
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
611
$dbi->execute($CREATE_TABLE->{0});
612
$dbi->{_cached} = {};
613
$dbi->cache(0);
614
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
615
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
616

            
add tests
yuki-kimoto authored on 2010-08-10
617
test 'execute';
618
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
619
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
620
{
621
    local $Carp::Verbose = 0;
622
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
623
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
624
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
625
}
626
{
627
    local $Carp::Verbose = 1;
628
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
629
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
630
}
add tests
yuki-kimoto authored on 2010-08-10
631

            
632
eval{$dbi->execute('select * from table1', no_exists => 1)};
improved error messages
Yuki Kimoto authored on 2011-04-18
633
like($@, qr/wrong/, "invald SQL");
add tests
yuki-kimoto authored on 2010-08-10
634

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
640
{
641
    local $Carp::Verbose = 0;
642
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
643
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
644
}
645
{
646
    local $Carp::Verbose = 1;
647
    eval{$dbi->create_query('select * from table1 where {0 key1}')};
cleanup
Yuki Kimoto authored on 2011-01-23
648
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
649
}
cleanup
yuki-kimoto authored on 2010-10-17
650

            
651

            
652
test 'transaction';
653
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
654
$dbi->execute($CREATE_TABLE->{0});
655

            
656
$dbi->begin_work;
657

            
658
eval {
659
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
660
    die "Error";
661
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
662
};
663

            
664
$dbi->rollback if $@;
665

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

            
670
$dbi->begin_work;
671

            
672
eval {
673
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
674
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
675
};
676

            
677
$dbi->commit unless $@;
678

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

            
683
$dbi->dbh->{AutoCommit} = 0;
684
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
685
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
686
$dbi->dbh->{AutoCommit} = 1;
687

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
689
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
690
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
691
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
692
    one => sub { 1 }
693
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
694
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
695
    two => sub { 2 }
696
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
697
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
698
    twice => sub {
699
        my $self = shift;
700
        return $_[0] * 2;
701
    }
702
});
703

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
711
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
712
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
713
$dbi->execute($CREATE_TABLE->{0});
714
$dbi->register_filter(twice => sub { $_[0] * 2 });
715
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
716
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
717
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
718
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
719
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
720
$result = $dbi->execute($SELECT_SOURCES->{0});
721
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
722
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
723
$result = $dbi->select(table => 'table1');
724
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
725
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
726

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
727
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
728
$dbi->execute($CREATE_TABLE->{0});
729
$dbi->register_filter(twice => sub { $_[0] * 2 });
730
$dbi->register_filter(three_times => sub { $_[0] * 3});
731
$dbi->apply_filter(
732
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
733
              'key2' => {out => 'three_times', in => 'twice'});
734
$dbi->apply_filter(
735
    'table1', 'key1' => {out => undef}
736
); 
737
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
738
$result = $dbi->execute($SELECT_SOURCES->{0});
739
$row   = $result->fetch_hash_first;
740
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
741

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
742
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
743
$dbi->execute($CREATE_TABLE->{0});
744
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
745
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
746
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
747
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
748
$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
749
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
750
$result = $dbi->execute($SELECT_SOURCES->{0});
751
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
752
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
753

            
754
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
755
$dbi->execute($CREATE_TABLE->{0});
756
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
757
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
758
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
759
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
760
$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
761
$dbi->delete(table => 'table1', where => {key1 => 1});
762
$result = $dbi->execute($SELECT_SOURCES->{0});
763
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
764
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
765

            
766
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
767
$dbi->execute($CREATE_TABLE->{0});
768
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
769
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
770
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
771
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
772
$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
773
$result = $dbi->select(table => 'table1', where => {key1 => 1});
774
$result->filter({'key2' => 'twice'});
775
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
776
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
777

            
778
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
779
$dbi->execute($CREATE_TABLE->{0});
780
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
781
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
782
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
783
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
784
$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
785
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
786
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
787
                        table => ['table1']);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
788
$rows   = $result->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
789
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
790

            
add table tag
Yuki Kimoto authored on 2011-02-09
791
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
792
$dbi->execute($CREATE_TABLE->{0});
793
$dbi->register_filter(twice => sub { $_[0] * 2 });
794
$dbi->apply_filter(
795
    'table1', 'key1' => {out => 'twice', in => 'twice'}
796
);
797
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
798
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
799
                        param => {key1 => 1, key2 => 2});
800
$rows   = $result->fetch_hash_all;
801
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
802

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
803
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
804
$dbi->execute($CREATE_TABLE->{0});
805
$dbi->execute($CREATE_TABLE->{2});
806
$dbi->register_filter(twice => sub { $_[0] * 2 });
807
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
808
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
809
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
810
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
811
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
812
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
813
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
814
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
815
$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
816
$result = $dbi->select(
817
     table => ['table1', 'table2'],
818
     column => ['key2', 'key3'],
819
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
820

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

            
825
$result = $dbi->select(
826
     table => ['table1', 'table2'],
827
     column => ['key2', 'key3'],
828
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
829

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
834
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
835
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
836
$dbi->execute($CREATE_TABLE->{2});
837
$dbi->execute($CREATE_TABLE->{3});
838

            
839
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
840
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
841
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
842
    
843
    if ($table =~ /^table/) {
844
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
845
         push @$infos, $info;
846
    }
847
});
848
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
849
is_deeply($infos, 
850
    [
851
        ['table1', 'key1', 'key1'],
852
        ['table1', 'key2', 'key2'],
853
        ['table2', 'key1', 'key1'],
854
        ['table2', 'key3', 'key3']
855
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
856
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
857
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
858

            
add examples
Yuki Kimoto authored on 2011-01-07
859
test 'limit';
860
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
861
$dbi->execute($CREATE_TABLE->{0});
862
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
863
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
864
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
865
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
866
    limit => sub {
867
        my ($count, $offset) = @_;
868
        
869
        my $s = '';
870
        $s .= "limit $count";
871
        $s .= " offset $offset" if defined $offset;
872
        
873
        return [$s, []];
874
    }
875
);
876
$rows = $dbi->select(
877
  table => 'table1',
878
  where => {key1 => 1},
879
  append => "order by key2 {limit 1 0}"
880
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
881
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
882
$rows = $dbi->select(
883
  table => 'table1',
884
  where => {key1 => 1},
885
  append => "order by key2 {limit 2 1}"
886
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
887
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
888
$rows = $dbi->select(
889
  table => 'table1',
890
  where => {key1 => 1},
891
  append => "order by key2 {limit 1}"
892
)->fetch_hash_all;
cleanup
Yuki Kimoto authored on 2011-01-23
893
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
894

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
895
test 'connect super';
896
{
897
    package MyDBI;
898
    
899
    use base 'DBIx::Custom';
900
    sub connect {
901
        my $self = shift->SUPER::connect(@_);
902
        
903
        return $self;
904
    }
905
    
906
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
907
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
908
        
909
        return $self;
910
    }
911
}
912

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
924
{
925
    package MyDBI2;
926
    
927
    use base 'DBIx::Custom';
928
    sub connect {
929
        my $self = shift->SUPER::new(@_);
930
        $self->connect;
931
        
932
        return $self;
933
    }
934
}
935

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

            
941
test 'end_filter';
942
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
943
$dbi->execute($CREATE_TABLE->{0});
944
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
945
$result = $dbi->select(table => 'table1');
946
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
947
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
948
$row = $result->fetch_first;
949
is_deeply($row, [6, 40]);
950

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
951
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
952
$dbi->execute($CREATE_TABLE->{0});
953
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
954
$result = $dbi->select(table => 'table1');
955
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
956
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
957
$row = $result->fetch_first;
958
is_deeply($row, [6, 12]);
959

            
960
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
961
$dbi->execute($CREATE_TABLE->{0});
962
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
963
$result = $dbi->select(table => 'table1');
964
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
965
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
966
$row = $result->fetch_first;
967
is_deeply($row, [6, 12]);
968

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
976
$dbi->register_filter(five_times => sub { $_[0] * 5 });
977
$dbi->apply_filter('table1',
978
    key1 => {end => sub { $_[0] * 3 } },
979
    key2 => {end => 'five_times'}
980
);
981
$result = $dbi->select(table => 'table1');
982
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
983
$row = $result->fetch_hash_first;
984
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
985

            
986
$dbi->register_filter(five_times => sub { $_[0] * 5 });
987
$dbi->apply_filter('table1',
988
    key1 => {end => sub { $_[0] * 3 } },
989
    key2 => {end => 'five_times'}
990
);
991
$result = $dbi->select(table => 'table1');
992
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
993
$result->filter(key1 => undef);
994
$result->end_filter(key1 => undef);
995
$row = $result->fetch_hash_first;
996
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
997

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
998
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
999
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1000
$dbi->execute($CREATE_TABLE->{0});
1001
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1002
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1003
$row = $result
1004
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1005
       ->remove_filter
1006
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1007
       ->remove_end_filter
1008
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1009
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1010

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1011
test 'empty where select';
1012
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1013
$dbi->execute($CREATE_TABLE->{0});
1014
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1015
$result = $dbi->select(table => 'table1', where => {});
1016
$row = $result->fetch_hash_first;
1017
is_deeply($row, {key1 => 1, key2 => 2});
1018

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1019
test 'select query option';
1020
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1021
$dbi->execute($CREATE_TABLE->{0});
1022
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1023
is(ref $query, 'DBIx::Custom::Query');
1024
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1025
is(ref $query, 'DBIx::Custom::Query');
1026
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1027
is(ref $query, 'DBIx::Custom::Query');
1028
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1029
is(ref $query, 'DBIx::Custom::Query');
1030

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1031
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1032
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1033
$dbi->execute($CREATE_TABLE->{0});
1034
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1035
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1036
$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
1037
is("$where", "where ( {= key1} and {= key2} )", 'no param');
1038

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

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1050
$result = $dbi->select(
1051
    table => 'table1',
1052
    where => [
1053
        ['and', '{= key1}', '{= key2}'],
1054
        {key1 => 1}
1055
    ]
1056
);
1057
$row = $result->fetch_hash_all;
1058
is_deeply($row, [{key1 => 1, key2 => 2}]);
1059

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1060
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1061
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1062
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1063
$result = $dbi->select(
1064
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1065
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1066
);
1067
$row = $result->fetch_hash_all;
1068
is_deeply($row, [{key1 => 1, key2 => 2}]);
1069

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1070
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1071
             ->clause(['and', '{= key1}', '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1072
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1073
$result = $dbi->select(
1074
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1075
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1076
);
1077
$row = $result->fetch_hash_all;
1078
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1079

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1080
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1081
             ->clause(['and', ['or', '{> key1}', '{< key1}'], '{= key2}'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1082
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1083
$result = $dbi->select(
1084
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1085
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1086
); 
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1087
$row = $result->fetch_hash_all;
1088
is_deeply($row, [{key1 => 1, key2 => 2}]);
1089

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1090
$where = $dbi->where;
1091
$result = $dbi->select(
1092
    table => 'table1',
1093
    where => $where
1094
);
1095
$row = $result->fetch_hash_all;
1096
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1097

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1098
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1099
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1100
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1101
$result = $dbi->select(
1102
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1103
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1104
);
1105
};
1106
ok($@);
1107

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

            
added test
Yuki Kimoto authored on 2011-01-19
1111
$where = $dbi->where
1112
             ->clause(['or', ('{= key1}') x 2])
1113
             ->param({key1 => [1, 3]});
1114
$result = $dbi->select(
1115
    table => 'table1',
1116
    where => $where,
1117
);
1118
$row = $result->fetch_hash_all;
1119
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1120

            
1121
$where = $dbi->where
1122
             ->clause(['or', ('{= key1}') x 2])
1123
             ->param({key1 => [1]});
1124
$result = $dbi->select(
1125
    table => 'table1',
1126
    where => $where,
1127
);
1128
$row = $result->fetch_hash_all;
1129
is_deeply($row, [{key1 => 1, key2 => 2}]);
1130

            
1131
$where = $dbi->where
1132
             ->clause(['or', ('{= key1}') x 2])
1133
             ->param({key1 => 1});
1134
$result = $dbi->select(
1135
    table => 'table1',
1136
    where => $where,
1137
);
1138
$row = $result->fetch_hash_all;
1139
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1140

            
many changed
Yuki Kimoto authored on 2011-01-23
1141
$where = $dbi->where
1142
             ->clause('{= key1}')
1143
             ->param({key1 => 1});
1144
$result = $dbi->select(
1145
    table => 'table1',
1146
    where => $where,
1147
);
1148
$row = $result->fetch_hash_all;
1149
is_deeply($row, [{key1 => 1, key2 => 2}]);
1150

            
1151
$where = $dbi->where
1152
             ->clause('{= key1} {= key2}')
1153
             ->param({key1 => 1});
1154
eval{$where->to_string};
1155
like($@, qr/one column/);
1156

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1157
$where = $dbi->where
1158
             ->clause('{= key1}')
1159
             ->param([]);
1160
eval{$where->to_string};
1161
like($@, qr/Parameter/);
1162

            
1163
$where = $dbi->where
1164
             ->clause(['or', ('{= key1}') x 3])
1165
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1166
$result = $dbi->select(
1167
    table => 'table1',
1168
    where => $where,
1169
);
1170
$row = $result->fetch_hash_all;
1171
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1172

            
1173
$where = $dbi->where
1174
             ->clause(['or', ('{= key1}') x 3])
1175
             ->param({key1 => [1, $dbi->not_exists, 3]});
1176
$result = $dbi->select(
1177
    table => 'table1',
1178
    where => $where,
1179
);
1180
$row = $result->fetch_hash_all;
1181
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1182

            
1183
$where = $dbi->where
1184
             ->clause(['or', ('{= key1}') x 3])
1185
             ->param({key1 => [1, 3, $dbi->not_exists]});
1186
$result = $dbi->select(
1187
    table => 'table1',
1188
    where => $where,
1189
);
1190
$row = $result->fetch_hash_all;
1191
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1192

            
1193
$where = $dbi->where
1194
             ->clause(['or', ('{= key1}') x 3])
1195
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1196
$result = $dbi->select(
1197
    table => 'table1',
1198
    where => $where,
1199
);
1200
$row = $result->fetch_hash_all;
1201
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1202

            
1203
$where = $dbi->where
1204
             ->clause(['or', ('{= key1}') x 3])
1205
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1206
$result = $dbi->select(
1207
    table => 'table1',
1208
    where => $where,
1209
);
1210
$row = $result->fetch_hash_all;
1211
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1212

            
1213
$where = $dbi->where
1214
             ->clause(['or', ('{= key1}') x 3])
1215
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1216
$result = $dbi->select(
1217
    table => 'table1',
1218
    where => $where,
1219
);
1220
$row = $result->fetch_hash_all;
1221
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1222

            
1223
$where = $dbi->where
1224
             ->clause(['or', ('{= key1}') x 3])
1225
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1226
$result = $dbi->select(
1227
    table => 'table1',
1228
    where => $where,
1229
);
1230
$row = $result->fetch_hash_all;
1231
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1232

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1233
$where = $dbi->where
1234
             ->clause(['or', ('{= key1}') x 3])
1235
             ->param({key1 => []});
1236
$result = $dbi->select(
1237
    table => 'table1',
1238
    where => $where,
1239
);
1240
$row = $result->fetch_hash_all;
1241
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1242

            
1243
$where = $dbi->where
1244
             ->clause(['and', '{> key1}', '{< key1}' ])
1245
             ->param({key1 => [2, $dbi->not_exists]});
1246
$result = $dbi->select(
1247
    table => 'table1',
1248
    where => $where,
1249
);
1250
$row = $result->fetch_hash_all;
1251
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1252

            
1253
$where = $dbi->where
1254
             ->clause(['and', '{> key1}', '{< key1}' ])
1255
             ->param({key1 => [$dbi->not_exists, 2]});
1256
$result = $dbi->select(
1257
    table => 'table1',
1258
    where => $where,
1259
);
1260
$row = $result->fetch_hash_all;
1261
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1262

            
1263
$where = $dbi->where
1264
             ->clause(['and', '{> key1}', '{< key1}' ])
1265
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1266
$result = $dbi->select(
1267
    table => 'table1',
1268
    where => $where,
1269
);
1270
$row = $result->fetch_hash_all;
1271
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1272

            
1273
$where = $dbi->where
1274
             ->clause(['and', '{> key1}', '{< key1}' ])
1275
             ->param({key1 => [0, 2]});
1276
$result = $dbi->select(
1277
    table => 'table1',
1278
    where => $where,
1279
);
1280
$row = $result->fetch_hash_all;
1281
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1282

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1283
$where = $dbi->where
1284
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1285
$result = $dbi->select(
1286
    table => 'table1',
1287
    where => $where,
1288
);
1289
$row = $result->fetch_hash_all;
1290
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1291

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1292
eval {$dbi->where(ppp => 1) };
1293
like($@, qr/invalid/);
1294

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1299
test 'register_tag_processor';
1300
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1301
$dbi->register_tag_processor(
1302
    a => sub { 1 }
1303
);
1304
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1305

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1306
test 'register_tag';
1307
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1308
$dbi->register_tag(
1309
    b => sub { 2 }
1310
);
1311
is($dbi->query_builder->tags->{b}->(), 2);
1312

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1313
test 'table not specify exception';
1314
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1315
eval {$dbi->insert};
1316
like($@, qr/table/);
1317
eval {$dbi->update};
1318
like($@, qr/table/);
1319
eval {$dbi->delete};
1320
like($@, qr/table/);
1321
eval {$dbi->select};
1322
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1323

            
1324

            
1325
test 'more tests';
1326
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1327
eval{$dbi->apply_filter('table', 'column', [])};
1328
like($@, qr/apply_filter/);
1329

            
1330
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1331
like($@, qr/apply_filter/);
1332

            
1333
$dbi->apply_filter(
1334

            
1335
);
1336
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1337
$dbi->execute($CREATE_TABLE->{0});
1338
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1339
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1340
$dbi->apply_filter('table1', 'key2', 
1341
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
1342
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
1343
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1344

            
1345
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1346
$dbi->execute($CREATE_TABLE->{0});
1347
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1348
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1349
$dbi->apply_filter('table1', 'key2', {});
1350
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
1351
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1352

            
1353
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1354
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1355
like($@, qr/not registered/);
1356
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1357
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1358
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1359
is($dbi->one, 1);
1360

            
1361
eval{DBIx::Custom->connect()};
cleanup
Yuki Kimoto authored on 2011-04-25
1362
like($@, qr/_connect/);
many changed
Yuki Kimoto authored on 2011-01-23
1363

            
1364
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1365
$dbi->execute($CREATE_TABLE->{0});
1366
$dbi->register_filter(twice => sub { $_[0] * 2 });
1367
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1368
             filter => {key1 => 'twice'});
1369
$row = $dbi->select(table => 'table1')->fetch_hash_first;
1370
is_deeply($row, {key1 => 2, key2 => 2});
1371
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1372
             filter => {key1 => 'no'}) };
1373
like($@, qr//);
1374

            
1375
$dbi->register_filter(one => sub { });
1376
$dbi->default_fetch_filter('one');
1377
ok($dbi->default_fetch_filter);
1378
$dbi->default_bind_filter('one');
1379
ok($dbi->default_bind_filter);
1380
eval{$dbi->default_fetch_filter('no')};
1381
like($@, qr/not registered/);
1382
eval{$dbi->default_bind_filter('no')};
1383
like($@, qr/not registered/);
1384
$dbi->default_bind_filter(undef);
1385
ok(!defined $dbi->default_bind_filter);
1386
$dbi->default_fetch_filter(undef);
1387
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1388
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1389
like($@, qr/Tag not finished/);
1390

            
1391
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1392
$dbi->execute($CREATE_TABLE->{0});
1393
$dbi->register_filter(one => sub { 1 });
1394
$result = $dbi->select(table => 'table1');
1395
eval {$result->filter(key1 => 'no')};
1396
like($@, qr/not registered/);
1397
eval {$result->end_filter(key1 => 'no')};
1398
like($@, qr/not registered/);
1399
$result->default_filter(undef);
1400
ok(!defined $result->default_filter);
1401
$result->default_filter('one');
1402
is($result->default_filter->(), 1);
1403

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1404
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1405
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1406
                             dbi_option => {PrintError => 1});
1407
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1408
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1409
                             dbi_options => {PrintError => 1});
1410
ok($dbi->dbh->{PrintError});
1411

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1412
test 'DBIx::Custom::Result stash()';
1413
$result = DBIx::Custom::Result->new;
1414
is_deeply($result->stash, {}, 'default');
1415
$result->stash->{foo} = 1;
1416
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1417

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1418
test 'filter __ expression';
1419
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1420
$dbi->execute('create table company (id, name, location_id)');
1421
$dbi->execute('create table location (id, name)');
1422
$dbi->apply_filter('location',
1423
  name => {in => sub { uc $_[0] } }
1424
);
1425

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

            
1429
$result = $dbi->select(
1430
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1431
    column => ['location.name as location__name']
1432
);
1433
is($result->fetch_first->[0], 'B');
1434

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1435
$result = $dbi->select(
1436
    table => 'company', relation => {'company.location_id' => 'location.id'},
1437
    column => ['location.name as location__name']
1438
);
1439
is($result->fetch_first->[0], 'B');
1440

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1441
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1442
use MyDBI1;
1443
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1444
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1445
$model = $dbi->model('book');
1446
$model->insert({title => 'a', author => 'b'});
1447
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1448
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1449
$model = $dbi->model('company');
1450
$model->insert({name => 'a'});
1451
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1452
is($dbi->models->{'book'}, $dbi->model('book'));
1453
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1454

            
1455
{
1456
    package MyDBI4;
1457

            
1458
    use strict;
1459
    use warnings;
1460

            
1461
    use base 'DBIx::Custom';
1462

            
1463
    sub connect {
1464
        my $self = shift->SUPER::connect(@_);
1465
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1466
        $self->include_model(
1467
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1468
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1469
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1470
            ]
1471
        );
1472
    }
1473

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

            
1476
    use strict;
1477
    use warnings;
1478

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

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

            
1483
    use strict;
1484
    use warnings;
1485

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

            
1488
    sub insert {
1489
        my ($self, $param) = @_;
1490
        
1491
        return $self->SUPER::insert(param => $param);
1492
    }
1493

            
1494
    sub list { shift->select; }
1495

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

            
1498
    use strict;
1499
    use warnings;
1500

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

            
1503
    sub insert {
1504
        my ($self, $param) = @_;
1505
        
1506
        return $self->SUPER::insert(param => $param);
1507
    }
1508

            
1509
    sub list { shift->select; }
1510
}
1511
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1512
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1513
$model = $dbi->model('book');
1514
$model->insert({title => 'a', author => 'b'});
1515
is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1516
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1517
$model = $dbi->model('company');
1518
$model->insert({name => 'a'});
1519
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
1520

            
1521
{
1522
     package MyDBI5;
1523

            
1524
    use strict;
1525
    use warnings;
1526

            
1527
    use base 'DBIx::Custom';
1528

            
1529
    sub connect {
1530
        my $self = shift->SUPER::connect(@_);
1531
        
1532
        $self->include_model('MyModel4');
1533
    }
1534
}
1535
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1536
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1537
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1538
$model = $dbi->model('company');
1539
$model->insert({name => 'a'});
1540
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1541
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1542
$model = $dbi->model('book');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1543
is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1544

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1545
test 'primary_key';
1546
use MyDBI1;
1547
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1548
$model = $dbi->model('book');
1549
$model->primary_key(['id', 'number']);
1550
is_deeply($model->primary_key, ['id', 'number']);
1551

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1552
test 'columns';
1553
use MyDBI1;
1554
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1555
$model = $dbi->model('book');
1556
$model->columns(['id', 'number']);
1557
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1558

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1559
test 'setup_model';
1560
use MyDBI1;
1561
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1562
$dbi->execute('create table book (id)');
1563
$dbi->execute('create table company (id, name);');
1564
$dbi->execute('create table test (id, name, primary key (id, name));');
1565
$dbi->setup_model;
1566
is_deeply($dbi->model('book')->columns, ['id']);
1567
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1568

            
1569
test 'delete_at';
1570
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1571
$dbi->execute($CREATE_TABLE->{1});
1572
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1573
$dbi->delete_at(
1574
    table => 'table1',
1575
    primary_key => ['key1', 'key2'],
1576
    where => [1, 2],
1577
);
1578
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1579

            
1580
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1581
$dbi->delete_at(
1582
    table => 'table1',
1583
    primary_key => 'key1',
1584
    where => 1,
1585
);
1586
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
1587

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1588
test 'insert_at';
1589
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1590
$dbi->execute($CREATE_TABLE->{1});
1591
$dbi->insert_at(
1592
    primary_key => ['key1', 'key2'], 
1593
    table => 'table1',
1594
    where => [1, 2],
1595
    param => {key3 => 3}
1596
);
1597
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1598
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1599
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 3);
1600

            
1601
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1602
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1603
$dbi->insert_at(
1604
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1605
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1606
    where => 1,
1607
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1608
);
1609

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

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

            
1624
test 'update_at';
1625
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1626
$dbi->execute($CREATE_TABLE->{1});
1627
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1628
$dbi->update_at(
1629
    table => 'table1',
1630
    primary_key => ['key1', 'key2'],
1631
    where => [1, 2],
1632
    param => {key3 => 4}
1633
);
1634
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1635
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1636
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1637

            
1638
$dbi->delete_all(table => 'table1');
1639
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1640
$dbi->update_at(
1641
    table => 'table1',
1642
    primary_key => 'key1',
1643
    where => 1,
1644
    param => {key3 => 4}
1645
);
1646
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1647
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
1648
is($dbi->select(table => 'table1')->fetch_hash_first->{key3}, 4);
1649

            
1650
test 'select_at';
1651
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1652
$dbi->execute($CREATE_TABLE->{1});
1653
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1654
$result = $dbi->select_at(
1655
    table => 'table1',
1656
    primary_key => ['key1', 'key2'],
1657
    where => [1, 2]
1658
);
1659
$row = $result->fetch_hash_first;
1660
is($row->{key1}, 1);
1661
is($row->{key2}, 2);
1662
is($row->{key3}, 3);
1663

            
1664
$dbi->delete_all(table => 'table1');
1665
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1666
$result = $dbi->select_at(
1667
    table => 'table1',
1668
    primary_key => 'key1',
1669
    where => 1,
1670
);
1671
$row = $result->fetch_hash_first;
1672
is($row->{key1}, 1);
1673
is($row->{key2}, 2);
1674
is($row->{key3}, 3);
1675

            
1676
$dbi->delete_all(table => 'table1');
1677
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1678
$result = $dbi->select_at(
1679
    table => 'table1',
1680
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1681
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1682
);
1683
$row = $result->fetch_hash_first;
1684
is($row->{key1}, 1);
1685
is($row->{key2}, 2);
1686
is($row->{key3}, 3);
1687

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1688
eval {
1689
    $result = $dbi->select_at(
1690
        table => 'table1',
1691
        primary_key => ['key1', 'key2'],
1692
        where => {},
1693
    );
1694
};
1695
like($@, qr/must be/);
1696

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1697
eval {
1698
    $result = $dbi->select_at(
1699
        table => 'table1',
1700
        primary_key => ['key1', 'key2'],
1701
        where => [1],
1702
    );
1703
};
1704
like($@, qr/same/);
1705

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1706
eval {
1707
    $result = $dbi->update_at(
1708
        table => 'table1',
1709
        primary_key => ['key1', 'key2'],
1710
        where => {},
1711
        param => {key1 => 1, key2 => 2},
1712
    );
1713
};
1714
like($@, qr/must be/);
1715

            
1716
eval {
1717
    $result = $dbi->delete_at(
1718
        table => 'table1',
1719
        primary_key => ['key1', 'key2'],
1720
        where => {},
1721
    );
1722
};
1723
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1724

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1725
test 'columns';
1726
use MyDBI1;
1727
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1728
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1729

            
1730

            
1731
test 'model delete_at';
1732
{
1733
    package MyDBI6;
1734
    
1735
    use base 'DBIx::Custom';
1736
    
1737
    sub connect {
1738
        my $self = shift->SUPER::connect(@_);
1739
        
1740
        $self->include_model('MyModel5');
1741
        
1742
        return $self;
1743
    }
1744
}
1745
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1746
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1747
$dbi->execute("create table table2 (key1, key2, key3)");
1748
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1749
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1750
$dbi->model('table1')->delete_at(where => [1, 2]);
1751
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1752
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1753
$dbi->model('table1_1')->delete_at(where => [1, 2]);
1754
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1755
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1756
$dbi->model('table1_3')->delete_at(where => [1, 2]);
1757
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1758

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1759
test 'model insert_at';
1760
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1761
$dbi->execute($CREATE_TABLE->{1});
1762
$dbi->model('table1')->insert_at(
1763
    where => [1, 2],
1764
    param => {key3 => 3}
1765
);
1766
$result = $dbi->model('table1')->select;
1767
$row = $result->fetch_hash_first;
1768
is($row->{key1}, 1);
1769
is($row->{key2}, 2);
1770
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1771

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1772
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1773
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1774
$dbi->execute($CREATE_TABLE->{1});
1775
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1776
$dbi->model('table1')->update_at(
1777
    where => [1, 2],
1778
    param => {key3 => 4}
1779
);
1780
$result = $dbi->model('table1')->select;
1781
$row = $result->fetch_hash_first;
1782
is($row->{key1}, 1);
1783
is($row->{key2}, 2);
1784
is($row->{key3}, 4);
1785

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1786
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1787
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1788
$dbi->execute($CREATE_TABLE->{1});
1789
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1790
$result = $dbi->model('table1')->select_at(where => [1, 2]);
1791
$row = $result->fetch_hash_first;
1792
is($row->{key1}, 1);
1793
is($row->{key2}, 2);
1794
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1795

            
1796

            
cleanup
Yuki Kimoto authored on 2011-03-21
1797
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1798
{
1799
    package MyDBI7;
1800
    
1801
    use base 'DBIx::Custom';
1802
    
1803
    sub connect {
1804
        my $self = shift->SUPER::connect(@_);
1805
        
1806
        $self->include_model('MyModel6');
1807
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1808
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1809
        return $self;
1810
    }
1811
}
1812
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1813
$dbi->execute($CREATE_TABLE->{0});
1814
$dbi->execute($CREATE_TABLE->{2});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1815
$dbi->setup_model;
1816
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1817
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1818
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1819
$result = $model->select(
1820
    column => [$model->mycolumn, $model->column('table2')],
1821
    where => {'table1.key1' => 1}
1822
);
1823
is_deeply($result->fetch_hash_first,
1824
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1825

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1826
test 'update_param';
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1827
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1828
$dbi->execute($CREATE_TABLE->{1});
1829
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1830
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1831

            
1832
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1833
$update_param = $dbi->update_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1834
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1835
update table1 $update_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1836
where key1 = 1
1837
EOS
1838
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1839
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1840
$rows   = $result->fetch_hash_all;
1841
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1842
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1843
                  "basic");
1844

            
1845

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1846
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1847
$dbi->execute($CREATE_TABLE->{1});
1848
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1849
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1850

            
1851
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1852
$update_param = $dbi->update_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1853
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1854
update table1 $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1855
where key1 = 1
1856
EOS
1857
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1858
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1859
$rows   = $result->fetch_hash_all;
1860
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1861
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1862
                  "basic");
1863

            
1864
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1865
$dbi->execute($CREATE_TABLE->{1});
1866
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1867
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1868

            
1869
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1870
$update_param = $dbi->update_param($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1871
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1872
update table1 set $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1873
where key1 = 1
1874
EOS
1875
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1876
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1877
$rows   = $result->fetch_hash_all;
1878
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1879
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1880
                  "update param no_set");
1881

            
1882
            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1883
eval { $dbi->update_param({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1884
like($@, qr/not safety/);
1885

            
1886

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1887
test 'update_param';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1888
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1889
$dbi->execute($CREATE_TABLE->{1});
1890
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1891
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1892

            
1893
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1894
$update_param = $dbi->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1895
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1896
update table1 set $update_param
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1897
where key1 = 1
1898
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1899
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1900
$result = $dbi->execute($SELECT_SOURCES->{0});
1901
$rows   = $result->fetch_hash_all;
1902
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1903
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1904
                  "basic");
1905

            
1906

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1907
test 'insert_param';
1908
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1909
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1910
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1911
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1912
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1913
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1914
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1915
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1916
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
1917
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1918

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1919
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1920
$dbi->reserved_word_quote('"');
1921
$dbi->execute($CREATE_TABLE->{1});
1922
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1923
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1924
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1925
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1926
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1927
$dbi->execute($sql, param => $param, table => 'table1');
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1928
is($dbi->select(table => 'table1')->fetch_hash_first->{key1}, 1);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1929
is($dbi->select(table => 'table1')->fetch_hash_first->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1930

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1931
eval { $dbi->insert_param({";" => 1}) };
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1932
like($@, qr/not safety/);
cleanup
Yuki Kimoto authored on 2011-03-08
1933

            
1934

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1935
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
1936
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1937
$dbi->execute($CREATE_TABLE->{0});
1938
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1939
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1940
$dbi->execute($CREATE_TABLE->{2});
1941
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1942
$dbi->execute($CREATE_TABLE->{4});
1943
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
1944
$rows = $dbi->select(
1945
    table => 'table1',
1946
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1947
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1948
    join  => ['left outer join table2 on table1.key1 = table2.key1']
cleanup
Yuki Kimoto authored on 2011-03-08
1949
)->fetch_hash_all;
1950
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
1951

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1952
$rows = $dbi->select(
1953
    table => 'table1',
1954
    where   => {'key1' => 1},
1955
    join  => ['left outer join table2 on table1.key1 = table2.key1']
1956
)->fetch_hash_all;
1957
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1958

            
cleanup
Yuki Kimoto authored on 2011-03-08
1959
eval {
1960
    $rows = $dbi->select(
1961
        table => 'table1',
1962
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
1963
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1964
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
1965
    );
1966
};
1967
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
1968

            
1969
$rows = $dbi->select(
1970
    table => 'table1',
1971
    where   => {'key1' => 1},
1972
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1973
              'left outer join table3 on table2.key3 = table3.key3']
1974
)->fetch_hash_all;
1975
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1976

            
1977
$rows = $dbi->select(
1978
    column => 'table3.key4 as table3__key4',
1979
    table => 'table1',
1980
    where   => {'table1.key1' => 1},
1981
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1982
              'left outer join table3 on table2.key3 = table3.key3']
1983
)->fetch_hash_all;
1984
is_deeply($rows, [{table3__key4 => 4}]);
1985

            
1986
$rows = $dbi->select(
1987
    column => 'table1.key1 as table1__key1',
1988
    table => 'table1',
1989
    where   => {'table3.key4' => 4},
1990
    join  => ['left outer join table2 on table1.key1 = table2.key1',
1991
              'left outer join table3 on table2.key3 = table3.key3']
1992
)->fetch_hash_all;
1993
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1994

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1995
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1996
$dbi->reserved_word_quote('"');
1997
$dbi->execute($CREATE_TABLE->{0});
1998
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1999
$dbi->execute($CREATE_TABLE->{2});
2000
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2001
$rows = $dbi->select(
2002
    table => 'table1',
2003
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2004
    where   => {'table1.key2' => 2},
2005
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
2006
)->fetch_hash_all;
2007
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
2008
          'reserved_word_quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2009

            
2010
{
2011
    package MyDBI8;
2012
    
2013
    use base 'DBIx::Custom';
2014
    
2015
    sub connect {
2016
        my $self = shift->SUPER::connect(@_);
2017
        
2018
        $self->include_model('MyModel7');
2019
        
2020
        return $self;
2021
    }
2022
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2023

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2024
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2025
$dbi->execute($CREATE_TABLE->{0});
2026
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2027
$sql = <<"EOS";
2028
left outer join (
2029
  select * from table1 as t1
2030
  where t1.key2 = (
2031
    select max(t2.key2) from table1 as t2
2032
    where t1.key1 = t2.key1
2033
  )
2034
) as latest_table1 on table1.key1 = latest_table1.key1
2035
EOS
2036
$join = [$sql];
2037
$rows = $dbi->select(
2038
    table => 'table1',
2039
    column => 'latest_table1.key1 as latest_table1__key1',
2040
    join  => $join
2041
)->fetch_hash_all;
2042
is_deeply($rows, [{latest_table1__key1 => 1}]);
2043

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2044
test 'mycolumn';
2045
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2046
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2047
$dbi->execute($CREATE_TABLE->{2});
2048
$dbi->setup_model;
2049
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2050
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2051
$model = $dbi->model('table1');
2052
$result = $model->select_at(
2053
    column => [
2054
        $model->mycolumn,
2055
        $model->column('table2')
2056
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2057
);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2058
is_deeply($result->fetch_hash_first,
2059
          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2060

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2061
$result = $model->select_at(
2062
    column => [
2063
        $model->mycolumn(['key1']),
2064
        $model->column(table2 => ['key1'])
2065
    ]
2066
);
2067
is_deeply($result->fetch_hash_first,
2068
          {key1 => 1, table2__key1 => 1});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2069

            
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2070
$result = $model->select_at(
2071
    column => [
2072
        $model->mycolumn(['key1']),
2073
        {table2 => ['key1']}
2074
    ]
2075
);
2076
is_deeply($result->fetch_hash_first,
2077
          {key1 => 1, table2__key1 => 1});
2078

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2079
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2080
{
2081
    package MyDBI9;
2082
    
2083
    use base 'DBIx::Custom';
2084
    
2085
    sub connect {
2086
        my $self = shift->SUPER::connect(@_);
2087
        
2088
        $self->include_model('MyModel8')->setup_model;
2089
        
2090
        return $self;
2091
    }
2092
}
2093
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2094
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2095
$model = $dbi->model('table1');
2096
eval{$model->execute('select * from table1')};
2097
ok(!$@);
2098

            
2099
test 'table_alias';
2100
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2101
$dbi->execute($CREATE_TABLE->{0});
2102
$dbi->execute($CREATE_TABLE->{2});
2103
$dbi->setup_model;
2104
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2105
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2106
$model = $dbi->model('table1');
2107
$result = $model->select(
2108
    column => [
2109
        $model->column('table2_alias')
2110
    ],
2111
    where => {'table2_alias.key3' => 2}
2112
);
2113
is_deeply($result->fetch_hash_first, 
2114
          {table2_alias__key1 => 1, table2_alias__key3 => 48});
2115

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2116
test 'type() option';
2117
$dbi = DBIx::Custom->connect(
2118
    data_source => 'dbi:SQLite:dbname=:memory:',
2119
    dbi_option => {
2120
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2121
    }
2122
);
2123
my $binary = pack("I3", 1, 2, 3);
2124
$dbi->execute('create table table1(key1, key2)');
2125
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2126
$result = $dbi->select(table => 'table1');
2127
$row   = $result->fetch_hash_first;
2128
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2129
$result = $dbi->execute('select length(key1) as key1_length from table1');
2130
$row = $result->fetch_hash_first;
2131
is($row->{key1_length}, length $binary);
2132

            
2133
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2134
$result = $dbi->select(table => 'table1');
2135
$row   = $result->fetch_hash_first;
2136
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2137
$result = $dbi->execute('select length(key1) as key1_length from table1');
2138
$row = $result->fetch_hash_first;
2139
is($row->{key1_length}, length $binary);
2140

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2141
test 'create_model';
2142
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2143
$dbi->execute($CREATE_TABLE->{0});
2144
$dbi->execute($CREATE_TABLE->{2});
2145

            
2146
$dbi->create_model(
2147
    table => 'table1',
2148
    join => [
2149
       'left outer join table2 on table1.key1 = table2.key1'
2150
    ],
2151
    primary_key => ['key1']
2152
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2153
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2154
    table => 'table2'
2155
);
2156
$dbi->create_model(
2157
    table => 'table3',
2158
    filter => [
2159
        key1 => {in => sub { uc $_[0] }}
2160
    ]
2161
);
2162
$dbi->setup_model;
2163
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2164
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2165
$model = $dbi->model('table1');
2166
$result = $model->select(
2167
    column => [$model->mycolumn, $model->column('table2')],
2168
    where => {'table1.key1' => 1}
2169
);
2170
is_deeply($result->fetch_hash_first,
2171
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
create_model() return model
Yuki Kimoto authored on 2011-03-29
2172
is_deeply($model2->select->fetch_hash_first, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2173

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2174
test 'model method';
2175
test 'create_model';
2176
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2177
$dbi->execute($CREATE_TABLE->{2});
2178
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2179
$model = $dbi->create_model(
2180
    table => 'table2'
2181
);
2182
$model->method(foo => sub { shift->select(@_) });
2183
is_deeply($model->foo->fetch_hash_first, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2184

            
2185
test 'merge_param';
2186
{
2187
    my $dbi = DBIx::Custom->new;
2188
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2189
    my $param2 = {key1 => 1, key2 => 2};
2190
    my $param3 = {key1 => 1};
2191
    my $param = $dbi->merge_param($param1, $param2, $param3);
2192
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2193
}
2194

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2195
{
2196
    my $dbi = DBIx::Custom->new;
2197
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2198
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2199
    my $param = $dbi->merge_param($param1, $param2);
2200
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2201
}
2202

            
cleanup
Yuki Kimoto authored on 2011-04-01
2203
test 'select() param option';
2204
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2205
$dbi->execute($CREATE_TABLE->{0});
2206
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2207
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2208
$dbi->execute($CREATE_TABLE->{2});
2209
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2210
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2211
$rows = $dbi->select(
2212
    table => 'table1',
2213
    column => 'table1.key1 as table1_key1, key2, key3',
2214
    where   => {'table1.key2' => 3},
2215
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2216
              ' as table2 on table1.key1 = table2.key1'],
2217
    param => {'table2.key3' => 5}
2218
)->fetch_hash_all;
2219
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2220

            
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2221

            
2222
test 'select() wrap option';
2223
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2224
$dbi->execute($CREATE_TABLE->{0});
2225
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2226
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2227
$rows = $dbi->select(
2228
    table => 'table1',
2229
    column => 'key1',
2230
    wrap => ['select * from (', ') as t where key1 = 1']
2231
)->fetch_hash_all;
2232
is_deeply($rows, [{key1 => 1}]);
2233

            
2234
eval {
2235
$dbi->select(
2236
    table => 'table1',
2237
    column => 'key1',
2238
    wrap => 'select * from ('
2239
)
2240
};
cleanup
Yuki Kimoto authored on 2011-04-25
2241
like($@, qr/array/);
2242

            
2243
test 'select() string where';
2244
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2245
$dbi->execute($CREATE_TABLE->{0});
2246
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2247
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2248
$rows = $dbi->select(
2249
    table => 'table1',
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2250
    where => '{= key1} and {= key2}',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2251
    where_param => {key1 => 1, key2 => 2}
cleanup
Yuki Kimoto authored on 2011-04-25
2252
)->fetch_hash_all;
2253
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2254

            
2255
test 'delete() string where';
2256
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2257
$dbi->execute($CREATE_TABLE->{0});
2258
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2259
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2260
$dbi->delete(
2261
    table => 'table1',
2262
    where => '{= key1} and {= key2}',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2263
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2264
);
2265
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
2266
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2267

            
2268

            
2269
test 'update() string where';
2270
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2271
$dbi->execute($CREATE_TABLE->{0});
2272
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2273
$dbi->update(
2274
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2275
    param => {key1 => 5},
2276
    where => '{= key1} and {= key2}',
2277
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2278
);
2279
$rows = $dbi->select(table => 'table1')->fetch_hash_all;
2280
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2281

            
2282
=cut