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

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
9
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
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;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
107
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "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}";
updated pod
Yuki Kimoto authored on 2011-06-21
113
$query = $dbi->execute($source, {}, query => 1);
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});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
124
$rows = $result->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};";
updated pod
Yuki Kimoto authored on 2011-06-21
134
$insert_query = $dbi->execute($insert_SOURCE, {}, query => 1);
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});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
138
$rows = $result->filter({key2 => 'three_times'})->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};";
updated pod
Yuki Kimoto authored on 2011-06-21
145
$insert_query = $dbi->execute($insert_SOURCE, {}, query => 1);
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}";
updated pod
Yuki Kimoto authored on 2011-06-21
148
$select_query = $dbi->execute($select_SOURCE,{}, query => 1);
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]});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
151
$rows = $result->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

            
updated pod
Yuki Kimoto authored on 2011-06-21
160
$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
161
$query = $dbi->execute($source, {}, query => 1);
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});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
163
$rows = $result->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

            
updated pod
Yuki Kimoto authored on 2011-06-21
166
$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
167
$query = $dbi->execute($source, {}, query => 1);
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
168
$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
169
$rows = $result->all;
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
170
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
171

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
172
$source = "select * from table1 where {<= key1} and {like key2};";
updated pod
Yuki Kimoto authored on 2011-06-21
173
$query = $dbi->execute($source, {}, query => 1);
removed register_format()
yuki-kimoto authored on 2010-05-26
174
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
175
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
176
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
177

            
178
test 'DIB::Custom::SQLTemplate in tag';
179
$dbi->execute($DROP_TABLE->{0});
180
$dbi->execute($CREATE_TABLE->{1});
181
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
182
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
183

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
184
$source = "select * from table1 where {in key1 2};";
updated pod
Yuki Kimoto authored on 2011-06-21
185
$query = $dbi->execute($source, {}, query => 1);
removed register_format()
yuki-kimoto authored on 2010-05-26
186
$result = $dbi->execute($query, param => {key1 => [9, 1]});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
187
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
188
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
189

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

            
add tests
yuki-kimoto authored on 2010-08-10
195
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
196
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
197
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
198

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

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

            
add tests
yuki-kimoto authored on 2010-08-10
208
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
209
$rows = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
210
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
cleanup
Yuki Kimoto authored on 2011-01-23
211
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
212

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

            
214
test 'parameter';
215
$dbi->execute($DROP_TABLE->{0});
216
$dbi->execute($CREATE_TABLE->{1});
217
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
218
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
219

            
220
$source = "select * from table1 where key1 = :key1 and key2 = :key2";
221
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
222
$rows = $result->all;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
223
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
224

            
225
$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2";
226
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
227
$rows = $result->all;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
228
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
229

            
230
$source = "select * from table1 where key1 = :key1 or key1 = :key1";
231
$result = $dbi->execute($source, param => {key1 => [1, 2]});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
232
$rows = $result->all;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
233
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
234

            
235
$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2";
236
$result = $dbi->execute(
237
    $source,
238
    param => {'table1.key1' => 1, 'table1.key2' => 1},
239
    filter => {'table1.key2' => sub { $_[0] * 2 }}
240
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
241
$rows = $result->all;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
242
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
243

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

            
248
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
updated pod
Yuki Kimoto authored on 2011-06-21
249
eval{$dbi->execute("{p }", {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
250
ok($@, "create_query invalid SQL template");
removed register_format()
yuki-kimoto authored on 2010-05-26
251

            
252
test 'insert';
253
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
254
$dbi->execute($CREATE_TABLE->{0});
255
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
256
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
257
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
258
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
259
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
260

            
261
$dbi->execute('delete from table1');
262
$dbi->register_filter(
263
    twice       => sub { $_[0] * 2 },
264
    three_times => sub { $_[0] * 3 }
265
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
266
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
267
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
268
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
269
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
270
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
271
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
272

            
273
$dbi->execute($DROP_TABLE->{0});
274
$dbi->execute($CREATE_TABLE->{0});
275
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => '   ');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
276
$rows = $dbi->select(table => 'table1')->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
277
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
278

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
285
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
286
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
287
$dbi->execute('create table "table" ("select")');
288
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
289
$dbi->insert(table => 'table', param => {select => 1});
290
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
291
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
292
is_deeply($rows, [{select => 2}], "reserved word");
293

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
294
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
295
$dbi->execute($CREATE_TABLE->{0});
296
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
297
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
298
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
299
$rows   = $result->all;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
300
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
301

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
302
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
303
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
304
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
305
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
306
$result = $dbi->execute($SELECT_SOURCES->{0});
307
$rows   = $result->all;
308
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
309

            
removed register_format()
yuki-kimoto authored on 2010-05-26
310
test 'update';
311
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
312
$dbi->execute($CREATE_TABLE->{1});
313
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
314
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
315
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
316
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
317
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
318
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
319
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
320
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
321
                  
322
$dbi->execute("delete from table1");
323
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
324
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
325
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
326
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
327
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
328
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
329
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
330
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
331

            
add tests
yuki-kimoto authored on 2010-08-10
332
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
333
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
334
$rows   = $result->all;
add tests
yuki-kimoto authored on 2010-08-10
335
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
336
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
337
                  "update key same as search key : param is array ref");
add tests
yuki-kimoto authored on 2010-08-10
338

            
removed register_format()
yuki-kimoto authored on 2010-05-26
339
$dbi->execute("delete from table1");
340
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
341
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
342
$dbi->register_filter(twice => sub { $_[0] * 2 });
343
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
344
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
345
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
346
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
347
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
348
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
349
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
350

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

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
353
eval{$dbi->update(table => 'table1', where => {key1 => 1}, noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
354
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
355

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
359
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
360
$dbi->execute($CREATE_TABLE->{0});
361
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
362
$where = $dbi->where;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
363
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
364
$where->param({key1 => 1, key2 => 2});
365
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
366
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
367
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
368

            
369
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
370
$dbi->execute($CREATE_TABLE->{0});
371
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
372
$dbi->update(
373
    table => 'table1',
374
    param => {key1 => 3},
375
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
376
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
377
        {key1 => 1, key2 => 2}
378
    ]
379
);
380
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
381
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
382

            
383
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
384
$dbi->execute($CREATE_TABLE->{0});
385
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
386
$where = $dbi->where;
updated pod
Yuki Kimoto authored on 2011-06-21
387
$where->clause(['and', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
388
$where->param({key2 => 2});
389
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
390
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
391
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
392

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
399
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
400
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
401
$dbi->execute('create table "table" ("select", "update")');
402
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
403
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
404
$dbi->insert(table => 'table', param => {select => 1});
405
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
406
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
407
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
408
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
409

            
410
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
411
like($@, qr/safety/);
412

            
413
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
414
$dbi->reserved_word_quote('"');
415
$dbi->execute('create table "table" ("select", "update")');
416
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
417
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
418
$dbi->insert(table => 'table', param => {select => 1});
419
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
420
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
421
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
422
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
423

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
424
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
425
$dbi->execute($CREATE_TABLE->{1});
426
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
427
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
428
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
429
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
430
$rows   = $result->all;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
431
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
432
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
433
                  "basic");
434

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
435
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
436
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
437
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
438
$dbi->update(table => 'table1', param => {key2 => 4},
439
  where => {key1 => 1}, prefix => 'or replace');
440
$result = $dbi->execute($SELECT_SOURCES->{0});
441
$rows   = $result->all;
442
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
443

            
removed register_format()
yuki-kimoto authored on 2010-05-26
444
test 'update_all';
445
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
446
$dbi->execute($CREATE_TABLE->{1});
447
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
448
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
449
$dbi->register_filter(twice => sub { $_[0] * 2 });
450
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
451
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
452
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
453
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
454
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
455
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
456

            
457

            
458
test 'delete';
459
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
460
$dbi->execute($CREATE_TABLE->{0});
461
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
462
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
463
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
464
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
465
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
466
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
467

            
468
$dbi->execute("delete from table1;");
469
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
470
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
471
$dbi->register_filter(twice => sub { $_[0] * 2 });
472
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
473
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
474
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
475
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
476

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

            
479
$dbi->delete_all(table => 'table1');
480
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
481
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
482
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
483
$rows = $dbi->select(table => 'table1')->all;
cleanup
Yuki Kimoto authored on 2011-01-23
484
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
485

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
486
eval{$dbi->delete(table => 'table1', where => {key1 => 1}, noexist => 1)};
cleanup
Yuki Kimoto authored on 2011-03-09
487
like($@, qr/noexist/, "invalid");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
488

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
489
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
490
$dbi->execute($CREATE_TABLE->{0});
491
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
492
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
493
$where = $dbi->where;
updated pod
Yuki Kimoto authored on 2011-06-21
494
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
495
$where->param({ke1 => 1, key2 => 2});
496
$dbi->delete(table => 'table1', where => $where);
497
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
498
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
499

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
500
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
501
$dbi->execute($CREATE_TABLE->{0});
502
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
503
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
504
$dbi->delete(
505
    table => 'table1',
506
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
507
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
508
        {ke1 => 1, key2 => 2}
509
    ]
510
);
511
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
512
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
513

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
514
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
515
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
516
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
517
$dbi->delete(table => 'table1', where => {key1 => 1}, prefix => '    ');
518
$result = $dbi->execute($SELECT_SOURCES->{0});
519
$rows   = $result->all;
520
is_deeply($rows, [], "basic");
521

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
532
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
533
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
534
$dbi->execute('create table "table" ("select", "update")');
535
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
536
$dbi->insert(table => 'table', param => {select => 1});
537
$dbi->delete(table => 'table', where => {select => 1});
538
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
539
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
540
is_deeply($rows, [], "reserved word");
541

            
removed register_format()
yuki-kimoto authored on 2010-05-26
542
test 'delete_all';
543
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
544
$dbi->execute($CREATE_TABLE->{0});
545
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
546
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
547
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
548
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
549
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
550
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
551

            
552

            
553
test 'select';
554
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
555
$dbi->execute($CREATE_TABLE->{0});
556
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
557
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
558
$rows = $dbi->select(table => 'table1')->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
559
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
560
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
561

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
562
$rows = $dbi->select(table => 'table1', column => ['key1'])->all;
cleanup
Yuki Kimoto authored on 2011-01-23
563
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
564

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
565
$rows = $dbi->select(table => 'table1', where => {key1 => 1})->all;
cleanup
Yuki Kimoto authored on 2011-01-23
566
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
567

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
568
$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->all;
cleanup
Yuki Kimoto authored on 2011-01-23
569
is_deeply($rows, [{key1 => 3}], "table and columns and where key");
removed register_format()
yuki-kimoto authored on 2010-05-26
570

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
571
$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all;
cleanup
Yuki Kimoto authored on 2011-01-23
572
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
removed register_format()
yuki-kimoto authored on 2010-05-26
573

            
574
$dbi->register_filter(decrement => sub { $_[0] - 1 });
update document
yuki-kimoto authored on 2010-05-27
575
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
576
            ->all;
cleanup
Yuki Kimoto authored on 2011-01-23
577
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
578

            
579
$dbi->execute($CREATE_TABLE->{2});
580
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
581
$rows = $dbi->select(
582
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
583
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
584
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
585
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
586
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
587
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
588

            
589
$rows = $dbi->select(
590
    table => [qw/table1 table2/],
591
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
592
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
593
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
594
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
595

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
599
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
600
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
601
$dbi->execute('create table "table" ("select", "update")');
602
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
603
$dbi->insert(table => 'table', param => {select => 1, update => 2});
604
$result = $dbi->select(table => 'table', where => {select => 1});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
605
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
606
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
607

            
removed register_format()
yuki-kimoto authored on 2010-05-26
608
test 'fetch filter';
609
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
610
$dbi->register_filter(
611
    twice       => sub { $_[0] * 2 },
612
    three_times => sub { $_[0] * 3 }
613
);
614
$dbi->default_fetch_filter('twice');
615
$dbi->execute($CREATE_TABLE->{0});
616
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
617
$result = $dbi->select(table => 'table1');
618
$result->filter({key1 => 'three_times'});
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
619
$row = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
620
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
621

            
622
test 'filters';
623
$dbi = DBIx::Custom->new;
624

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
631
test 'transaction';
632
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
633
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
634
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
635
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
636
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
637
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
638
$result = $dbi->select(table => 'table1');
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
639
is_deeply(scalar $result->all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
640
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
641

            
642
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
643
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
644
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
645
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
646
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
647

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

            
651
test 'cache';
652
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
653
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
654
$dbi->execute($CREATE_TABLE->{0});
updated pod
Yuki Kimoto authored on 2011-06-21
655
$source = 'select * from table1 where key1 = :key1 and key2 = :key2;';
656
$dbi->execute($source, {}, query => 1);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
657
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
658
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
659

            
660
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
661
$dbi->execute($CREATE_TABLE->{0});
662
$dbi->{_cached} = {};
663
$dbi->cache(0);
664
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
665
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
666

            
add tests
yuki-kimoto authored on 2010-08-10
667
test 'execute';
668
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
669
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
670
{
671
    local $Carp::Verbose = 0;
672
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
673
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
674
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
675
}
676
{
677
    local $Carp::Verbose = 1;
678
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
679
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
680
}
add tests
yuki-kimoto authored on 2010-08-10
681

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
685
$query = $dbi->execute('select * from table1 where key1 = :key1', {}, query => 1);
add tests
yuki-kimoto authored on 2010-08-10
686
$dbi->dbh->disconnect;
687
eval{$dbi->execute($query, param => {key1 => {a => 1}})};
cleanup
Yuki Kimoto authored on 2011-01-23
688
ok($@, "execute fail");
add tests
yuki-kimoto authored on 2010-08-10
689

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
690
{
691
    local $Carp::Verbose = 0;
updated pod
Yuki Kimoto authored on 2011-06-21
692
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
693
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
694
}
695
{
696
    local $Carp::Verbose = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
697
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
698
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
699
}
cleanup
yuki-kimoto authored on 2010-10-17
700

            
701

            
702
test 'transaction';
703
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
704
$dbi->execute($CREATE_TABLE->{0});
705

            
706
$dbi->begin_work;
707

            
708
eval {
709
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
710
    die "Error";
711
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
712
};
713

            
714
$dbi->rollback if $@;
715

            
716
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
717
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
718
is_deeply($rows, [], "rollback");
cleanup
yuki-kimoto authored on 2010-10-17
719

            
720
$dbi->begin_work;
721

            
722
eval {
723
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
724
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
725
};
726

            
727
$dbi->commit unless $@;
728

            
729
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
730
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
731
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit");
cleanup
yuki-kimoto authored on 2010-10-17
732

            
733
$dbi->dbh->{AutoCommit} = 0;
734
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
735
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
736
$dbi->dbh->{AutoCommit} = 1;
737

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
739
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
740
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
741
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
742
    one => sub { 1 }
743
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
744
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
745
    two => sub { 2 }
746
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
747
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
748
    twice => sub {
749
        my $self = shift;
750
        return $_[0] * 2;
751
    }
752
});
753

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
761
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
762
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
763
$dbi->execute($CREATE_TABLE->{0});
764
$dbi->register_filter(twice => sub { $_[0] * 2 });
765
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
766
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
767
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
768
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
769
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
770
$result = $dbi->execute($SELECT_SOURCES->{0});
771
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
772
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
773
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
774
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
775
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
776

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
777
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
778
$dbi->execute($CREATE_TABLE->{0});
779
$dbi->register_filter(twice => sub { $_[0] * 2 });
780
$dbi->register_filter(three_times => sub { $_[0] * 3});
781
$dbi->apply_filter(
782
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
783
              'key2' => {out => 'three_times', in => 'twice'});
784
$dbi->apply_filter(
785
    'table1', 'key1' => {out => undef}
786
); 
787
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
788
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
789
$row   = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
790
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
791

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
792
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
793
$dbi->execute($CREATE_TABLE->{0});
794
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
795
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
796
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
797
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
798
$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
799
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
800
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
801
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
802
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
803

            
804
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
805
$dbi->execute($CREATE_TABLE->{0});
806
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
807
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
808
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
809
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
810
$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
811
$dbi->delete(table => 'table1', where => {key1 => 1});
812
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
813
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
814
is_deeply($rows, [], "delete");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
815

            
816
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
817
$dbi->execute($CREATE_TABLE->{0});
818
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
819
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
820
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
821
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
822
$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
823
$result = $dbi->select(table => 'table1', where => {key1 => 1});
824
$result->filter({'key2' => 'twice'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
825
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
826
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
827

            
828
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
829
$dbi->execute($CREATE_TABLE->{0});
830
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
831
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
832
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
833
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
834
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
835
$result = $dbi->execute("select * from table1 where key1 = :key1 and key2 = :key2;",
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
836
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
837
                        table => ['table1']);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
838
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
839
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
840

            
add table tag
Yuki Kimoto authored on 2011-02-09
841
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
842
$dbi->execute($CREATE_TABLE->{0});
843
$dbi->register_filter(twice => sub { $_[0] * 2 });
844
$dbi->apply_filter(
845
    'table1', 'key1' => {out => 'twice', in => 'twice'}
846
);
847
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
848
$result = $dbi->execute("select * from {table table1} where key1 = :key1 and key2 = :key2;",
add table tag
Yuki Kimoto authored on 2011-02-09
849
                        param => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
850
$rows   = $result->all;
add table tag
Yuki Kimoto authored on 2011-02-09
851
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
852

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
853
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
854
$dbi->execute($CREATE_TABLE->{0});
855
$dbi->execute($CREATE_TABLE->{2});
856
$dbi->register_filter(twice => sub { $_[0] * 2 });
857
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
858
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
859
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
860
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
861
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
862
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
863
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
864
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
865
$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
866
$result = $dbi->select(
867
     table => ['table1', 'table2'],
868
     column => ['key2', 'key3'],
869
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
870

            
871
$result->filter({'key2' => 'twice'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
872
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
873
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
874

            
875
$result = $dbi->select(
876
     table => ['table1', 'table2'],
877
     column => ['key2', 'key3'],
878
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
879

            
880
$result->filter({'key2' => 'twice'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
881
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
882
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
883

            
pod fix
Yuki Kimoto authored on 2011-01-21
884
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
885
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
886
$dbi->execute($CREATE_TABLE->{2});
887
$dbi->execute($CREATE_TABLE->{3});
888

            
889
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
890
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
891
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
892
    
893
    if ($table =~ /^table/) {
894
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
895
         push @$infos, $info;
896
    }
897
});
898
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
899
is_deeply($infos, 
900
    [
901
        ['table1', 'key1', 'key1'],
902
        ['table1', 'key2', 'key2'],
903
        ['table2', 'key1', 'key1'],
904
        ['table2', 'key3', 'key3']
905
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
906
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
907
);
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
908
test 'each_table';
909
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
910
$dbi->execute($CREATE_TABLE->{2});
911
$dbi->execute($CREATE_TABLE->{3});
912

            
913
$infos = [];
914
$dbi->each_table(sub {
915
    my ($self, $table, $table_info) = @_;
916
    
917
    if ($table =~ /^table/) {
918
         my $info = [$table, $table_info->{TABLE_NAME}];
919
         push @$infos, $info;
920
    }
921
});
922
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
923
is_deeply($infos, 
924
    [
925
        ['table1', 'table1'],
926
        ['table2', 'table2'],
927
    ]
928
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
929

            
add examples
Yuki Kimoto authored on 2011-01-07
930
test 'limit';
931
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
932
$dbi->execute($CREATE_TABLE->{0});
933
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
934
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
935
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
936
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
937
    limit => sub {
938
        my ($count, $offset) = @_;
939
        
940
        my $s = '';
941
        $s .= "limit $count";
942
        $s .= " offset $offset" if defined $offset;
943
        
944
        return [$s, []];
945
    }
946
);
947
$rows = $dbi->select(
948
  table => 'table1',
949
  where => {key1 => 1},
950
  append => "order by key2 {limit 1 0}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
951
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
952
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
953
$rows = $dbi->select(
954
  table => 'table1',
955
  where => {key1 => 1},
956
  append => "order by key2 {limit 2 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
957
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
958
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
959
$rows = $dbi->select(
960
  table => 'table1',
961
  where => {key1 => 1},
962
  append => "order by key2 {limit 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
963
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
964
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
965

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
966
test 'connect super';
967
{
968
    package MyDBI;
969
    
970
    use base 'DBIx::Custom';
971
    sub connect {
972
        my $self = shift->SUPER::connect(@_);
973
        
974
        return $self;
975
    }
976
    
977
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
978
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
979
        
980
        return $self;
981
    }
982
}
983

            
984
$dbi = MyDBI->connect($NEW_ARGS->{0});
985
$dbi->execute($CREATE_TABLE->{0});
986
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
987
is($dbi->select(table => 'table1')->one->{key1}, 1);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
988

            
989
$dbi = MyDBI->new($NEW_ARGS->{0});
cleanup
Yuki Kimoto authored on 2011-01-25
990
$dbi->connect;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
991
$dbi->execute($CREATE_TABLE->{0});
992
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
993
is($dbi->select(table => 'table1')->one->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
994

            
cleanup
Yuki Kimoto authored on 2011-01-25
995
{
996
    package MyDBI2;
997
    
998
    use base 'DBIx::Custom';
999
    sub connect {
1000
        my $self = shift->SUPER::new(@_);
1001
        $self->connect;
1002
        
1003
        return $self;
1004
    }
1005
}
1006

            
1007
$dbi = MyDBI->connect($NEW_ARGS->{0});
1008
$dbi->execute($CREATE_TABLE->{0});
1009
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
added tests
Yuki Kimoto authored on 2011-06-08
1010
is($dbi->select(table => 'table1')->one->{key1}, 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1011

            
1012
test 'end_filter';
1013
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1014
$dbi->execute($CREATE_TABLE->{0});
1015
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1016
$result = $dbi->select(table => 'table1');
1017
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1018
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
1019
$row = $result->fetch_first;
1020
is_deeply($row, [6, 40]);
1021

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1022
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1023
$dbi->execute($CREATE_TABLE->{0});
1024
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1025
$result = $dbi->select(table => 'table1');
1026
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
1027
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
1028
$row = $result->fetch_first;
1029
is_deeply($row, [6, 12]);
1030

            
1031
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1032
$dbi->execute($CREATE_TABLE->{0});
1033
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1034
$result = $dbi->select(table => 'table1');
1035
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
1036
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
1037
$row = $result->fetch_first;
1038
is_deeply($row, [6, 12]);
1039

            
many changed
Yuki Kimoto authored on 2011-01-23
1040
$dbi->register_filter(five_times => sub { $_[0] * 5 });
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1041
$result = $dbi->select(table => 'table1');
1042
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
many changed
Yuki Kimoto authored on 2011-01-23
1043
$result->end_filter({key1 => sub { $_[0] * 3 }, key2 => 'five_times' });
added tests
Yuki Kimoto authored on 2011-06-08
1044
$row = $result->one;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1045
is_deeply($row, {key1 => 6, key2 => 40});
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1046

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1047
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1048
$dbi->apply_filter('table1',
1049
    key1 => {end => sub { $_[0] * 3 } },
1050
    key2 => {end => 'five_times'}
1051
);
1052
$result = $dbi->select(table => 'table1');
1053
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
added tests
Yuki Kimoto authored on 2011-06-08
1054
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1055
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
1056

            
1057
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1058
$dbi->apply_filter('table1',
1059
    key1 => {end => sub { $_[0] * 3 } },
1060
    key2 => {end => 'five_times'}
1061
);
1062
$result = $dbi->select(table => 'table1');
1063
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1064
$result->filter(key1 => undef);
1065
$result->end_filter(key1 => undef);
added tests
Yuki Kimoto authored on 2011-06-08
1066
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1067
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1068

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1069
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1070
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1071
$dbi->execute($CREATE_TABLE->{0});
1072
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1073
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1074
$row = $result
1075
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1076
       ->remove_filter
1077
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1078
       ->remove_end_filter
1079
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1080
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1081

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1082
test 'empty where select';
1083
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1084
$dbi->execute($CREATE_TABLE->{0});
1085
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1086
$result = $dbi->select(table => 'table1', where => {});
added tests
Yuki Kimoto authored on 2011-06-08
1087
$row = $result->one;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1088
is_deeply($row, {key1 => 1, key2 => 2});
1089

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1090
test 'select query option';
1091
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1092
$dbi->execute($CREATE_TABLE->{0});
1093
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1094
is(ref $query, 'DBIx::Custom::Query');
1095
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1096
is(ref $query, 'DBIx::Custom::Query');
1097
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1098
is(ref $query, 'DBIx::Custom::Query');
1099
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1100
is(ref $query, 'DBIx::Custom::Query');
1101

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1102
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1103
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1104
$dbi->execute($CREATE_TABLE->{0});
1105
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1106
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
updated pod
Yuki Kimoto authored on 2011-06-21
1107
$where = $dbi->where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
1108
is("$where", "where ( key1 = :key1 and key2 = :key2 )", 'no param');
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1109

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1110
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1111
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1112
             ->param({key1 => 1});
added test
Yuki Kimoto authored on 2011-01-19
1113

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1114
$result = $dbi->select(
1115
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1116
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1117
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1118
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1119
is_deeply($row, [{key1 => 1, key2 => 2}]);
1120

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1121
$result = $dbi->select(
1122
    table => 'table1',
1123
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
1124
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1125
        {key1 => 1}
1126
    ]
1127
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1128
$row = $result->all;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1129
is_deeply($row, [{key1 => 1, key2 => 2}]);
1130

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1131
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1132
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1133
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1134
$result = $dbi->select(
1135
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1136
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1137
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1138
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1139
is_deeply($row, [{key1 => 1, key2 => 2}]);
1140

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1141
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1142
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1143
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1144
$result = $dbi->select(
1145
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1146
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1147
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1148
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1149
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1150

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1151
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-07
1152
             ->clause(['and', ['or', 'key1 > :key1', 'key1 < :key1'], 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1153
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1154
$result = $dbi->select(
1155
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1156
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1157
); 
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1158
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1159
is_deeply($row, [{key1 => 1, key2 => 2}]);
1160

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1161
$where = $dbi->where;
1162
$result = $dbi->select(
1163
    table => 'table1',
1164
    where => $where
1165
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1166
$row = $result->all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1167
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1168

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1169
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1170
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1171
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1172
$result = $dbi->select(
1173
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1174
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1175
);
1176
};
1177
ok($@);
1178

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

            
added test
Yuki Kimoto authored on 2011-01-19
1182
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1183
             ->clause(['or', ('key1 = :key1') x 2])
added test
Yuki Kimoto authored on 2011-01-19
1184
             ->param({key1 => [1, 3]});
1185
$result = $dbi->select(
1186
    table => 'table1',
1187
    where => $where,
1188
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1189
$row = $result->all;
added test
Yuki Kimoto authored on 2011-01-19
1190
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1191

            
1192
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1193
             ->clause(['or', ('key1 = :key1') x 2])
added test
Yuki Kimoto authored on 2011-01-19
1194
             ->param({key1 => [1]});
1195
$result = $dbi->select(
1196
    table => 'table1',
1197
    where => $where,
1198
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1199
$row = $result->all;
added test
Yuki Kimoto authored on 2011-01-19
1200
is_deeply($row, [{key1 => 1, key2 => 2}]);
1201

            
1202
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1203
             ->clause(['or', ('key1 = :key1') x 2])
added test
Yuki Kimoto authored on 2011-01-19
1204
             ->param({key1 => 1});
1205
$result = $dbi->select(
1206
    table => 'table1',
1207
    where => $where,
1208
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1209
$row = $result->all;
added test
Yuki Kimoto authored on 2011-01-19
1210
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1211

            
many changed
Yuki Kimoto authored on 2011-01-23
1212
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1213
             ->clause('key1 = :key1')
many changed
Yuki Kimoto authored on 2011-01-23
1214
             ->param({key1 => 1});
1215
$result = $dbi->select(
1216
    table => 'table1',
1217
    where => $where,
1218
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1219
$row = $result->all;
many changed
Yuki Kimoto authored on 2011-01-23
1220
is_deeply($row, [{key1 => 1, key2 => 2}]);
1221

            
1222
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1223
             ->clause('key1 = :key1 key2 = :key2')
many changed
Yuki Kimoto authored on 2011-01-23
1224
             ->param({key1 => 1});
1225
eval{$where->to_string};
1226
like($@, qr/one column/);
1227

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1228
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1229
             ->clause('key1 = :key1')
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1230
             ->param([]);
1231
eval{$where->to_string};
1232
like($@, qr/Parameter/);
1233

            
1234
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1235
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1236
             ->param({key1 => [$dbi->not_exists, 1, 3]});
1237
$result = $dbi->select(
1238
    table => 'table1',
1239
    where => $where,
1240
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1241
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1242
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1243

            
1244
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1245
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1246
             ->param({key1 => [1, $dbi->not_exists, 3]});
1247
$result = $dbi->select(
1248
    table => 'table1',
1249
    where => $where,
1250
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1251
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1252
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1253

            
1254
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1255
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1256
             ->param({key1 => [1, 3, $dbi->not_exists]});
1257
$result = $dbi->select(
1258
    table => 'table1',
1259
    where => $where,
1260
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1261
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1262
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1263

            
1264
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1265
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1266
             ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1267
$result = $dbi->select(
1268
    table => 'table1',
1269
    where => $where,
1270
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1271
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1272
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1273

            
1274
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1275
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1276
             ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1277
$result = $dbi->select(
1278
    table => 'table1',
1279
    where => $where,
1280
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1281
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1282
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1283

            
1284
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1285
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1286
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1287
$result = $dbi->select(
1288
    table => 'table1',
1289
    where => $where,
1290
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1291
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1292
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1293

            
1294
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1295
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1296
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1297
$result = $dbi->select(
1298
    table => 'table1',
1299
    where => $where,
1300
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1301
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1302
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1303

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1304
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1305
             ->clause(['or', ('key1 = :key1') x 3])
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1306
             ->param({key1 => []});
1307
$result = $dbi->select(
1308
    table => 'table1',
1309
    where => $where,
1310
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1311
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1312
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1313

            
1314
$where = $dbi->where
1315
             ->clause(['and', '{> key1}', '{< key1}' ])
1316
             ->param({key1 => [2, $dbi->not_exists]});
1317
$result = $dbi->select(
1318
    table => 'table1',
1319
    where => $where,
1320
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1321
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1322
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1323

            
1324
$where = $dbi->where
1325
             ->clause(['and', '{> key1}', '{< key1}' ])
1326
             ->param({key1 => [$dbi->not_exists, 2]});
1327
$result = $dbi->select(
1328
    table => 'table1',
1329
    where => $where,
1330
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1331
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1332
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1333

            
1334
$where = $dbi->where
1335
             ->clause(['and', '{> key1}', '{< key1}' ])
1336
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1337
$result = $dbi->select(
1338
    table => 'table1',
1339
    where => $where,
1340
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1341
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1342
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1343

            
1344
$where = $dbi->where
1345
             ->clause(['and', '{> key1}', '{< key1}' ])
1346
             ->param({key1 => [0, 2]});
1347
$result = $dbi->select(
1348
    table => 'table1',
1349
    where => $where,
1350
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1351
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1352
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1353

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1354
$where = $dbi->where
1355
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1356
$result = $dbi->select(
1357
    table => 'table1',
1358
    where => $where,
1359
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1360
$row = $result->all;
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1361
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1362

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

            
fixed DBIx::Custom::Where to...
Yuki Kimoto authored on 2011-06-27
1366
$where = $dbi->where(
1367
    clause => ['and', ['or'], ['and', 'key1 = :key1', 'key2 = :key2']],
1368
    param => {key1 => 1, key2 => 2}
1369
);
1370
$result = $dbi->select(
1371
    table => 'table1',
1372
    where => $where,
1373
);
1374
$row = $result->all;
1375
is_deeply($row, [{key1 => 1, key2 => 2}]);
1376

            
1377

            
1378
$where = $dbi->where(
1379
    clause => ['and', ['or'], ['or', ':key1', ':key2']],
1380
    param => {}
1381
);
1382
$result = $dbi->select(
1383
    table => 'table1',
1384
    where => $where,
1385
);
1386
$row = $result->all;
1387
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1388

            
1389

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1394
test 'register_tag_processor';
1395
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1396
$dbi->register_tag_processor(
1397
    a => sub { 1 }
1398
);
1399
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1400

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1401
test 'register_tag';
1402
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1403
$dbi->register_tag(
1404
    b => sub { 2 }
1405
);
1406
is($dbi->query_builder->tags->{b}->(), 2);
1407

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1408
test 'table not specify exception';
1409
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1410
eval {$dbi->insert};
1411
like($@, qr/table/);
1412
eval {$dbi->update};
1413
like($@, qr/table/);
1414
eval {$dbi->delete};
1415
like($@, qr/table/);
1416
eval {$dbi->select};
1417
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1418

            
1419

            
1420
test 'more tests';
1421
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1422
eval{$dbi->apply_filter('table', 'column', [])};
1423
like($@, qr/apply_filter/);
1424

            
1425
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1426
like($@, qr/apply_filter/);
1427

            
1428
$dbi->apply_filter(
1429

            
1430
);
1431
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1432
$dbi->execute($CREATE_TABLE->{0});
1433
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1434
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1435
$dbi->apply_filter('table1', 'key2', 
1436
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1437
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1438
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1439

            
1440
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1441
$dbi->execute($CREATE_TABLE->{0});
1442
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1443
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1444
$dbi->apply_filter('table1', 'key2', {});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1445
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1446
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1447

            
1448
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1449
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1450
like($@, qr/not registered/);
1451
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1452
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1453
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1454
is($dbi->one, 1);
1455

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

            
1459
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1460
$dbi->execute($CREATE_TABLE->{0});
1461
$dbi->register_filter(twice => sub { $_[0] * 2 });
1462
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1463
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1464
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1465
is_deeply($row, {key1 => 2, key2 => 2});
1466
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1467
             filter => {key1 => 'no'}) };
1468
like($@, qr//);
1469

            
1470
$dbi->register_filter(one => sub { });
1471
$dbi->default_fetch_filter('one');
1472
ok($dbi->default_fetch_filter);
1473
$dbi->default_bind_filter('one');
1474
ok($dbi->default_bind_filter);
1475
eval{$dbi->default_fetch_filter('no')};
1476
like($@, qr/not registered/);
1477
eval{$dbi->default_bind_filter('no')};
1478
like($@, qr/not registered/);
1479
$dbi->default_bind_filter(undef);
1480
ok(!defined $dbi->default_bind_filter);
1481
$dbi->default_fetch_filter(undef);
1482
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1483
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1484
like($@, qr/Tag not finished/);
1485

            
1486
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1487
$dbi->execute($CREATE_TABLE->{0});
1488
$dbi->register_filter(one => sub { 1 });
1489
$result = $dbi->select(table => 'table1');
1490
eval {$result->filter(key1 => 'no')};
1491
like($@, qr/not registered/);
1492
eval {$result->end_filter(key1 => 'no')};
1493
like($@, qr/not registered/);
1494
$result->default_filter(undef);
1495
ok(!defined $result->default_filter);
1496
$result->default_filter('one');
1497
is($result->default_filter->(), 1);
1498

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1499
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1500
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1501
                             dbi_option => {PrintError => 1});
1502
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1503
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1504
                             dbi_options => {PrintError => 1});
1505
ok($dbi->dbh->{PrintError});
1506

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1507
test 'DBIx::Custom::Result stash()';
1508
$result = DBIx::Custom::Result->new;
1509
is_deeply($result->stash, {}, 'default');
1510
$result->stash->{foo} = 1;
1511
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1512

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1513
test 'filter __ expression';
1514
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1515
$dbi->execute('create table company (id, name, location_id)');
1516
$dbi->execute('create table location (id, name)');
1517
$dbi->apply_filter('location',
1518
  name => {in => sub { uc $_[0] } }
1519
);
1520

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

            
1524
$result = $dbi->select(
1525
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1526
    column => ['location.name as location__name']
1527
);
1528
is($result->fetch_first->[0], 'B');
1529

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1530
$result = $dbi->select(
1531
    table => 'company', relation => {'company.location_id' => 'location.id'},
1532
    column => ['location.name as location__name']
1533
);
1534
is($result->fetch_first->[0], 'B');
1535

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1536
$result = $dbi->select(
1537
    table => 'company', relation => {'company.location_id' => 'location.id'},
1538
    column => ['location.name as "location.name"']
1539
);
1540
is($result->fetch_first->[0], 'B');
1541

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1542
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1543
use MyDBI1;
1544
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1545
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1546
$model = $dbi->model('book');
1547
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1548
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1549
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1550
$model = $dbi->model('company');
1551
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1552
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1553
is($dbi->models->{'book'}, $dbi->model('book'));
1554
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1555

            
1556
{
1557
    package MyDBI4;
1558

            
1559
    use strict;
1560
    use warnings;
1561

            
1562
    use base 'DBIx::Custom';
1563

            
1564
    sub connect {
1565
        my $self = shift->SUPER::connect(@_);
1566
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1567
        $self->include_model(
1568
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1569
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1570
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1571
            ]
1572
        );
1573
    }
1574

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

            
1577
    use strict;
1578
    use warnings;
1579

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

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

            
1584
    use strict;
1585
    use warnings;
1586

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

            
1589
    sub insert {
1590
        my ($self, $param) = @_;
1591
        
1592
        return $self->SUPER::insert(param => $param);
1593
    }
1594

            
1595
    sub list { shift->select; }
1596

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

            
1599
    use strict;
1600
    use warnings;
1601

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

            
1604
    sub insert {
1605
        my ($self, $param) = @_;
1606
        
1607
        return $self->SUPER::insert(param => $param);
1608
    }
1609

            
1610
    sub list { shift->select; }
1611
}
1612
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1613
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1614
$model = $dbi->model('book');
1615
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1616
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1617
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1618
$model = $dbi->model('company');
1619
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1620
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1621

            
1622
{
1623
     package MyDBI5;
1624

            
1625
    use strict;
1626
    use warnings;
1627

            
1628
    use base 'DBIx::Custom';
1629

            
1630
    sub connect {
1631
        my $self = shift->SUPER::connect(@_);
1632
        
1633
        $self->include_model('MyModel4');
1634
    }
1635
}
1636
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1637
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1638
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1639
$model = $dbi->model('company');
1640
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1641
is_deeply($model->list->all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1642
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1643
$model = $dbi->model('book');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1644
is_deeply($model->list->all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1645

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1646
test 'primary_key';
1647
use MyDBI1;
1648
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1649
$model = $dbi->model('book');
1650
$model->primary_key(['id', 'number']);
1651
is_deeply($model->primary_key, ['id', 'number']);
1652

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1653
test 'columns';
1654
use MyDBI1;
1655
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1656
$model = $dbi->model('book');
1657
$model->columns(['id', 'number']);
1658
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1659

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1660
test 'setup_model';
1661
use MyDBI1;
1662
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1663
$dbi->execute('create table book (id)');
1664
$dbi->execute('create table company (id, name);');
1665
$dbi->execute('create table test (id, name, primary key (id, name));');
1666
$dbi->setup_model;
1667
is_deeply($dbi->model('book')->columns, ['id']);
1668
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1669

            
1670
test 'delete_at';
1671
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1672
$dbi->execute($CREATE_TABLE->{1});
1673
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1674
$dbi->delete_at(
1675
    table => 'table1',
1676
    primary_key => ['key1', 'key2'],
1677
    where => [1, 2],
1678
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1679
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1680

            
1681
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1682
$dbi->delete_at(
1683
    table => 'table1',
1684
    primary_key => 'key1',
1685
    where => 1,
1686
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1687
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1688

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1689
test 'insert_at';
1690
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1691
$dbi->execute($CREATE_TABLE->{1});
1692
$dbi->insert_at(
1693
    primary_key => ['key1', 'key2'], 
1694
    table => 'table1',
1695
    where => [1, 2],
1696
    param => {key3 => 3}
1697
);
added tests
Yuki Kimoto authored on 2011-06-08
1698
is($dbi->select(table => 'table1')->one->{key1}, 1);
1699
is($dbi->select(table => 'table1')->one->{key2}, 2);
1700
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1701

            
1702
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1703
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1704
$dbi->insert_at(
1705
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1706
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1707
    where => 1,
1708
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1709
);
1710

            
added tests
Yuki Kimoto authored on 2011-06-08
1711
is($dbi->select(table => 'table1')->one->{key1}, 1);
1712
is($dbi->select(table => 'table1')->one->{key2}, 2);
1713
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1714

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

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1725
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1726
$dbi->execute($CREATE_TABLE->{1});
1727
$dbi->insert_at(
1728
    {key3 => 3},
1729
    primary_key => ['key1', 'key2'], 
1730
    table => 'table1',
1731
    where => [1, 2],
1732
);
added tests
Yuki Kimoto authored on 2011-06-08
1733
is($dbi->select(table => 'table1')->one->{key1}, 1);
1734
is($dbi->select(table => 'table1')->one->{key2}, 2);
1735
is($dbi->select(table => 'table1')->one->{key3}, 3);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1736

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1737
test 'update_at';
1738
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1739
$dbi->execute($CREATE_TABLE->{1});
1740
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1741
$dbi->update_at(
1742
    table => 'table1',
1743
    primary_key => ['key1', 'key2'],
1744
    where => [1, 2],
1745
    param => {key3 => 4}
1746
);
added tests
Yuki Kimoto authored on 2011-06-08
1747
is($dbi->select(table => 'table1')->one->{key1}, 1);
1748
is($dbi->select(table => 'table1')->one->{key2}, 2);
1749
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1750

            
1751
$dbi->delete_all(table => 'table1');
1752
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1753
$dbi->update_at(
1754
    table => 'table1',
1755
    primary_key => 'key1',
1756
    where => 1,
1757
    param => {key3 => 4}
1758
);
added tests
Yuki Kimoto authored on 2011-06-08
1759
is($dbi->select(table => 'table1')->one->{key1}, 1);
1760
is($dbi->select(table => 'table1')->one->{key2}, 2);
1761
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1762

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1763
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1764
$dbi->execute($CREATE_TABLE->{1});
1765
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1766
$dbi->update_at(
1767
    {key3 => 4},
1768
    table => 'table1',
1769
    primary_key => ['key1', 'key2'],
1770
    where => [1, 2]
1771
);
added tests
Yuki Kimoto authored on 2011-06-08
1772
is($dbi->select(table => 'table1')->one->{key1}, 1);
1773
is($dbi->select(table => 'table1')->one->{key2}, 2);
1774
is($dbi->select(table => 'table1')->one->{key3}, 4);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1775

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1776
test 'select_at';
1777
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1778
$dbi->execute($CREATE_TABLE->{1});
1779
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1780
$result = $dbi->select_at(
1781
    table => 'table1',
1782
    primary_key => ['key1', 'key2'],
1783
    where => [1, 2]
1784
);
added tests
Yuki Kimoto authored on 2011-06-08
1785
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1786
is($row->{key1}, 1);
1787
is($row->{key2}, 2);
1788
is($row->{key3}, 3);
1789

            
1790
$dbi->delete_all(table => 'table1');
1791
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1792
$result = $dbi->select_at(
1793
    table => 'table1',
1794
    primary_key => 'key1',
1795
    where => 1,
1796
);
added tests
Yuki Kimoto authored on 2011-06-08
1797
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1798
is($row->{key1}, 1);
1799
is($row->{key2}, 2);
1800
is($row->{key3}, 3);
1801

            
1802
$dbi->delete_all(table => 'table1');
1803
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1804
$result = $dbi->select_at(
1805
    table => 'table1',
1806
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1807
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1808
);
added tests
Yuki Kimoto authored on 2011-06-08
1809
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1810
is($row->{key1}, 1);
1811
is($row->{key2}, 2);
1812
is($row->{key3}, 3);
1813

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1814
eval {
1815
    $result = $dbi->select_at(
1816
        table => 'table1',
1817
        primary_key => ['key1', 'key2'],
1818
        where => {},
1819
    );
1820
};
1821
like($@, qr/must be/);
1822

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1823
eval {
1824
    $result = $dbi->select_at(
1825
        table => 'table1',
1826
        primary_key => ['key1', 'key2'],
1827
        where => [1],
1828
    );
1829
};
1830
like($@, qr/same/);
1831

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1832
eval {
1833
    $result = $dbi->update_at(
1834
        table => 'table1',
1835
        primary_key => ['key1', 'key2'],
1836
        where => {},
1837
        param => {key1 => 1, key2 => 2},
1838
    );
1839
};
1840
like($@, qr/must be/);
1841

            
1842
eval {
1843
    $result = $dbi->delete_at(
1844
        table => 'table1',
1845
        primary_key => ['key1', 'key2'],
1846
        where => {},
1847
    );
1848
};
1849
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1850

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1851
test 'columns';
1852
use MyDBI1;
1853
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1854
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1855

            
1856

            
1857
test 'model delete_at';
1858
{
1859
    package MyDBI6;
1860
    
1861
    use base 'DBIx::Custom';
1862
    
1863
    sub connect {
1864
        my $self = shift->SUPER::connect(@_);
1865
        
1866
        $self->include_model('MyModel5');
1867
        
1868
        return $self;
1869
    }
1870
}
1871
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1872
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1873
$dbi->execute("create table table2 (key1, key2, key3)");
1874
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1875
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1876
$dbi->model('table1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1877
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1878
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1879
$dbi->model('table1_1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1880
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1881
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1882
$dbi->model('table1_3')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1883
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1884

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1885
test 'model insert_at';
1886
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1887
$dbi->execute($CREATE_TABLE->{1});
1888
$dbi->model('table1')->insert_at(
1889
    where => [1, 2],
1890
    param => {key3 => 3}
1891
);
1892
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1893
$row = $result->one;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1894
is($row->{key1}, 1);
1895
is($row->{key2}, 2);
1896
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1897

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1898
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1899
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1900
$dbi->execute($CREATE_TABLE->{1});
1901
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1902
$dbi->model('table1')->update_at(
1903
    where => [1, 2],
1904
    param => {key3 => 4}
1905
);
1906
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1907
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1908
is($row->{key1}, 1);
1909
is($row->{key2}, 2);
1910
is($row->{key3}, 4);
1911

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1912
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1913
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1914
$dbi->execute($CREATE_TABLE->{1});
1915
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1916
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1917
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1918
is($row->{key1}, 1);
1919
is($row->{key2}, 2);
1920
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1921

            
1922

            
cleanup
Yuki Kimoto authored on 2011-03-21
1923
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1924
{
1925
    package MyDBI7;
1926
    
1927
    use base 'DBIx::Custom';
1928
    
1929
    sub connect {
1930
        my $self = shift->SUPER::connect(@_);
1931
        
1932
        $self->include_model('MyModel6');
1933
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1934
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1935
        return $self;
1936
    }
1937
}
1938
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1939
$dbi->execute($CREATE_TABLE->{0});
1940
$dbi->execute($CREATE_TABLE->{2});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
1941
$dbi->separator('__');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1942
$dbi->setup_model;
1943
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1944
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1945
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1946
$result = $model->select(
1947
    column => [$model->mycolumn, $model->column('table2')],
1948
    where => {'table1.key1' => 1}
1949
);
added tests
Yuki Kimoto authored on 2011-06-08
1950
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1951
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1952

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

            
1959
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1960
$update_param = $dbi->update_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1961
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1962
update table1 $update_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1963
where key1 = 1
1964
EOS
1965
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1966
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1967
$rows   = $result->all;
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1968
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1969
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1970
                  "basic");
1971

            
1972

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

            
1978
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1979
$update_param = $dbi->update_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1980
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1981
update table1 $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1982
where key1 = 1
1983
EOS
1984
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1985
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1986
$rows   = $result->all;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1987
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1988
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1989
                  "basic");
1990

            
1991
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1992
$dbi->execute($CREATE_TABLE->{1});
1993
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1994
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1995

            
1996
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1997
$update_param = $dbi->update_param($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1998
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1999
update table1 set $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2000
where key1 = 1
2001
EOS
2002
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2003
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2004
$rows   = $result->all;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2005
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
2006
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
2007
                  "update param no_set");
2008

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

            
2013

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

            
2020
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2021
$update_param = $dbi->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2022
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2023
update table1 set $update_param
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2024
where key1 = 1
2025
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2026
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2027
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2028
$rows   = $result->all;
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2029
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2030
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
2031
                  "basic");
2032

            
2033

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2034
test 'insert_param';
2035
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2036
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2037
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2038
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2039
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2040
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2041
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2042
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2043
is($dbi->select(table => 'table1')->one->{key1}, 1);
2044
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2045

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2046
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2047
$dbi->quote('"');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2048
$dbi->execute($CREATE_TABLE->{1});
2049
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2050
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2051
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2052
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2053
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2054
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2055
is($dbi->select(table => 'table1')->one->{key1}, 1);
2056
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
2057

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

            
2061

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2062
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
2063
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2064
$dbi->execute($CREATE_TABLE->{0});
2065
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2066
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
2067
$dbi->execute($CREATE_TABLE->{2});
2068
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2069
$dbi->execute($CREATE_TABLE->{4});
2070
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
2071
$rows = $dbi->select(
2072
    table => 'table1',
2073
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2074
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2075
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2076
)->all;
cleanup
Yuki Kimoto authored on 2011-03-08
2077
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
2078

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2079
$rows = $dbi->select(
2080
    table => 'table1',
2081
    where   => {'key1' => 1},
2082
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2083
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2084
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2085

            
cleanup
Yuki Kimoto authored on 2011-03-08
2086
eval {
2087
    $rows = $dbi->select(
2088
        table => 'table1',
2089
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2090
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2091
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2092
    );
2093
};
2094
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2095

            
2096
$rows = $dbi->select(
2097
    table => 'table1',
2098
    where   => {'key1' => 1},
2099
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2100
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2101
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2102
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2103

            
2104
$rows = $dbi->select(
2105
    column => 'table3.key4 as table3__key4',
2106
    table => 'table1',
2107
    where   => {'table1.key1' => 1},
2108
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2109
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2110
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2111
is_deeply($rows, [{table3__key4 => 4}]);
2112

            
2113
$rows = $dbi->select(
2114
    column => 'table1.key1 as table1__key1',
2115
    table => 'table1',
2116
    where   => {'table3.key4' => 4},
2117
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2118
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2119
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2120
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2121

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2122
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2123
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2124
$dbi->execute($CREATE_TABLE->{0});
2125
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2126
$dbi->execute($CREATE_TABLE->{2});
2127
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2128
$rows = $dbi->select(
2129
    table => 'table1',
2130
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2131
    where   => {'table1.key2' => 2},
2132
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2133
)->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2134
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2135
          'quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2136

            
2137
{
2138
    package MyDBI8;
2139
    
2140
    use base 'DBIx::Custom';
2141
    
2142
    sub connect {
2143
        my $self = shift->SUPER::connect(@_);
2144
        
2145
        $self->include_model('MyModel7');
2146
        
2147
        return $self;
2148
    }
2149
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2150

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2151
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2152
$dbi->execute($CREATE_TABLE->{0});
2153
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2154
$sql = <<"EOS";
2155
left outer join (
2156
  select * from table1 as t1
2157
  where t1.key2 = (
2158
    select max(t2.key2) from table1 as t2
2159
    where t1.key1 = t2.key1
2160
  )
2161
) as latest_table1 on table1.key1 = latest_table1.key1
2162
EOS
2163
$join = [$sql];
2164
$rows = $dbi->select(
2165
    table => 'table1',
2166
    column => 'latest_table1.key1 as latest_table1__key1',
2167
    join  => $join
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2168
)->all;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2169
is_deeply($rows, [{latest_table1__key1 => 1}]);
2170

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2171
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2172
$dbi->execute($CREATE_TABLE->{0});
2173
$dbi->execute($CREATE_TABLE->{2});
2174
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2175
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2176
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2177
$result = $dbi->select(
2178
    table => 'table1',
2179
    join => [
2180
        "left outer join table2 on table2.key2 = '4' and table1.key1 = table2.key1"
2181
    ]
2182
);
2183
is_deeply($result->all, [{key1 => 1, key2 => 2}]);
2184
$result = $dbi->select(
2185
    table => 'table1',
2186
    column => [{table2 => ['key3']}],
2187
    join => [
2188
        "left outer join table2 on table2.key3 = '4' and table1.key1 = table2.key1"
2189
    ]
2190
);
2191
is_deeply($result->all, [{'table2.key3' => 4}]);
added join new syntax
Yuki Kimoto authored on 2011-07-28
2192
$result = $dbi->select(
2193
    table => 'table1',
2194
    column => [{table2 => ['key3']}],
2195
    join => [
2196
        "left outer join table2 on table1.key1 = table2.key1 and table2.key3 = '4'"
2197
    ]
2198
);
2199
is_deeply($result->all, [{'table2.key3' => 4}]);
2200

            
2201
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2202
$dbi->execute($CREATE_TABLE->{0});
2203
$dbi->execute($CREATE_TABLE->{2});
2204
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2205
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2206
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2207
$result = $dbi->select(
2208
    table => 'table1',
2209
    column => [{table2 => ['key3']}],
2210
    join => [
2211
        {
2212
            clause => "left outer join table2 on table2.key3 = '4' and table1.key1 = table2.key1",
2213
            table => ['table1', 'table2']
2214
        }
2215
    ]
2216
);
2217
is_deeply($result->all, [{'table2.key3' => 4}]);
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2218

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2219
test 'mycolumn';
2220
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2221
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2222
$dbi->execute($CREATE_TABLE->{2});
2223
$dbi->setup_model;
2224
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2225
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2226
$model = $dbi->model('table1');
2227
$result = $model->select_at(
2228
    column => [
2229
        $model->mycolumn,
2230
        $model->column('table2')
2231
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2232
);
added tests
Yuki Kimoto authored on 2011-06-08
2233
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2234
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2235

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2236
$result = $model->select_at(
2237
    column => [
2238
        $model->mycolumn(['key1']),
2239
        $model->column(table2 => ['key1'])
2240
    ]
2241
);
added tests
Yuki Kimoto authored on 2011-06-08
2242
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2243
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2244
$result = $model->select_at(
2245
    column => [
2246
        $model->mycolumn(['key1']),
2247
        {table2 => ['key1']}
2248
    ]
2249
);
added tests
Yuki Kimoto authored on 2011-06-08
2250
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2251
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2252

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2253
$result = $model->select_at(
2254
    column => [
2255
        $model->mycolumn(['key1']),
2256
        ['table2.key1', as => 'table2.key1']
2257
    ]
2258
);
2259
is_deeply($result->one,
2260
          {key1 => 1, 'table2.key1' => 1});
2261

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2262
$result = $model->select_at(
2263
    column => [
2264
        $model->mycolumn(['key1']),
2265
        ['table2.key1' => 'table2.key1']
2266
    ]
2267
);
2268
is_deeply($result->one,
2269
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2270

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2271
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2272
{
2273
    package MyDBI9;
2274
    
2275
    use base 'DBIx::Custom';
2276
    
2277
    sub connect {
2278
        my $self = shift->SUPER::connect(@_);
2279
        
2280
        $self->include_model('MyModel8')->setup_model;
2281
        
2282
        return $self;
2283
    }
2284
}
2285
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2286
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2287
$model = $dbi->model('table1');
2288
eval{$model->execute('select * from table1')};
2289
ok(!$@);
2290

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2291
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2292
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2293
$dbi->execute($CREATE_TABLE->{0});
2294
$dbi->execute($CREATE_TABLE->{2});
2295
$dbi->setup_model;
2296
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2297
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2298
$model = $dbi->model('table1');
2299
$result = $model->select(
2300
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2301
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2302
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2303
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2304
);
added tests
Yuki Kimoto authored on 2011-06-08
2305
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2306
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2307

            
cleanup
Yuki Kimoto authored on 2011-06-13
2308
$dbi->separator('__');
2309
$result = $model->select(
2310
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2311
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2312
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2313
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2314
);
2315
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2316
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2317

            
2318
$dbi->separator('-');
2319
$result = $model->select(
2320
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2321
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2322
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2323
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2324
);
2325
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2326
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2327

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2328
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2329
$dbi = DBIx::Custom->connect(
2330
    data_source => 'dbi:SQLite:dbname=:memory:',
2331
    dbi_option => {
2332
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2333
    }
2334
);
2335
my $binary = pack("I3", 1, 2, 3);
2336
$dbi->execute('create table table1(key1, key2)');
2337
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2338
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2339
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2340
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2341
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2342
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2343
is($row->{key1_length}, length $binary);
2344

            
2345
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2346
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2347
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2348
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2349
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2350
$row = $result->one;
2351
is($row->{key1_length}, length $binary);
2352

            
2353

            
2354
test 'bind_type option';
2355
$dbi = DBIx::Custom->connect(
2356
    data_source => 'dbi:SQLite:dbname=:memory:',
2357
    dbi_option => {
2358
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2359
    }
2360
);
2361
$binary = pack("I3", 1, 2, 3);
2362
$dbi->execute('create table table1(key1, key2)');
2363
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2364
$result = $dbi->select(table => 'table1');
2365
$row   = $result->one;
2366
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2367
$result = $dbi->execute('select length(key1) as key1_length from table1');
2368
$row = $result->one;
2369
is($row->{key1_length}, length $binary);
2370

            
2371
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2372
$result = $dbi->select(table => 'table1');
2373
$row   = $result->one;
2374
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2375
$result = $dbi->execute('select length(key1) as key1_length from table1');
2376
$row = $result->one;
2377
is($row->{key1_length}, length $binary);
2378

            
2379
test 'model type attribute';
2380
$dbi = DBIx::Custom->connect(
2381
    data_source => 'dbi:SQLite:dbname=:memory:',
2382
    dbi_option => {
2383
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2384
    }
2385
);
2386
$binary = pack("I3", 1, 2, 3);
2387
$dbi->execute('create table table1(key1, key2)');
2388
$model = $dbi->create_model(table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
2389
$model->insert(param => {key1 => $binary, key2 => 'あ'});
2390
$result = $dbi->select(table => 'table1');
2391
$row   = $result->one;
2392
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2393
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2394
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2395
is($row->{key1_length}, length $binary);
2396

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2397
test 'create_model';
2398
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2399
$dbi->execute($CREATE_TABLE->{0});
2400
$dbi->execute($CREATE_TABLE->{2});
2401

            
2402
$dbi->create_model(
2403
    table => 'table1',
2404
    join => [
2405
       'left outer join table2 on table1.key1 = table2.key1'
2406
    ],
2407
    primary_key => ['key1']
2408
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2409
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2410
    table => 'table2'
2411
);
2412
$dbi->create_model(
2413
    table => 'table3',
2414
    filter => [
2415
        key1 => {in => sub { uc $_[0] }}
2416
    ]
2417
);
2418
$dbi->setup_model;
2419
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2420
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2421
$model = $dbi->model('table1');
2422
$result = $model->select(
2423
    column => [$model->mycolumn, $model->column('table2')],
2424
    where => {'table1.key1' => 1}
2425
);
added tests
Yuki Kimoto authored on 2011-06-08
2426
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2427
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2428
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2429

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2430
test 'model method';
2431
test 'create_model';
2432
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2433
$dbi->execute($CREATE_TABLE->{2});
2434
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2435
$model = $dbi->create_model(
2436
    table => 'table2'
2437
);
2438
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2439
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2440

            
2441
test 'merge_param';
2442
{
2443
    my $dbi = DBIx::Custom->new;
2444
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2445
    my $param2 = {key1 => 1, key2 => 2};
2446
    my $param3 = {key1 => 1};
2447
    my $param = $dbi->merge_param($param1, $param2, $param3);
2448
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2449
}
2450

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2451
{
2452
    my $dbi = DBIx::Custom->new;
2453
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2454
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2455
    my $param = $dbi->merge_param($param1, $param2);
2456
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2457
}
2458

            
cleanup
Yuki Kimoto authored on 2011-04-01
2459
test 'select() param option';
2460
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2461
$dbi->execute($CREATE_TABLE->{0});
2462
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2463
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2464
$dbi->execute($CREATE_TABLE->{2});
2465
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2466
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2467
$rows = $dbi->select(
2468
    table => 'table1',
2469
    column => 'table1.key1 as table1_key1, key2, key3',
2470
    where   => {'table1.key2' => 3},
2471
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2472
              ' as table2 on table1.key1 = table2.key1'],
2473
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2474
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2475
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2476

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

            
2478
test 'select() wrap option';
2479
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2480
$dbi->execute($CREATE_TABLE->{0});
2481
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2482
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2483
$rows = $dbi->select(
2484
    table => 'table1',
2485
    column => 'key1',
2486
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2487
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2488
is_deeply($rows, [{key1 => 1}]);
2489

            
2490
eval {
2491
$dbi->select(
2492
    table => 'table1',
2493
    column => 'key1',
2494
    wrap => 'select * from ('
2495
)
2496
};
cleanup
Yuki Kimoto authored on 2011-04-25
2497
like($@, qr/array/);
2498

            
2499
test 'select() string where';
2500
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2501
$dbi->execute($CREATE_TABLE->{0});
2502
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2503
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2504
$rows = $dbi->select(
2505
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2506
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2507
    where_param => {key1 => 1, key2 => 2}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2508
)->all;
cleanup
Yuki Kimoto authored on 2011-04-25
2509
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2510

            
updated pod
Yuki Kimoto authored on 2011-06-21
2511
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2512
$dbi->execute($CREATE_TABLE->{0});
2513
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2514
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2515
$rows = $dbi->select(
2516
    table => 'table1',
2517
    where => [
2518
        'key1 = :key1 and key2 = :key2',
2519
        {key1 => 1, key2 => 2}
2520
    ]
2521
)->all;
2522
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2523

            
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2524
test 'delete() string where';
2525
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2526
$dbi->execute($CREATE_TABLE->{0});
2527
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2528
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2529
$dbi->delete(
2530
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2531
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2532
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2533
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2534
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2535
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2536

            
updated pod
Yuki Kimoto authored on 2011-06-21
2537
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2538
$dbi->execute($CREATE_TABLE->{0});
2539
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2540
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2541
$dbi->delete(
2542
    table => 'table1',
2543
    where => [
2544
        'key1 = :key1 and key2 = :key2',
2545
         {key1 => 1, key2 => 2}
2546
    ]
2547
);
2548
$rows = $dbi->select(table => 'table1')->all;
2549
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2550

            
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2551

            
2552
test 'update() string where';
2553
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2554
$dbi->execute($CREATE_TABLE->{0});
2555
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2556
$dbi->update(
2557
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2558
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2559
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2560
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2561
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2562
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2563
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2564

            
updated pod
Yuki Kimoto authored on 2011-06-21
2565
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2566
$dbi->execute($CREATE_TABLE->{0});
2567
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2568
$dbi->update(
2569
    table => 'table1',
2570
    param => {key1 => 5},
2571
    where => [
2572
        'key1 = :key1 and key2 = :key2',
2573
        {key1 => 1, key2 => 2}
2574
    ]
2575
);
2576
$rows = $dbi->select(table => 'table1')->all;
2577
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2578

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2579
test 'insert id and primary_key option';
2580
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2581
$dbi->execute($CREATE_TABLE->{1});
2582
$dbi->insert(
2583
    primary_key => ['key1', 'key2'], 
2584
    table => 'table1',
2585
    id => [1, 2],
2586
    param => {key3 => 3}
2587
);
2588
is($dbi->select(table => 'table1')->one->{key1}, 1);
2589
is($dbi->select(table => 'table1')->one->{key2}, 2);
2590
is($dbi->select(table => 'table1')->one->{key3}, 3);
2591

            
2592
$dbi->delete_all(table => 'table1');
2593
$dbi->insert(
2594
    primary_key => 'key1', 
2595
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2596
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2597
    param => {key2 => 2, key3 => 3}
2598
);
2599

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2600
is($dbi->select(table => 'table1')->one->{key1}, 0);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2601
is($dbi->select(table => 'table1')->one->{key2}, 2);
2602
is($dbi->select(table => 'table1')->one->{key3}, 3);
2603

            
2604
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2605
$dbi->execute($CREATE_TABLE->{1});
2606
$dbi->insert(
2607
    {key3 => 3},
2608
    primary_key => ['key1', 'key2'], 
2609
    table => 'table1',
2610
    id => [1, 2],
2611
);
2612
is($dbi->select(table => 'table1')->one->{key1}, 1);
2613
is($dbi->select(table => 'table1')->one->{key2}, 2);
2614
is($dbi->select(table => 'table1')->one->{key3}, 3);
2615

            
cleanup
Yuki Kimoto authored on 2011-06-08
2616

            
added tests
Yuki Kimoto authored on 2011-06-08
2617
test 'model insert id and primary_key option';
2618
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2619
$dbi->execute($CREATE_TABLE->{1});
2620
$dbi->model('table1')->insert(
2621
    id => [1, 2],
2622
    param => {key3 => 3}
2623
);
2624
$result = $dbi->model('table1')->select;
2625
$row = $result->one;
2626
is($row->{key1}, 1);
2627
is($row->{key2}, 2);
2628
is($row->{key3}, 3);
2629

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2630
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2631
$dbi->execute($CREATE_TABLE->{1});
2632
$dbi->model('table1')->insert(
2633
    {key3 => 3},
2634
    id => [1, 2]
2635
);
2636
$result = $dbi->model('table1')->select;
2637
$row = $result->one;
2638
is($row->{key1}, 1);
2639
is($row->{key2}, 2);
2640
is($row->{key3}, 3);
2641

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2642
test 'update and id option';
2643
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2644
$dbi->execute($CREATE_TABLE->{1});
2645
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2646
$dbi->update(
2647
    table => 'table1',
2648
    primary_key => ['key1', 'key2'],
2649
    id => [1, 2],
2650
    param => {key3 => 4}
2651
);
2652
is($dbi->select(table => 'table1')->one->{key1}, 1);
2653
is($dbi->select(table => 'table1')->one->{key2}, 2);
2654
is($dbi->select(table => 'table1')->one->{key3}, 4);
2655

            
2656
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2657
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2658
$dbi->update(
2659
    table => 'table1',
2660
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2661
    id => 0,
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2662
    param => {key3 => 4}
2663
);
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2664
is($dbi->select(table => 'table1')->one->{key1}, 0);
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2665
is($dbi->select(table => 'table1')->one->{key2}, 2);
2666
is($dbi->select(table => 'table1')->one->{key3}, 4);
2667

            
2668
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2669
$dbi->execute($CREATE_TABLE->{1});
2670
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2671
$dbi->update(
2672
    {key3 => 4},
2673
    table => 'table1',
2674
    primary_key => ['key1', 'key2'],
2675
    id => [1, 2]
2676
);
2677
is($dbi->select(table => 'table1')->one->{key1}, 1);
2678
is($dbi->select(table => 'table1')->one->{key2}, 2);
2679
is($dbi->select(table => 'table1')->one->{key3}, 4);
2680

            
2681

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2682
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2683
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2684
$dbi->execute($CREATE_TABLE->{1});
2685
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2686
$dbi->model('table1')->update(
2687
    id => [1, 2],
2688
    param => {key3 => 4}
2689
);
2690
$result = $dbi->model('table1')->select;
2691
$row = $result->one;
2692
is($row->{key1}, 1);
2693
is($row->{key2}, 2);
2694
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2695

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2696

            
2697
test 'delete and id option';
2698
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2699
$dbi->execute($CREATE_TABLE->{1});
2700
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2701
$dbi->delete(
2702
    table => 'table1',
2703
    primary_key => ['key1', 'key2'],
2704
    id => [1, 2],
2705
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2706
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2707

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2708
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2709
$dbi->delete(
2710
    table => 'table1',
2711
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2712
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2713
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2714
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2715

            
2716

            
2717
test 'model delete and id option';
2718
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2719
$dbi->execute($CREATE_TABLE->{1});
2720
$dbi->execute("create table table2 (key1, key2, key3)");
2721
$dbi->execute("create table table3 (key1, key2, key3)");
2722
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2723
$dbi->model('table1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2724
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2725
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2726
$dbi->model('table1_1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2727
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2728
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2729
$dbi->model('table1_3')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2730
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2731

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2732

            
2733
test 'select and id option';
2734
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2735
$dbi->execute($CREATE_TABLE->{1});
2736
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2737
$result = $dbi->select(
2738
    table => 'table1',
2739
    primary_key => ['key1', 'key2'],
2740
    id => [1, 2]
2741
);
2742
$row = $result->one;
2743
is($row->{key1}, 1);
2744
is($row->{key2}, 2);
2745
is($row->{key3}, 3);
2746

            
2747
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2748
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2749
$result = $dbi->select(
2750
    table => 'table1',
2751
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2752
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2753
);
2754
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2755
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2756
is($row->{key2}, 2);
2757
is($row->{key3}, 3);
2758

            
2759
$dbi->delete_all(table => 'table1');
2760
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2761
$result = $dbi->select(
2762
    table => 'table1',
2763
    primary_key => ['key1', 'key2'],
2764
    id => [1, 2]
2765
);
2766
$row = $result->one;
2767
is($row->{key1}, 1);
2768
is($row->{key2}, 2);
2769
is($row->{key3}, 3);
2770

            
2771

            
2772
test 'model select_at';
2773
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2774
$dbi->execute($CREATE_TABLE->{1});
2775
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2776
$result = $dbi->model('table1')->select(id => [1, 2]);
2777
$row = $result->one;
2778
is($row->{key1}, 1);
2779
is($row->{key2}, 2);
2780
is($row->{key3}, 3);
2781

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2782
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2783
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2784
$dbi->execute($CREATE_TABLE->{0});
2785
$dbi->execute($CREATE_TABLE->{2});
2786
$dbi->setup_model;
2787
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2788
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2789
$model = $dbi->model('table1');
2790
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2791
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2792
    where => {'table1.key1' => 1}
2793
);
2794
is_deeply($result->one,
2795
          {'table2.key1' => 1, 'table2.key3' => 3});
2796

            
2797
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2798
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2799
    where => {'table1.key1' => 1}
2800
);
2801
is_deeply($result->one,
2802
          {'table2.key1' => 1, 'table2.key3' => 3});
2803

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2804

            
2805
test 'type_rule from';
2806
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2807
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2808
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2809
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2810
    }
2811
);
2812
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2813
$dbi->insert({key1 => 'a'}, table => 'table1');
2814
$result = $dbi->select(table => 'table1');
2815
is($result->fetch_first->[0], 'A');
2816

            
2817
$result = $dbi->select(table => 'table1');
2818
is($result->one->{key1}, 'A');
2819

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2820

            
2821
test 'type_rule into';
2822
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2823
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2824
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2825
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2826
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2827
    }
2828
);
2829
$dbi->insert({key1 => 'a'}, table => 'table1');
2830
$result = $dbi->select(table => 'table1');
2831
is($result->one->{key1}, 'A');
2832

            
2833
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2834
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2835
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2836
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2837
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2838
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2839
);
2840
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2841
$result = $dbi->select(table => 'table1');
2842
$row = $result->one;
2843
is($row->{key1}, 'A');
2844
is($row->{key2}, 'B');
2845

            
2846
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2847
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2848
$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1');
2849
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2850
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2851
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2852
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2853
);
2854
$result = $dbi->execute(
2855
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2856
    param => {key1 => 'a', 'table1.key2' => 'b'}
2857
);
2858
$row = $result->one;
2859
is($row->{key1}, 'a');
2860
is($row->{key2}, 'B');
2861

            
2862
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2863
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2864
$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1');
2865
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2866
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2867
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2868
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2869
);
2870
$result = $dbi->execute(
2871
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2872
    param => {key1 => 'a', 'table1.key2' => 'b'},
2873
    table => 'table1'
2874
);
2875
$row = $result->one;
2876
is($row->{key1}, 'A');
2877
is($row->{key2}, 'B');
2878

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2879
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2880
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2881
$dbi->register_filter(twice => sub { $_[0] * 2 });
2882
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2883
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2884
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2885
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2886
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2887
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2888
    }
2889
);
2890
$dbi->insert({key1 => 2}, table => 'table1');
2891
$result = $dbi->select(table => 'table1');
2892
is($result->fetch->[0], 8);
2893

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2894
test 'type_rule and filter order';
2895
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2896
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2897
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2898
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2899
        date => sub { $_[0] . 'b' }
2900
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2901
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2902
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2903
    },
2904
    from1 => {
2905
        date => sub { $_[0] . 'd' }
2906
    },
2907
    from2 => {
2908
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2909
    }
2910
);
2911
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2912
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2913
$result->filter(key1 => sub { $_[0] . 'f' });
2914
is($result->fetch_first->[0], '1abcdef');
2915

            
2916
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2917
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2918
$dbi->type_rule(
2919
    from1 => {
2920
        date => sub { $_[0] . 'p' }
2921
    },
2922
    from2 => {
2923
        date => sub { $_[0] . 'q' }
2924
    },
2925
);
2926
$dbi->insert({key1 => '1'}, table => 'table1');
2927
$result = $dbi->select(table => 'table1');
2928
$result->type_rule(
2929
    from1 => {
2930
        date => sub { $_[0] . 'd' }
2931
    },
2932
    from2 => {
2933
        date => sub { $_[0] . 'e' }
2934
    }
2935
);
2936
$result->filter(key1 => sub { $_[0] . 'f' });
2937
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2938

            
2939
test 'type_rule_off';
2940
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2941
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2942
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2943
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2944
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2945
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2946
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2947
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2948
    }
2949
);
2950
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2951
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2952
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2953

            
2954
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2955
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2956
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2957
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2958
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2959
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2960
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2961
        date => sub { $_[0] * 3 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2962
    }
2963
);
2964
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2965
$result = $dbi->select(table => 'table1', type_rule_off => 1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2966
is($result->one->{key1}, 4);
2967

            
2968
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2969
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2970
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2971
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2972
        date => sub { $_[0] * 2 },
2973
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2974
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2975
        date => sub { $_[0] * 3 },
2976
    }
2977
);
2978
$dbi->insert({key1 => 2}, table => 'table1');
2979
$result = $dbi->select(table => 'table1');
2980
is($result->one->{key1}, 12);
2981

            
2982
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2983
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2984
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2985
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2986
        date => sub { $_[0] * 2 },
2987
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2988
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2989
        date => sub { $_[0] * 3 },
2990
    }
2991
);
2992
$dbi->insert({key1 => 2}, table => 'table1');
2993
$result = $dbi->select(table => 'table1');
2994
is($result->fetch->[0], 12);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2995

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2996
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2997
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2998
$dbi->register_filter(ppp => sub { uc $_[0] });
2999
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3000
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3001
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3002
    }
3003
);
3004
$dbi->insert({key1 => 'a'}, table => 'table1');
3005
$result = $dbi->select(table => 'table1');
3006
is($result->one->{key1}, 'A');
3007

            
3008
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3009
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3010
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3011
    }
3012
)};
3013
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3014

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3015
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3016
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3017
eval {
3018
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3019
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3020
            Date => sub { $_[0] * 2 },
3021
        }
3022
    );
3023
};
3024
like($@, qr/lower/);
3025

            
3026
eval {
3027
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3028
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3029
            Date => sub { $_[0] * 2 },
3030
        }
3031
    );
3032
};
3033
like($@, qr/lower/);
3034

            
3035
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3036
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3037
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3038
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3039
        date => sub { $_[0] * 2 },
3040
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3041
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3042
        date => sub { $_[0] * 3 },
3043
    }
3044
);
3045
$dbi->insert({key1 => 2}, table => 'table1');
3046
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3047
$result->type_rule_off;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3048
is($result->one->{key1}, 6);
3049

            
3050
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3051
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3052
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3053
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3054
        date => sub { $_[0] * 2 },
3055
        datetime => sub { $_[0] * 4 },
3056
    },
3057
);
3058
$dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3059
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3060
$result->type_rule(
3061
    from1 => {
3062
        date => sub { $_[0] * 3 }
3063
    }
3064
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3065
$row = $result->one;
3066
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3067
is($row->{key2}, 2);
3068

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3069
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3070
$result->type_rule(
3071
    from1 => {
3072
        date => sub { $_[0] * 3 }
3073
    }
3074
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3075
$row = $result->one;
3076
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3077
is($row->{key2}, 2);
3078

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3079
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3080
$result->type_rule(
3081
    from1 => {
3082
        date => sub { $_[0] * 3 }
3083
    }
3084
);
cleanup
Yuki Kimoto authored on 2011-06-15
3085
$row = $result->one;
3086
is($row->{key1}, 6);
3087
is($row->{key2}, 2);
3088
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3089
$result->type_rule(
3090
    from1 => [date => sub { $_[0] * 3 }]
3091
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3092
$row = $result->one;
3093
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3094
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3095
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3096
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3097
$result->type_rule(
3098
    from1 => [date => 'fivetimes']
3099
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3100
$row = $result->one;
3101
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3102
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3103
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3104
$result->type_rule(
3105
    from1 => [date => undef]
3106
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3107
$row = $result->one;
3108
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3109
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3110

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3111
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3112
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3113
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3114
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3115
        date => sub { $_[0] * 2 },
3116
    },
3117
);
3118
$dbi->insert({key1 => 2}, table => 'table1');
3119
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3120
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3121
is($result->one->{key1}, 12);
3122

            
3123
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3124
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3125
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3126
    from1 => {
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3127
        date => sub { $_[0] * 2 },
3128
    },
3129
);
3130
$dbi->insert({key1 => 2}, table => 'table1');
3131
$result = $dbi->select(table => 'table1');
3132
$result->filter(key1 => sub { $_[0] * 3 });
3133
is($result->fetch->[0], 12);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3134

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3135
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3136
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3137
$dbi->type_rule(
3138
    into1 => {
3139
        date => sub { $_[0] . 'b' }
3140
    },
3141
    into2 => {
3142
        date => sub { $_[0] . 'c' }
3143
    },
3144
    from1 => {
3145
        date => sub { $_[0] . 'd' }
3146
    },
3147
    from2 => {
3148
        date => sub { $_[0] . 'e' }
3149
    }
3150
);
3151
$dbi->insert({key1 => '1'}, table => 'table1', type_rule_off => 1);
3152
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3153
is($result->type_rule_off->fetch_first->[0], '1');
3154
$result = $dbi->select(table => 'table1');
3155
is($result->type_rule_on->fetch_first->[0], '1de');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3156

            
3157
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3158
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3159
$dbi->type_rule(
3160
    into1 => {
3161
        date => sub { $_[0] . 'b' }
3162
    },
3163
    into2 => {
3164
        date => sub { $_[0] . 'c' }
3165
    },
3166
    from1 => {
3167
        date => sub { $_[0] . 'd' }
3168
    },
3169
    from2 => {
3170
        date => sub { $_[0] . 'e' }
3171
    }
3172
);
3173
$dbi->insert({key1 => '1'}, table => 'table1', type_rule1_off => 1);
3174
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3175
is($result->type_rule1_off->fetch_first->[0], '1ce');
3176
$result = $dbi->select(table => 'table1');
3177
is($result->type_rule1_on->fetch_first->[0], '1cde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3178

            
3179
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3180
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3181
$dbi->type_rule(
3182
    into1 => {
3183
        date => sub { $_[0] . 'b' }
3184
    },
3185
    into2 => {
3186
        date => sub { $_[0] . 'c' }
3187
    },
3188
    from1 => {
3189
        date => sub { $_[0] . 'd' }
3190
    },
3191
    from2 => {
3192
        date => sub { $_[0] . 'e' }
3193
    }
3194
);
3195
$dbi->insert({key1 => '1'}, table => 'table1', type_rule2_off => 1);
3196
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3197
is($result->type_rule2_off->fetch_first->[0], '1bd');
3198
$result = $dbi->select(table => 'table1');
3199
is($result->type_rule2_on->fetch_first->[0], '1bde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3200

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3201
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3202
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3203
$dbi->execute($CREATE_TABLE->{0});
3204
$dbi->execute($CREATE_TABLE->{2});
3205

            
3206
$dbi->create_model(
3207
    table => 'table1',
3208
    join => [
3209
       'left outer join table2 on table1.key1 = table2.key1'
3210
    ],
3211
    primary_key => ['key1'],
3212
);
3213
$model2 = $dbi->create_model(
3214
    table => 'table2',
3215
);
3216
$dbi->setup_model;
3217
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3218
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3219
$model = $dbi->model('table1');
3220
$result = $model->select(
3221
    column => [
3222
        $model->mycolumn,
3223
        {table2 => [qw/key1 key3/]}
3224
    ],
3225
    where => {'table1.key1' => 1}
3226
);
3227
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3228
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3229
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3230

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3231
$dbi->separator('__');
3232
$model = $dbi->model('table1');
3233
$result = $model->select(
3234
    column => [
3235
        $model->mycolumn,
3236
        {table2 => [qw/key1 key3/]}
3237
    ],
3238
    where => {'table1.key1' => 1}
3239
);
3240
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3241
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3242
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3243

            
cleanup
Yuki Kimoto authored on 2011-06-13
3244
$dbi->separator('-');
3245
$model = $dbi->model('table1');
3246
$result = $model->select(
3247
    column => [
3248
        $model->mycolumn,
3249
        {table2 => [qw/key1 key3/]}
3250
    ],
3251
    where => {'table1.key1' => 1}
3252
);
3253
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3254
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3255
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3256

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3257

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3258
test 'filter_off';
3259
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3260
$dbi->execute($CREATE_TABLE->{0});
3261
$dbi->execute($CREATE_TABLE->{2});
3262

            
3263
$dbi->create_model(
3264
    table => 'table1',
3265
    join => [
3266
       'left outer join table2 on table1.key1 = table2.key1'
3267
    ],
3268
    primary_key => ['key1'],
3269
);
3270
$dbi->setup_model;
3271
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3272
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3273
$result = $model->select(column => 'key1');
3274
$result->filter(key1 => sub { $_[0] * 2 });
3275
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3276

            
3277
test 'available_date_type';
3278
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3279
ok($dbi->can('available_data_type'));
3280

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3281

            
3282
test 'select prefix option';
3283
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3284
$dbi->execute($CREATE_TABLE->{0});
3285
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3286
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3287
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3288

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
3289

            
3290
test 'separator';
3291
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3292
is($dbi->separator, '.');
3293
$dbi->separator('-');
3294
is($dbi->separator, '-');
3295
$dbi->separator('__');
3296
is($dbi->separator, '__');
3297
eval { $dbi->separator('?') };
3298
like($@, qr/Separator/);
3299

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
3300

            
3301
test 'map_param';
3302
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3303
$param = $dbi->map_param(
3304
    {id => 1, author => 'Ken', price => 1900},
3305
    id => 'book.id',
3306
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3307
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3308
);
3309
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3310
  'book.price' => 1900});
3311

            
3312
$param = $dbi->map_param(
3313
    {id => 0, author => 0, price => 0},
3314
    id => 'book.id',
3315
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3316
    price => ['book.price', sub { '%' . $_[0] . '%' },
3317
      {if => sub { $_[0] eq 0 }}]
3318
);
3319
is_deeply($param, {'book.id' => 0, 'book.author' => '%0%', 'book.price' => '%0%'});
3320

            
3321
$param = $dbi->map_param(
3322
    {id => '', author => '', price => ''},
3323
    id => 'book.id',
3324
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3325
    price => ['book.price', sub { '%' . $_[0] . '%' },
3326
      {if => sub { $_[0] eq 1 }}]
3327
);
3328
is_deeply($param, {});
3329

            
3330
$param = $dbi->map_param(
3331
    {id => undef, author => undef, price => undef},
3332
    id => 'book.id',
3333
    price => ['book.price', {if => 'exists'}]
3334
);
3335
is_deeply($param, {'book.price' => undef});
3336

            
3337
$param = $dbi->map_param(
3338
    {price => 'a'},
3339
    id => ['book.id', {if => 'exists'}],
3340
    price => ['book.price', sub { '%' . $_[0] }, {if => 'exists'}]
3341
);
3342
is_deeply($param, {'book.price' => '%a'});
3343

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
3344

            
3345
test 'table_alias';
3346
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3347
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3348
$dbi->type_rule(
3349
    into1 => {
3350
        date => sub { uc $_[0] }
3351
    }
3352
);
3353
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3354
  table_alias => {table2 => 'table1'});
3355
$result = $dbi->select(table => 'table1');
3356
is($result->one->{key1}, 'A');
3357

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3358

            
3359
test 'order';
3360
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3361
{
3362
    $dbi->execute("create table table1 (key1, key2)");
3363
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3364
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3365
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3366
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3367
    my $order = $dbi->order;
3368
    $order->prepend('key1', 'key2 desc');
3369
    $result = $dbi->select(table => 'table1', append => "$order");
3370
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3371
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3372
    $order->prepend('key1 desc');
3373
    $result = $dbi->select(table => 'table1', append => "$order");
3374
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3375
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
added DBIx::Cusotm::Order pr...
Yuki Kimoto authored on 2011-07-11
3376

            
3377
    $order = $dbi->order;
3378
    $order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
3379
    $result = $dbi->select(table => 'table1',
3380
      column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
3381
      append => "$order");
3382
    is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
3383
      {'table1-key1' => 1, 'table1-key2' => 1},
3384
      {'table1-key1' => 2, 'table1-key2' => 4},
3385
      {'table1-key1' => 2, 'table1-key2' => 2}]);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3386
}
3387

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3388
test 'tag_parse';
3389
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3390
$dbi->tag_parse(0);
3391
{
3392
    $dbi->execute("create table table1 (key1, key2)");
3393
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3394
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3395
    ok($@);
3396
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3397

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3398
test 'last_sql';
3399
{
3400
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3401
    $dbi->execute("create table table1 (key1, key2)");
3402
    $dbi->execute('select * from table1');
3403
    is($dbi->last_sql, 'select * from table1;');
3404
    
3405
    eval{$dbi->execute("aaa")};
3406
    is($dbi->last_sql, 'aaa;');
3407
    
3408
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3409

            
3410
test 'DBIx::Custom header';
3411
{
3412
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3413
    $dbi->execute("create table table1 (key1, key2)");
3414
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3415
    
3416
    is_deeply($result->header, [qw/h1 h2/]);
3417
    
3418
}
3419

            
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
3420
test 'parameter :name(operater) syntax';
3421
$dbi->execute($DROP_TABLE->{0});
3422
$dbi->execute($CREATE_TABLE->{1});
3423
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
3424
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
3425

            
3426
$source = "select * from table1 where :key1{=} and :key2{=}";
3427
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
3428
$rows = $result->all;
3429
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3430

            
3431
$source = "select * from table1 where :key1{ = } and :key2{=}";
3432
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
3433
$rows = $result->all;
3434
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3435

            
3436
$source = "select * from table1 where :key1{<} and :key2{=}";
3437
$result = $dbi->execute($source, param => {key1 => 5, key2 => 2});
3438
$rows = $result->all;
3439
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3440

            
3441
$source = "select * from table1 where :table1.key1{=} and :table1.key2{=}";
3442
$result = $dbi->execute(
3443
    $source,
3444
    param => {'table1.key1' => 1, 'table1.key2' => 1},
3445
    filter => {'table1.key2' => sub { $_[0] * 2 }}
3446
);
3447
$rows = $result->all;
3448
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3449

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3450
=cut