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

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
310
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
311
$dbi->execute($CREATE_TABLE->{0});
312
$dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
313
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
314
$result = $dbi->execute($SELECT_SOURCES->{0});
315
$rows   = $result->all;
316
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
317

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

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

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

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

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

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

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

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

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

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

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

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

            
418
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
419
like($@, qr/safety/);
420

            
421
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
422
$dbi->reserved_word_quote('"');
423
$dbi->execute('create table "table" ("select", "update")');
424
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
425
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
426
$dbi->insert(table => 'table', param => {select => 1});
427
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
428
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
429
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
430
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
431

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
443
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
444
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
445
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
446
$dbi->update(table => 'table1', param => {key2 => 4},
447
  where => {key1 => 1}, prefix => 'or replace');
448
$result = $dbi->execute($SELECT_SOURCES->{0});
449
$rows   = $result->all;
450
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
451

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
452
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
453
$dbi->execute($CREATE_TABLE->{1});
454
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
455
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
456
$dbi->update(table => 'table1', param => {key2 => \"'11'"}, where => {key1 => 1});
457
$result = $dbi->execute($SELECT_SOURCES->{0});
458
$rows   = $result->all;
459
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
460
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
461
                  "basic");
462

            
removed register_format()
yuki-kimoto authored on 2010-05-26
463
test 'update_all';
464
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
465
$dbi->execute($CREATE_TABLE->{1});
466
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
467
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
468
$dbi->register_filter(twice => sub { $_[0] * 2 });
469
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
470
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
471
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
472
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
473
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
474
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
475

            
476

            
477
test 'delete';
478
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
479
$dbi->execute($CREATE_TABLE->{0});
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});
add tests
yuki-kimoto authored on 2010-08-10
483
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
484
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
485
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
486

            
487
$dbi->execute("delete from table1;");
488
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
489
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
490
$dbi->register_filter(twice => sub { $_[0] * 2 });
491
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
492
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
493
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
494
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
495

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

            
498
$dbi->delete_all(table => 'table1');
499
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
500
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
501
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
502
$rows = $dbi->select(table => 'table1')->all;
cleanup
Yuki Kimoto authored on 2011-01-23
503
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
504

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
508
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
509
$dbi->execute($CREATE_TABLE->{0});
510
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
511
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
512
$where = $dbi->where;
updated pod
Yuki Kimoto authored on 2011-06-21
513
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
514
$where->param({ke1 => 1, key2 => 2});
515
$dbi->delete(table => 'table1', where => $where);
516
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
517
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
518

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
519
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
520
$dbi->execute($CREATE_TABLE->{0});
521
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
522
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
523
$dbi->delete(
524
    table => 'table1',
525
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
526
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
527
        {ke1 => 1, key2 => 2}
528
    ]
529
);
530
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
531
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
532

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
533
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
534
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
535
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
536
$dbi->delete(table => 'table1', where => {key1 => 1}, prefix => '    ');
537
$result = $dbi->execute($SELECT_SOURCES->{0});
538
$rows   = $result->all;
539
is_deeply($rows, [], "basic");
540

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
551
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
552
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
553
$dbi->execute('create table "table" ("select", "update")');
554
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
555
$dbi->insert(table => 'table', param => {select => 1});
556
$dbi->delete(table => 'table', where => {select => 1});
557
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
558
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
559
is_deeply($rows, [], "reserved word");
560

            
removed register_format()
yuki-kimoto authored on 2010-05-26
561
test 'delete_all';
562
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
563
$dbi->execute($CREATE_TABLE->{0});
564
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
565
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
566
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
567
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
568
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
569
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
570

            
571

            
572
test 'select';
573
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
574
$dbi->execute($CREATE_TABLE->{0});
575
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
576
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
577
$rows = $dbi->select(table => 'table1')->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
578
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
579
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
580

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

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

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

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

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

            
598
$dbi->execute($CREATE_TABLE->{2});
599
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
600
$rows = $dbi->select(
601
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
602
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
603
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
604
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
605
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
606
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
607

            
608
$rows = $dbi->select(
609
    table => [qw/table1 table2/],
610
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
611
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
612
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
613
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
614

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
618
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
619
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
620
$dbi->execute('create table "table" ("select", "update")');
621
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
622
$dbi->insert(table => 'table', param => {select => 1, update => 2});
623
$result = $dbi->select(table => 'table', where => {select => 1});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
624
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
625
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
626

            
removed register_format()
yuki-kimoto authored on 2010-05-26
627
test 'fetch filter';
628
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
629
$dbi->register_filter(
630
    twice       => sub { $_[0] * 2 },
631
    three_times => sub { $_[0] * 3 }
632
);
633
$dbi->default_fetch_filter('twice');
634
$dbi->execute($CREATE_TABLE->{0});
635
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
636
$result = $dbi->select(table => 'table1');
637
$result->filter({key1 => 'three_times'});
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
638
$row = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
639
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
640

            
641
test 'filters';
642
$dbi = DBIx::Custom->new;
643

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
650
test 'transaction';
651
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
652
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
653
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
654
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
655
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
656
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
657
$result = $dbi->select(table => 'table1');
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
658
is_deeply(scalar $result->all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
659
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
660

            
661
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
662
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
663
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
664
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
665
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
666

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

            
670
test 'cache';
671
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
672
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
673
$dbi->execute($CREATE_TABLE->{0});
updated pod
Yuki Kimoto authored on 2011-06-21
674
$source = 'select * from table1 where key1 = :key1 and key2 = :key2;';
675
$dbi->execute($source, {}, query => 1);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
676
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
677
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
678

            
679
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
680
$dbi->execute($CREATE_TABLE->{0});
681
$dbi->{_cached} = {};
682
$dbi->cache(0);
683
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
684
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
685

            
add tests
yuki-kimoto authored on 2010-08-10
686
test 'execute';
687
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
688
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
689
{
690
    local $Carp::Verbose = 0;
691
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
692
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
693
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
694
}
695
{
696
    local $Carp::Verbose = 1;
697
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
698
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
699
}
add tests
yuki-kimoto authored on 2010-08-10
700

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
709
{
710
    local $Carp::Verbose = 0;
updated pod
Yuki Kimoto authored on 2011-06-21
711
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
712
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
713
}
714
{
715
    local $Carp::Verbose = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
716
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
717
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
718
}
cleanup
yuki-kimoto authored on 2010-10-17
719

            
720

            
721
test 'transaction';
722
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
723
$dbi->execute($CREATE_TABLE->{0});
724

            
725
$dbi->begin_work;
726

            
727
eval {
728
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
729
    die "Error";
730
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
731
};
732

            
733
$dbi->rollback if $@;
734

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

            
739
$dbi->begin_work;
740

            
741
eval {
742
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
743
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
744
};
745

            
746
$dbi->commit unless $@;
747

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

            
752
$dbi->dbh->{AutoCommit} = 0;
753
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
754
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
755
$dbi->dbh->{AutoCommit} = 1;
756

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
758
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
759
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
760
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
761
    one => sub { 1 }
762
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
763
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
764
    two => sub { 2 }
765
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
766
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
767
    twice => sub {
768
        my $self = shift;
769
        return $_[0] * 2;
770
    }
771
});
772

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
780
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
781
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
782
$dbi->execute($CREATE_TABLE->{0});
783
$dbi->register_filter(twice => sub { $_[0] * 2 });
784
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
785
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
786
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
787
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
788
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
789
$result = $dbi->execute($SELECT_SOURCES->{0});
790
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
791
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
792
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
793
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
794
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
795

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
796
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
797
$dbi->execute($CREATE_TABLE->{0});
798
$dbi->register_filter(twice => sub { $_[0] * 2 });
799
$dbi->register_filter(three_times => sub { $_[0] * 3});
800
$dbi->apply_filter(
801
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
802
              'key2' => {out => 'three_times', in => 'twice'});
803
$dbi->apply_filter(
804
    'table1', 'key1' => {out => undef}
805
); 
806
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
807
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
808
$row   = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
809
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
810

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
811
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
812
$dbi->execute($CREATE_TABLE->{0});
813
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
814
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
815
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
816
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
817
$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
818
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
819
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
820
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
821
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
822

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

            
835
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
836
$dbi->execute($CREATE_TABLE->{0});
837
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
838
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
839
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
840
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
841
$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
842
$result = $dbi->select(table => 'table1', where => {key1 => 1});
843
$result->filter({'key2' => 'twice'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
844
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
845
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
846

            
847
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
848
$dbi->execute($CREATE_TABLE->{0});
849
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
850
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
851
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
852
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
853
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
854
$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
855
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
856
                        table => ['table1']);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
857
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
858
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
859

            
add table tag
Yuki Kimoto authored on 2011-02-09
860
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
861
$dbi->execute($CREATE_TABLE->{0});
862
$dbi->register_filter(twice => sub { $_[0] * 2 });
863
$dbi->apply_filter(
864
    'table1', 'key1' => {out => 'twice', in => 'twice'}
865
);
866
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
867
$result = $dbi->execute("select * from {table table1} where key1 = :key1 and key2 = :key2;",
add table tag
Yuki Kimoto authored on 2011-02-09
868
                        param => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
869
$rows   = $result->all;
add table tag
Yuki Kimoto authored on 2011-02-09
870
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
871

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
872
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
873
$dbi->execute($CREATE_TABLE->{0});
874
$dbi->execute($CREATE_TABLE->{2});
875
$dbi->register_filter(twice => sub { $_[0] * 2 });
876
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
877
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
878
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
879
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
880
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
881
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
882
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
883
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
884
$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
885
$result = $dbi->select(
886
     table => ['table1', 'table2'],
887
     column => ['key2', 'key3'],
888
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
889

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

            
894
$result = $dbi->select(
895
     table => ['table1', 'table2'],
896
     column => ['key2', 'key3'],
897
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
898

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
903
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
904
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
905
$dbi->execute($CREATE_TABLE->{2});
906
$dbi->execute($CREATE_TABLE->{3});
907

            
908
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
909
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
910
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
911
    
912
    if ($table =~ /^table/) {
913
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
914
         push @$infos, $info;
915
    }
916
});
917
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
918
is_deeply($infos, 
919
    [
920
        ['table1', 'key1', 'key1'],
921
        ['table1', 'key2', 'key2'],
922
        ['table2', 'key1', 'key1'],
923
        ['table2', 'key3', 'key3']
924
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
925
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
926
);
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
927
test 'each_table';
928
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
929
$dbi->execute($CREATE_TABLE->{2});
930
$dbi->execute($CREATE_TABLE->{3});
931

            
932
$infos = [];
933
$dbi->each_table(sub {
934
    my ($self, $table, $table_info) = @_;
935
    
936
    if ($table =~ /^table/) {
937
         my $info = [$table, $table_info->{TABLE_NAME}];
938
         push @$infos, $info;
939
    }
940
});
941
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
942
is_deeply($infos, 
943
    [
944
        ['table1', 'table1'],
945
        ['table2', 'table2'],
946
    ]
947
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
948

            
add examples
Yuki Kimoto authored on 2011-01-07
949
test 'limit';
950
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
951
$dbi->execute($CREATE_TABLE->{0});
952
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
953
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
954
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
955
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
956
    limit => sub {
957
        my ($count, $offset) = @_;
958
        
959
        my $s = '';
960
        $s .= "limit $count";
961
        $s .= " offset $offset" if defined $offset;
962
        
963
        return [$s, []];
964
    }
965
);
966
$rows = $dbi->select(
967
  table => 'table1',
968
  where => {key1 => 1},
969
  append => "order by key2 {limit 1 0}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
970
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
971
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
972
$rows = $dbi->select(
973
  table => 'table1',
974
  where => {key1 => 1},
975
  append => "order by key2 {limit 2 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
976
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
977
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
978
$rows = $dbi->select(
979
  table => 'table1',
980
  where => {key1 => 1},
981
  append => "order by key2 {limit 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
982
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
983
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
984

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
985
test 'connect super';
986
{
987
    package MyDBI;
988
    
989
    use base 'DBIx::Custom';
990
    sub connect {
991
        my $self = shift->SUPER::connect(@_);
992
        
993
        return $self;
994
    }
995
    
996
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
997
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
998
        
999
        return $self;
1000
    }
1001
}
1002

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1014
{
1015
    package MyDBI2;
1016
    
1017
    use base 'DBIx::Custom';
1018
    sub connect {
1019
        my $self = shift->SUPER::new(@_);
1020
        $self->connect;
1021
        
1022
        return $self;
1023
    }
1024
}
1025

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

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

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1041
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1042
$dbi->execute($CREATE_TABLE->{0});
1043
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1044
$result = $dbi->select(table => 'table1');
1045
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
1046
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
1047
$row = $result->fetch_first;
1048
is_deeply($row, [6, 12]);
1049

            
1050
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1051
$dbi->execute($CREATE_TABLE->{0});
1052
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1053
$result = $dbi->select(table => 'table1');
1054
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
1055
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
1056
$row = $result->fetch_first;
1057
is_deeply($row, [6, 12]);
1058

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1066
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1067
$dbi->apply_filter('table1',
1068
    key1 => {end => sub { $_[0] * 3 } },
1069
    key2 => {end => 'five_times'}
1070
);
1071
$result = $dbi->select(table => 'table1');
1072
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
added tests
Yuki Kimoto authored on 2011-06-08
1073
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1074
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
1075

            
1076
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1077
$dbi->apply_filter('table1',
1078
    key1 => {end => sub { $_[0] * 3 } },
1079
    key2 => {end => 'five_times'}
1080
);
1081
$result = $dbi->select(table => 'table1');
1082
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1083
$result->filter(key1 => undef);
1084
$result->end_filter(key1 => undef);
added tests
Yuki Kimoto authored on 2011-06-08
1085
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1086
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1087

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1088
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1089
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1090
$dbi->execute($CREATE_TABLE->{0});
1091
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1092
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1093
$row = $result
1094
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1095
       ->remove_filter
1096
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1097
       ->remove_end_filter
1098
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1099
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1100

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1101
test 'empty where select';
1102
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1103
$dbi->execute($CREATE_TABLE->{0});
1104
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1105
$result = $dbi->select(table => 'table1', where => {});
added tests
Yuki Kimoto authored on 2011-06-08
1106
$row = $result->one;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1107
is_deeply($row, {key1 => 1, key2 => 2});
1108

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1109
test 'select query option';
1110
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1111
$dbi->execute($CREATE_TABLE->{0});
1112
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1113
is(ref $query, 'DBIx::Custom::Query');
1114
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1115
is(ref $query, 'DBIx::Custom::Query');
1116
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1117
is(ref $query, 'DBIx::Custom::Query');
1118
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1119
is(ref $query, 'DBIx::Custom::Query');
1120

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1121
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1122
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1123
$dbi->execute($CREATE_TABLE->{0});
1124
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1125
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
updated pod
Yuki Kimoto authored on 2011-06-21
1126
$where = $dbi->where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
1127
is("$where", "where ( key1 = :key1 and key2 = :key2 )", 'no param');
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1128

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

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1140
$result = $dbi->select(
1141
    table => 'table1',
1142
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
1143
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1144
        {key1 => 1}
1145
    ]
1146
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1147
$row = $result->all;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1148
is_deeply($row, [{key1 => 1, key2 => 2}]);
1149

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

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

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1170
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-07
1171
             ->clause(['and', ['or', 'key1 > :key1', 'key1 < :key1'], 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1172
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1173
$result = $dbi->select(
1174
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1175
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1176
); 
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1177
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1178
is_deeply($row, [{key1 => 1, key2 => 2}]);
1179

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1180
$where = $dbi->where;
1181
$result = $dbi->select(
1182
    table => 'table1',
1183
    where => $where
1184
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1185
$row = $result->all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1186
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1187

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1188
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1189
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1190
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1191
$result = $dbi->select(
1192
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1193
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1194
);
1195
};
1196
ok($@);
1197

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

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

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

            
1221
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1222
             ->clause(['or', ('key1 = :key1') x 2])
added test
Yuki Kimoto authored on 2011-01-19
1223
             ->param({key1 => 1});
1224
$result = $dbi->select(
1225
    table => 'table1',
1226
    where => $where,
1227
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1228
$row = $result->all;
added test
Yuki Kimoto authored on 2011-01-19
1229
is_deeply($row, [{key1 => 1, key2 => 2}]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1230

            
many changed
Yuki Kimoto authored on 2011-01-23
1231
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1232
             ->clause('key1 = :key1')
many changed
Yuki Kimoto authored on 2011-01-23
1233
             ->param({key1 => 1});
1234
$result = $dbi->select(
1235
    table => 'table1',
1236
    where => $where,
1237
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1238
$row = $result->all;
many changed
Yuki Kimoto authored on 2011-01-23
1239
is_deeply($row, [{key1 => 1, key2 => 2}]);
1240

            
1241
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1242
             ->clause('key1 = :key1 key2 = :key2')
many changed
Yuki Kimoto authored on 2011-01-23
1243
             ->param({key1 => 1});
1244
eval{$where->to_string};
1245
like($@, qr/one column/);
1246

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1247
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1248
             ->clause('key1 = :key1')
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1249
             ->param([]);
1250
eval{$where->to_string};
1251
like($@, qr/Parameter/);
1252

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

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

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

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

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

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

            
1313
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1314
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1315
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1316
$result = $dbi->select(
1317
    table => 'table1',
1318
    where => $where,
1319
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1320
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1321
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1322

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

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

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

            
1353
$where = $dbi->where
1354
             ->clause(['and', '{> key1}', '{< key1}' ])
1355
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
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;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1361
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1362

            
1363
$where = $dbi->where
1364
             ->clause(['and', '{> key1}', '{< key1}' ])
1365
             ->param({key1 => [0, 2]});
1366
$result = $dbi->select(
1367
    table => 'table1',
1368
    where => $where,
1369
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1370
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1371
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1372

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1373
$where = $dbi->where
1374
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1375
$result = $dbi->select(
1376
    table => 'table1',
1377
    where => $where,
1378
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1379
$row = $result->all;
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1380
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1381

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

            
fixed DBIx::Custom::Where to...
Yuki Kimoto authored on 2011-06-27
1385
$where = $dbi->where(
1386
    clause => ['and', ['or'], ['and', 'key1 = :key1', 'key2 = :key2']],
1387
    param => {key1 => 1, key2 => 2}
1388
);
1389
$result = $dbi->select(
1390
    table => 'table1',
1391
    where => $where,
1392
);
1393
$row = $result->all;
1394
is_deeply($row, [{key1 => 1, key2 => 2}]);
1395

            
1396

            
1397
$where = $dbi->where(
1398
    clause => ['and', ['or'], ['or', ':key1', ':key2']],
1399
    param => {}
1400
);
1401
$result = $dbi->select(
1402
    table => 'table1',
1403
    where => $where,
1404
);
1405
$row = $result->all;
1406
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1407

            
1408

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1413
test 'register_tag_processor';
1414
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1415
$dbi->register_tag_processor(
1416
    a => sub { 1 }
1417
);
1418
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1419

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1420
test 'register_tag';
1421
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1422
$dbi->register_tag(
1423
    b => sub { 2 }
1424
);
1425
is($dbi->query_builder->tags->{b}->(), 2);
1426

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1427
test 'table not specify exception';
1428
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1429
eval {$dbi->insert};
1430
like($@, qr/table/);
1431
eval {$dbi->update};
1432
like($@, qr/table/);
1433
eval {$dbi->delete};
1434
like($@, qr/table/);
1435
eval {$dbi->select};
1436
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1437

            
1438

            
1439
test 'more tests';
1440
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1441
eval{$dbi->apply_filter('table', 'column', [])};
1442
like($@, qr/apply_filter/);
1443

            
1444
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1445
like($@, qr/apply_filter/);
1446

            
1447
$dbi->apply_filter(
1448

            
1449
);
1450
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1451
$dbi->execute($CREATE_TABLE->{0});
1452
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1453
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1454
$dbi->apply_filter('table1', 'key2', 
1455
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1456
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1457
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1458

            
1459
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1460
$dbi->execute($CREATE_TABLE->{0});
1461
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1462
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1463
$dbi->apply_filter('table1', 'key2', {});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1464
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1465
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1466

            
1467
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1468
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1469
like($@, qr/not registered/);
1470
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1471
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1472
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1473
is($dbi->one, 1);
1474

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

            
1478
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1479
$dbi->execute($CREATE_TABLE->{0});
1480
$dbi->register_filter(twice => sub { $_[0] * 2 });
1481
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1482
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1483
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1484
is_deeply($row, {key1 => 2, key2 => 2});
1485
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1486
             filter => {key1 => 'no'}) };
1487
like($@, qr//);
1488

            
1489
$dbi->register_filter(one => sub { });
1490
$dbi->default_fetch_filter('one');
1491
ok($dbi->default_fetch_filter);
1492
$dbi->default_bind_filter('one');
1493
ok($dbi->default_bind_filter);
1494
eval{$dbi->default_fetch_filter('no')};
1495
like($@, qr/not registered/);
1496
eval{$dbi->default_bind_filter('no')};
1497
like($@, qr/not registered/);
1498
$dbi->default_bind_filter(undef);
1499
ok(!defined $dbi->default_bind_filter);
1500
$dbi->default_fetch_filter(undef);
1501
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1502
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1503
like($@, qr/Tag not finished/);
1504

            
1505
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1506
$dbi->execute($CREATE_TABLE->{0});
1507
$dbi->register_filter(one => sub { 1 });
1508
$result = $dbi->select(table => 'table1');
1509
eval {$result->filter(key1 => 'no')};
1510
like($@, qr/not registered/);
1511
eval {$result->end_filter(key1 => 'no')};
1512
like($@, qr/not registered/);
1513
$result->default_filter(undef);
1514
ok(!defined $result->default_filter);
1515
$result->default_filter('one');
1516
is($result->default_filter->(), 1);
1517

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1518
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1519
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1520
                             dbi_option => {PrintError => 1});
1521
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1522
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1523
                             dbi_options => {PrintError => 1});
1524
ok($dbi->dbh->{PrintError});
1525

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1526
test 'DBIx::Custom::Result stash()';
1527
$result = DBIx::Custom::Result->new;
1528
is_deeply($result->stash, {}, 'default');
1529
$result->stash->{foo} = 1;
1530
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1531

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1532
test 'filter __ expression';
1533
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1534
$dbi->execute('create table company (id, name, location_id)');
1535
$dbi->execute('create table location (id, name)');
1536
$dbi->apply_filter('location',
1537
  name => {in => sub { uc $_[0] } }
1538
);
1539

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

            
1543
$result = $dbi->select(
1544
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1545
    column => ['location.name as location__name']
1546
);
1547
is($result->fetch_first->[0], 'B');
1548

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1549
$result = $dbi->select(
1550
    table => 'company', relation => {'company.location_id' => 'location.id'},
1551
    column => ['location.name as location__name']
1552
);
1553
is($result->fetch_first->[0], 'B');
1554

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1555
$result = $dbi->select(
1556
    table => 'company', relation => {'company.location_id' => 'location.id'},
1557
    column => ['location.name as "location.name"']
1558
);
1559
is($result->fetch_first->[0], 'B');
1560

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1561
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1562
use MyDBI1;
1563
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1564
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1565
$model = $dbi->model('book');
1566
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1567
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1568
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1569
$model = $dbi->model('company');
1570
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1571
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1572
is($dbi->models->{'book'}, $dbi->model('book'));
1573
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1574

            
1575
{
1576
    package MyDBI4;
1577

            
1578
    use strict;
1579
    use warnings;
1580

            
1581
    use base 'DBIx::Custom';
1582

            
1583
    sub connect {
1584
        my $self = shift->SUPER::connect(@_);
1585
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1586
        $self->include_model(
1587
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1588
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1589
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1590
            ]
1591
        );
1592
    }
1593

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

            
1596
    use strict;
1597
    use warnings;
1598

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

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

            
1603
    use strict;
1604
    use warnings;
1605

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

            
1608
    sub insert {
1609
        my ($self, $param) = @_;
1610
        
1611
        return $self->SUPER::insert(param => $param);
1612
    }
1613

            
1614
    sub list { shift->select; }
1615

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

            
1618
    use strict;
1619
    use warnings;
1620

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

            
1623
    sub insert {
1624
        my ($self, $param) = @_;
1625
        
1626
        return $self->SUPER::insert(param => $param);
1627
    }
1628

            
1629
    sub list { shift->select; }
1630
}
1631
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1632
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1633
$model = $dbi->model('book');
1634
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1635
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1636
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1637
$model = $dbi->model('company');
1638
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1639
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1640

            
1641
{
1642
     package MyDBI5;
1643

            
1644
    use strict;
1645
    use warnings;
1646

            
1647
    use base 'DBIx::Custom';
1648

            
1649
    sub connect {
1650
        my $self = shift->SUPER::connect(@_);
1651
        
1652
        $self->include_model('MyModel4');
1653
    }
1654
}
1655
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1656
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1657
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1658
$model = $dbi->model('company');
1659
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1660
is_deeply($model->list->all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1661
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1662
$model = $dbi->model('book');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1663
is_deeply($model->list->all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1664

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1665
test 'primary_key';
1666
use MyDBI1;
1667
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1668
$model = $dbi->model('book');
1669
$model->primary_key(['id', 'number']);
1670
is_deeply($model->primary_key, ['id', 'number']);
1671

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1672
test 'columns';
1673
use MyDBI1;
1674
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1675
$model = $dbi->model('book');
1676
$model->columns(['id', 'number']);
1677
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1678

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1679
test 'setup_model';
1680
use MyDBI1;
1681
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1682
$dbi->execute('create table book (id)');
1683
$dbi->execute('create table company (id, name);');
1684
$dbi->execute('create table test (id, name, primary key (id, name));');
1685
$dbi->setup_model;
1686
is_deeply($dbi->model('book')->columns, ['id']);
1687
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1688

            
1689
test 'delete_at';
1690
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1691
$dbi->execute($CREATE_TABLE->{1});
1692
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1693
$dbi->delete_at(
1694
    table => 'table1',
1695
    primary_key => ['key1', 'key2'],
1696
    where => [1, 2],
1697
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1698
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1699

            
1700
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1701
$dbi->delete_at(
1702
    table => 'table1',
1703
    primary_key => 'key1',
1704
    where => 1,
1705
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1706
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1707

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1708
test 'insert_at';
1709
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1710
$dbi->execute($CREATE_TABLE->{1});
1711
$dbi->insert_at(
1712
    primary_key => ['key1', 'key2'], 
1713
    table => 'table1',
1714
    where => [1, 2],
1715
    param => {key3 => 3}
1716
);
added tests
Yuki Kimoto authored on 2011-06-08
1717
is($dbi->select(table => 'table1')->one->{key1}, 1);
1718
is($dbi->select(table => 'table1')->one->{key2}, 2);
1719
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1720

            
1721
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1722
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1723
$dbi->insert_at(
1724
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1725
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1726
    where => 1,
1727
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1728
);
1729

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

            
1734
eval {
1735
    $dbi->insert_at(
1736
        table => 'table1',
1737
        primary_key => ['key1', 'key2'],
1738
        where => {},
1739
        param => {key1 => 1, key2 => 2, key3 => 3},
1740
    );
1741
};
1742
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1743

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1744
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1745
$dbi->execute($CREATE_TABLE->{1});
1746
$dbi->insert_at(
1747
    {key3 => 3},
1748
    primary_key => ['key1', 'key2'], 
1749
    table => 'table1',
1750
    where => [1, 2],
1751
);
added tests
Yuki Kimoto authored on 2011-06-08
1752
is($dbi->select(table => 'table1')->one->{key1}, 1);
1753
is($dbi->select(table => 'table1')->one->{key2}, 2);
1754
is($dbi->select(table => 'table1')->one->{key3}, 3);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1755

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1756
test 'update_at';
1757
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1758
$dbi->execute($CREATE_TABLE->{1});
1759
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1760
$dbi->update_at(
1761
    table => 'table1',
1762
    primary_key => ['key1', 'key2'],
1763
    where => [1, 2],
1764
    param => {key3 => 4}
1765
);
added tests
Yuki Kimoto authored on 2011-06-08
1766
is($dbi->select(table => 'table1')->one->{key1}, 1);
1767
is($dbi->select(table => 'table1')->one->{key2}, 2);
1768
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1769

            
1770
$dbi->delete_all(table => 'table1');
1771
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1772
$dbi->update_at(
1773
    table => 'table1',
1774
    primary_key => 'key1',
1775
    where => 1,
1776
    param => {key3 => 4}
1777
);
added tests
Yuki Kimoto authored on 2011-06-08
1778
is($dbi->select(table => 'table1')->one->{key1}, 1);
1779
is($dbi->select(table => 'table1')->one->{key2}, 2);
1780
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1781

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1782
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1783
$dbi->execute($CREATE_TABLE->{1});
1784
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1785
$dbi->update_at(
1786
    {key3 => 4},
1787
    table => 'table1',
1788
    primary_key => ['key1', 'key2'],
1789
    where => [1, 2]
1790
);
added tests
Yuki Kimoto authored on 2011-06-08
1791
is($dbi->select(table => 'table1')->one->{key1}, 1);
1792
is($dbi->select(table => 'table1')->one->{key2}, 2);
1793
is($dbi->select(table => 'table1')->one->{key3}, 4);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1794

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1795
test 'select_at';
1796
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1797
$dbi->execute($CREATE_TABLE->{1});
1798
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1799
$result = $dbi->select_at(
1800
    table => 'table1',
1801
    primary_key => ['key1', 'key2'],
1802
    where => [1, 2]
1803
);
added tests
Yuki Kimoto authored on 2011-06-08
1804
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1805
is($row->{key1}, 1);
1806
is($row->{key2}, 2);
1807
is($row->{key3}, 3);
1808

            
1809
$dbi->delete_all(table => 'table1');
1810
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1811
$result = $dbi->select_at(
1812
    table => 'table1',
1813
    primary_key => 'key1',
1814
    where => 1,
1815
);
added tests
Yuki Kimoto authored on 2011-06-08
1816
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1817
is($row->{key1}, 1);
1818
is($row->{key2}, 2);
1819
is($row->{key3}, 3);
1820

            
1821
$dbi->delete_all(table => 'table1');
1822
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1823
$result = $dbi->select_at(
1824
    table => 'table1',
1825
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1826
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1827
);
added tests
Yuki Kimoto authored on 2011-06-08
1828
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1829
is($row->{key1}, 1);
1830
is($row->{key2}, 2);
1831
is($row->{key3}, 3);
1832

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

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1842
eval {
1843
    $result = $dbi->select_at(
1844
        table => 'table1',
1845
        primary_key => ['key1', 'key2'],
1846
        where => [1],
1847
    );
1848
};
1849
like($@, qr/same/);
1850

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1851
eval {
1852
    $result = $dbi->update_at(
1853
        table => 'table1',
1854
        primary_key => ['key1', 'key2'],
1855
        where => {},
1856
        param => {key1 => 1, key2 => 2},
1857
    );
1858
};
1859
like($@, qr/must be/);
1860

            
1861
eval {
1862
    $result = $dbi->delete_at(
1863
        table => 'table1',
1864
        primary_key => ['key1', 'key2'],
1865
        where => {},
1866
    );
1867
};
1868
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1869

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1870
test 'columns';
1871
use MyDBI1;
1872
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1873
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1874

            
1875

            
1876
test 'model delete_at';
1877
{
1878
    package MyDBI6;
1879
    
1880
    use base 'DBIx::Custom';
1881
    
1882
    sub connect {
1883
        my $self = shift->SUPER::connect(@_);
1884
        
1885
        $self->include_model('MyModel5');
1886
        
1887
        return $self;
1888
    }
1889
}
1890
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1891
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1892
$dbi->execute("create table table2 (key1, key2, key3)");
1893
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1894
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1895
$dbi->model('table1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1896
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1897
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1898
$dbi->model('table1_1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1899
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1900
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1901
$dbi->model('table1_3')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1902
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1903

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1904
test 'model insert_at';
1905
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1906
$dbi->execute($CREATE_TABLE->{1});
1907
$dbi->model('table1')->insert_at(
1908
    where => [1, 2],
1909
    param => {key3 => 3}
1910
);
1911
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1912
$row = $result->one;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1913
is($row->{key1}, 1);
1914
is($row->{key2}, 2);
1915
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1916

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1917
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1918
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1919
$dbi->execute($CREATE_TABLE->{1});
1920
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1921
$dbi->model('table1')->update_at(
1922
    where => [1, 2],
1923
    param => {key3 => 4}
1924
);
1925
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1926
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1927
is($row->{key1}, 1);
1928
is($row->{key2}, 2);
1929
is($row->{key3}, 4);
1930

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1931
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1932
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1933
$dbi->execute($CREATE_TABLE->{1});
1934
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1935
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1936
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1937
is($row->{key1}, 1);
1938
is($row->{key2}, 2);
1939
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1940

            
1941

            
cleanup
Yuki Kimoto authored on 2011-03-21
1942
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1943
{
1944
    package MyDBI7;
1945
    
1946
    use base 'DBIx::Custom';
1947
    
1948
    sub connect {
1949
        my $self = shift->SUPER::connect(@_);
1950
        
1951
        $self->include_model('MyModel6');
1952
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1953
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1954
        return $self;
1955
    }
1956
}
1957
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1958
$dbi->execute($CREATE_TABLE->{0});
1959
$dbi->execute($CREATE_TABLE->{2});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
1960
$dbi->separator('__');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1961
$dbi->setup_model;
1962
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1963
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1964
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1965
$result = $model->select(
1966
    column => [$model->mycolumn, $model->column('table2')],
1967
    where => {'table1.key1' => 1}
1968
);
added tests
Yuki Kimoto authored on 2011-06-08
1969
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1970
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1971

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1972
test 'update_param';
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
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};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1979
$update_param = $dbi->update_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1980
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1981
update table1 $update_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
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 update_pa...
Yuki Kimoto authored on 2011-03-08
1987
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1988
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1989
                  "basic");
1990

            
1991

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

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

            
2010
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2011
$dbi->execute($CREATE_TABLE->{1});
2012
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
2013
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
2014

            
2015
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2016
$update_param = $dbi->update_param($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2017
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2018
update table1 set $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2019
where key1 = 1
2020
EOS
2021
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2022
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2023
$rows   = $result->all;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2024
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
2025
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
2026
                  "update param no_set");
2027

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

            
2032

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

            
2039
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2040
$update_param = $dbi->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2041
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2042
update table1 set $update_param
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2043
where key1 = 1
2044
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2045
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2046
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2047
$rows   = $result->all;
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2048
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2049
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
2050
                  "basic");
2051

            
2052

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2053
test 'insert_param';
2054
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2055
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2056
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2057
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2058
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2059
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2060
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2061
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2062
is($dbi->select(table => 'table1')->one->{key1}, 1);
2063
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2064

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2065
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2066
$dbi->quote('"');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2067
$dbi->execute($CREATE_TABLE->{1});
2068
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2069
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2070
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2071
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2072
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2073
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2074
is($dbi->select(table => 'table1')->one->{key1}, 1);
2075
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
2076

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

            
2080

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2081
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
2082
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2083
$dbi->execute($CREATE_TABLE->{0});
2084
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2085
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
2086
$dbi->execute($CREATE_TABLE->{2});
2087
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2088
$dbi->execute($CREATE_TABLE->{4});
2089
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
2090
$rows = $dbi->select(
2091
    table => 'table1',
2092
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2093
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2094
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2095
)->all;
cleanup
Yuki Kimoto authored on 2011-03-08
2096
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
2097

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

            
cleanup
Yuki Kimoto authored on 2011-03-08
2105
eval {
2106
    $rows = $dbi->select(
2107
        table => 'table1',
2108
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2109
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2110
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2111
    );
2112
};
2113
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2114

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

            
2123
$rows = $dbi->select(
2124
    column => 'table3.key4 as table3__key4',
2125
    table => 'table1',
2126
    where   => {'table1.key1' => 1},
2127
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2128
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2129
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2130
is_deeply($rows, [{table3__key4 => 4}]);
2131

            
2132
$rows = $dbi->select(
2133
    column => 'table1.key1 as table1__key1',
2134
    table => 'table1',
2135
    where   => {'table3.key4' => 4},
2136
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2137
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2138
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2139
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2140

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2141
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2142
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2143
$dbi->execute($CREATE_TABLE->{0});
2144
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2145
$dbi->execute($CREATE_TABLE->{2});
2146
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2147
$rows = $dbi->select(
2148
    table => 'table1',
2149
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2150
    where   => {'table1.key2' => 2},
2151
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2152
)->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2153
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
2154
          'quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2155

            
2156
{
2157
    package MyDBI8;
2158
    
2159
    use base 'DBIx::Custom';
2160
    
2161
    sub connect {
2162
        my $self = shift->SUPER::connect(@_);
2163
        
2164
        $self->include_model('MyModel7');
2165
        
2166
        return $self;
2167
    }
2168
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2169

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2170
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2171
$dbi->execute($CREATE_TABLE->{0});
2172
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2173
$sql = <<"EOS";
2174
left outer join (
2175
  select * from table1 as t1
2176
  where t1.key2 = (
2177
    select max(t2.key2) from table1 as t2
2178
    where t1.key1 = t2.key1
2179
  )
2180
) as latest_table1 on table1.key1 = latest_table1.key1
2181
EOS
2182
$join = [$sql];
2183
$rows = $dbi->select(
2184
    table => 'table1',
2185
    column => 'latest_table1.key1 as latest_table1__key1',
2186
    join  => $join
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2187
)->all;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2188
is_deeply($rows, [{latest_table1__key1 => 1}]);
2189

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

            
2220
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2221
$dbi->execute($CREATE_TABLE->{0});
2222
$dbi->execute($CREATE_TABLE->{2});
2223
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2224
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2225
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2226
$result = $dbi->select(
2227
    table => 'table1',
2228
    column => [{table2 => ['key3']}],
2229
    join => [
2230
        {
2231
            clause => "left outer join table2 on table2.key3 = '4' and table1.key1 = table2.key1",
2232
            table => ['table1', 'table2']
2233
        }
2234
    ]
2235
);
2236
is_deeply($result->all, [{'table2.key3' => 4}]);
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2237

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2238
test 'mycolumn';
2239
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2240
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2241
$dbi->execute($CREATE_TABLE->{2});
2242
$dbi->setup_model;
2243
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2244
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2245
$model = $dbi->model('table1');
2246
$result = $model->select_at(
2247
    column => [
2248
        $model->mycolumn,
2249
        $model->column('table2')
2250
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2251
);
added tests
Yuki Kimoto authored on 2011-06-08
2252
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2253
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2254

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2255
$result = $model->select_at(
2256
    column => [
2257
        $model->mycolumn(['key1']),
2258
        $model->column(table2 => ['key1'])
2259
    ]
2260
);
added tests
Yuki Kimoto authored on 2011-06-08
2261
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2262
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2263
$result = $model->select_at(
2264
    column => [
2265
        $model->mycolumn(['key1']),
2266
        {table2 => ['key1']}
2267
    ]
2268
);
added tests
Yuki Kimoto authored on 2011-06-08
2269
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2270
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2271

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2272
$result = $model->select_at(
2273
    column => [
2274
        $model->mycolumn(['key1']),
2275
        ['table2.key1', as => 'table2.key1']
2276
    ]
2277
);
2278
is_deeply($result->one,
2279
          {key1 => 1, 'table2.key1' => 1});
2280

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2281
$result = $model->select_at(
2282
    column => [
2283
        $model->mycolumn(['key1']),
2284
        ['table2.key1' => 'table2.key1']
2285
    ]
2286
);
2287
is_deeply($result->one,
2288
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2289

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2290
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2291
{
2292
    package MyDBI9;
2293
    
2294
    use base 'DBIx::Custom';
2295
    
2296
    sub connect {
2297
        my $self = shift->SUPER::connect(@_);
2298
        
2299
        $self->include_model('MyModel8')->setup_model;
2300
        
2301
        return $self;
2302
    }
2303
}
2304
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2305
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2306
$model = $dbi->model('table1');
2307
eval{$model->execute('select * from table1')};
2308
ok(!$@);
2309

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2310
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2311
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2312
$dbi->execute($CREATE_TABLE->{0});
2313
$dbi->execute($CREATE_TABLE->{2});
2314
$dbi->setup_model;
2315
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2316
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2317
$model = $dbi->model('table1');
2318
$result = $model->select(
2319
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2320
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2321
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2322
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2323
);
added tests
Yuki Kimoto authored on 2011-06-08
2324
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2325
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2326

            
cleanup
Yuki Kimoto authored on 2011-06-13
2327
$dbi->separator('__');
2328
$result = $model->select(
2329
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2330
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2331
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2332
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2333
);
2334
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2335
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2336

            
2337
$dbi->separator('-');
2338
$result = $model->select(
2339
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2340
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2341
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2342
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2343
);
2344
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2345
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2346

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2347
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2348
$dbi = DBIx::Custom->connect(
2349
    data_source => 'dbi:SQLite:dbname=:memory:',
2350
    dbi_option => {
2351
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2352
    }
2353
);
2354
my $binary = pack("I3", 1, 2, 3);
2355
$dbi->execute('create table table1(key1, key2)');
2356
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2357
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2358
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2359
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2360
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2361
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2362
is($row->{key1_length}, length $binary);
2363

            
2364
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2365
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2366
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2367
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2368
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2369
$row = $result->one;
2370
is($row->{key1_length}, length $binary);
2371

            
2372

            
2373
test 'bind_type option';
2374
$dbi = DBIx::Custom->connect(
2375
    data_source => 'dbi:SQLite:dbname=:memory:',
2376
    dbi_option => {
2377
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2378
    }
2379
);
2380
$binary = pack("I3", 1, 2, 3);
2381
$dbi->execute('create table table1(key1, key2)');
2382
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2383
$result = $dbi->select(table => 'table1');
2384
$row   = $result->one;
2385
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2386
$result = $dbi->execute('select length(key1) as key1_length from table1');
2387
$row = $result->one;
2388
is($row->{key1_length}, length $binary);
2389

            
2390
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2391
$result = $dbi->select(table => 'table1');
2392
$row   = $result->one;
2393
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2394
$result = $dbi->execute('select length(key1) as key1_length from table1');
2395
$row = $result->one;
2396
is($row->{key1_length}, length $binary);
2397

            
2398
test 'model type attribute';
2399
$dbi = DBIx::Custom->connect(
2400
    data_source => 'dbi:SQLite:dbname=:memory:',
2401
    dbi_option => {
2402
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2403
    }
2404
);
2405
$binary = pack("I3", 1, 2, 3);
2406
$dbi->execute('create table table1(key1, key2)');
2407
$model = $dbi->create_model(table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
2408
$model->insert(param => {key1 => $binary, key2 => 'あ'});
2409
$result = $dbi->select(table => 'table1');
2410
$row   = $result->one;
2411
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2412
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2413
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2414
is($row->{key1_length}, length $binary);
2415

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2416
test 'create_model';
2417
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2418
$dbi->execute($CREATE_TABLE->{0});
2419
$dbi->execute($CREATE_TABLE->{2});
2420

            
2421
$dbi->create_model(
2422
    table => 'table1',
2423
    join => [
2424
       'left outer join table2 on table1.key1 = table2.key1'
2425
    ],
2426
    primary_key => ['key1']
2427
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2428
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2429
    table => 'table2'
2430
);
2431
$dbi->create_model(
2432
    table => 'table3',
2433
    filter => [
2434
        key1 => {in => sub { uc $_[0] }}
2435
    ]
2436
);
2437
$dbi->setup_model;
2438
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2439
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2440
$model = $dbi->model('table1');
2441
$result = $model->select(
2442
    column => [$model->mycolumn, $model->column('table2')],
2443
    where => {'table1.key1' => 1}
2444
);
added tests
Yuki Kimoto authored on 2011-06-08
2445
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2446
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2447
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2448

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2449
test 'model method';
2450
test 'create_model';
2451
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2452
$dbi->execute($CREATE_TABLE->{2});
2453
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2454
$model = $dbi->create_model(
2455
    table => 'table2'
2456
);
2457
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2458
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2459

            
2460
test 'merge_param';
2461
{
2462
    my $dbi = DBIx::Custom->new;
2463
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2464
    my $param2 = {key1 => 1, key2 => 2};
2465
    my $param3 = {key1 => 1};
2466
    my $param = $dbi->merge_param($param1, $param2, $param3);
2467
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2468
}
2469

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2470
{
2471
    my $dbi = DBIx::Custom->new;
2472
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2473
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2474
    my $param = $dbi->merge_param($param1, $param2);
2475
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2476
}
2477

            
cleanup
Yuki Kimoto authored on 2011-04-01
2478
test 'select() param 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
$dbi->execute($CREATE_TABLE->{2});
2484
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2485
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2486
$rows = $dbi->select(
2487
    table => 'table1',
2488
    column => 'table1.key1 as table1_key1, key2, key3',
2489
    where   => {'table1.key2' => 3},
2490
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2491
              ' as table2 on table1.key1 = table2.key1'],
2492
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2493
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2494
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2495

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

            
2497
test 'select() wrap option';
2498
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2499
$dbi->execute($CREATE_TABLE->{0});
2500
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2501
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2502
$rows = $dbi->select(
2503
    table => 'table1',
2504
    column => 'key1',
2505
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2506
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2507
is_deeply($rows, [{key1 => 1}]);
2508

            
2509
eval {
2510
$dbi->select(
2511
    table => 'table1',
2512
    column => 'key1',
2513
    wrap => 'select * from ('
2514
)
2515
};
cleanup
Yuki Kimoto authored on 2011-04-25
2516
like($@, qr/array/);
2517

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2530
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2531
$dbi->execute($CREATE_TABLE->{0});
2532
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2533
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2534
$rows = $dbi->select(
2535
    table => 'table1',
2536
    where => [
2537
        'key1 = :key1 and key2 = :key2',
2538
        {key1 => 1, key2 => 2}
2539
    ]
2540
)->all;
2541
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2542

            
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2543
test 'delete() string where';
2544
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2545
$dbi->execute($CREATE_TABLE->{0});
2546
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2547
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2548
$dbi->delete(
2549
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2550
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2551
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2552
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2553
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2554
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2555

            
updated pod
Yuki Kimoto authored on 2011-06-21
2556
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2557
$dbi->execute($CREATE_TABLE->{0});
2558
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2559
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2560
$dbi->delete(
2561
    table => 'table1',
2562
    where => [
2563
        'key1 = :key1 and key2 = :key2',
2564
         {key1 => 1, key2 => 2}
2565
    ]
2566
);
2567
$rows = $dbi->select(table => 'table1')->all;
2568
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2569

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

            
2571
test 'update() string where';
2572
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2573
$dbi->execute($CREATE_TABLE->{0});
2574
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2575
$dbi->update(
2576
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2577
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2578
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2579
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2580
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2581
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2582
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2583

            
updated pod
Yuki Kimoto authored on 2011-06-21
2584
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2585
$dbi->execute($CREATE_TABLE->{0});
2586
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2587
$dbi->update(
2588
    table => 'table1',
2589
    param => {key1 => 5},
2590
    where => [
2591
        'key1 = :key1 and key2 = :key2',
2592
        {key1 => 1, key2 => 2}
2593
    ]
2594
);
2595
$rows = $dbi->select(table => 'table1')->all;
2596
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2597

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2598
test 'insert id and primary_key option';
2599
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2600
$dbi->execute($CREATE_TABLE->{1});
2601
$dbi->insert(
2602
    primary_key => ['key1', 'key2'], 
2603
    table => 'table1',
2604
    id => [1, 2],
2605
    param => {key3 => 3}
2606
);
2607
is($dbi->select(table => 'table1')->one->{key1}, 1);
2608
is($dbi->select(table => 'table1')->one->{key2}, 2);
2609
is($dbi->select(table => 'table1')->one->{key3}, 3);
2610

            
2611
$dbi->delete_all(table => 'table1');
2612
$dbi->insert(
2613
    primary_key => 'key1', 
2614
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2615
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2616
    param => {key2 => 2, key3 => 3}
2617
);
2618

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

            
2623
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2624
$dbi->execute($CREATE_TABLE->{1});
2625
$dbi->insert(
2626
    {key3 => 3},
2627
    primary_key => ['key1', 'key2'], 
2628
    table => 'table1',
2629
    id => [1, 2],
2630
);
2631
is($dbi->select(table => 'table1')->one->{key1}, 1);
2632
is($dbi->select(table => 'table1')->one->{key2}, 2);
2633
is($dbi->select(table => 'table1')->one->{key3}, 3);
2634

            
cleanup
Yuki Kimoto authored on 2011-06-08
2635

            
added tests
Yuki Kimoto authored on 2011-06-08
2636
test 'model insert id and primary_key option';
2637
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2638
$dbi->execute($CREATE_TABLE->{1});
2639
$dbi->model('table1')->insert(
2640
    id => [1, 2],
2641
    param => {key3 => 3}
2642
);
2643
$result = $dbi->model('table1')->select;
2644
$row = $result->one;
2645
is($row->{key1}, 1);
2646
is($row->{key2}, 2);
2647
is($row->{key3}, 3);
2648

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2649
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2650
$dbi->execute($CREATE_TABLE->{1});
2651
$dbi->model('table1')->insert(
2652
    {key3 => 3},
2653
    id => [1, 2]
2654
);
2655
$result = $dbi->model('table1')->select;
2656
$row = $result->one;
2657
is($row->{key1}, 1);
2658
is($row->{key2}, 2);
2659
is($row->{key3}, 3);
2660

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2661
test 'update and id option';
2662
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2663
$dbi->execute($CREATE_TABLE->{1});
2664
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2665
$dbi->update(
2666
    table => 'table1',
2667
    primary_key => ['key1', 'key2'],
2668
    id => [1, 2],
2669
    param => {key3 => 4}
2670
);
2671
is($dbi->select(table => 'table1')->one->{key1}, 1);
2672
is($dbi->select(table => 'table1')->one->{key2}, 2);
2673
is($dbi->select(table => 'table1')->one->{key3}, 4);
2674

            
2675
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2676
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2677
$dbi->update(
2678
    table => 'table1',
2679
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2680
    id => 0,
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2681
    param => {key3 => 4}
2682
);
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2683
is($dbi->select(table => 'table1')->one->{key1}, 0);
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2684
is($dbi->select(table => 'table1')->one->{key2}, 2);
2685
is($dbi->select(table => 'table1')->one->{key3}, 4);
2686

            
2687
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2688
$dbi->execute($CREATE_TABLE->{1});
2689
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2690
$dbi->update(
2691
    {key3 => 4},
2692
    table => 'table1',
2693
    primary_key => ['key1', 'key2'],
2694
    id => [1, 2]
2695
);
2696
is($dbi->select(table => 'table1')->one->{key1}, 1);
2697
is($dbi->select(table => 'table1')->one->{key2}, 2);
2698
is($dbi->select(table => 'table1')->one->{key3}, 4);
2699

            
2700

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2701
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2702
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2703
$dbi->execute($CREATE_TABLE->{1});
2704
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2705
$dbi->model('table1')->update(
2706
    id => [1, 2],
2707
    param => {key3 => 4}
2708
);
2709
$result = $dbi->model('table1')->select;
2710
$row = $result->one;
2711
is($row->{key1}, 1);
2712
is($row->{key2}, 2);
2713
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2714

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

            
2716
test 'delete and id option';
2717
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2718
$dbi->execute($CREATE_TABLE->{1});
2719
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2720
$dbi->delete(
2721
    table => 'table1',
2722
    primary_key => ['key1', 'key2'],
2723
    id => [1, 2],
2724
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2725
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2726

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2727
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2728
$dbi->delete(
2729
    table => 'table1',
2730
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2731
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2732
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2733
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2734

            
2735

            
2736
test 'model delete and id option';
2737
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2738
$dbi->execute($CREATE_TABLE->{1});
2739
$dbi->execute("create table table2 (key1, key2, key3)");
2740
$dbi->execute("create table table3 (key1, key2, key3)");
2741
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2742
$dbi->model('table1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2743
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2744
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2745
$dbi->model('table1_1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2746
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2747
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2748
$dbi->model('table1_3')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2749
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2750

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

            
2752
test 'select and id option';
2753
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2754
$dbi->execute($CREATE_TABLE->{1});
2755
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2756
$result = $dbi->select(
2757
    table => 'table1',
2758
    primary_key => ['key1', 'key2'],
2759
    id => [1, 2]
2760
);
2761
$row = $result->one;
2762
is($row->{key1}, 1);
2763
is($row->{key2}, 2);
2764
is($row->{key3}, 3);
2765

            
2766
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2767
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2768
$result = $dbi->select(
2769
    table => 'table1',
2770
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2771
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2772
);
2773
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2774
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2775
is($row->{key2}, 2);
2776
is($row->{key3}, 3);
2777

            
2778
$dbi->delete_all(table => 'table1');
2779
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2780
$result = $dbi->select(
2781
    table => 'table1',
2782
    primary_key => ['key1', 'key2'],
2783
    id => [1, 2]
2784
);
2785
$row = $result->one;
2786
is($row->{key1}, 1);
2787
is($row->{key2}, 2);
2788
is($row->{key3}, 3);
2789

            
2790

            
2791
test 'model select_at';
2792
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2793
$dbi->execute($CREATE_TABLE->{1});
2794
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2795
$result = $dbi->model('table1')->select(id => [1, 2]);
2796
$row = $result->one;
2797
is($row->{key1}, 1);
2798
is($row->{key2}, 2);
2799
is($row->{key3}, 3);
2800

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2801
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2802
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2803
$dbi->execute($CREATE_TABLE->{0});
2804
$dbi->execute($CREATE_TABLE->{2});
2805
$dbi->setup_model;
2806
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2807
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2808
$model = $dbi->model('table1');
2809
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2810
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2811
    where => {'table1.key1' => 1}
2812
);
2813
is_deeply($result->one,
2814
          {'table2.key1' => 1, 'table2.key3' => 3});
2815

            
2816
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2817
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2818
    where => {'table1.key1' => 1}
2819
);
2820
is_deeply($result->one,
2821
          {'table2.key1' => 1, 'table2.key3' => 3});
2822

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

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

            
2836
$result = $dbi->select(table => 'table1');
2837
is($result->one->{key1}, 'A');
2838

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

            
2840
test 'type_rule into';
2841
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2842
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2843
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2844
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2845
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2846
    }
2847
);
2848
$dbi->insert({key1 => 'a'}, table => 'table1');
2849
$result = $dbi->select(table => 'table1');
2850
is($result->one->{key1}, 'A');
2851

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

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

            
2881
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2882
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2883
$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1');
2884
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2885
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2886
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2887
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2888
);
2889
$result = $dbi->execute(
2890
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2891
    param => {key1 => 'a', 'table1.key2' => 'b'},
2892
    table => 'table1'
2893
);
2894
$row = $result->one;
2895
is($row->{key1}, 'A');
2896
is($row->{key2}, 'B');
2897

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2898
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2899
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2900
$dbi->register_filter(twice => sub { $_[0] * 2 });
2901
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2902
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2903
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2904
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2905
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2906
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2907
    }
2908
);
2909
$dbi->insert({key1 => 2}, table => 'table1');
2910
$result = $dbi->select(table => 'table1');
2911
is($result->fetch->[0], 8);
2912

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2913
test 'type_rule and filter order';
2914
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2915
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2916
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2917
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2918
        date => sub { $_[0] . 'b' }
2919
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2920
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2921
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2922
    },
2923
    from1 => {
2924
        date => sub { $_[0] . 'd' }
2925
    },
2926
    from2 => {
2927
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2928
    }
2929
);
2930
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2931
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2932
$result->filter(key1 => sub { $_[0] . 'f' });
2933
is($result->fetch_first->[0], '1abcdef');
2934

            
2935
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2936
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2937
$dbi->type_rule(
2938
    from1 => {
2939
        date => sub { $_[0] . 'p' }
2940
    },
2941
    from2 => {
2942
        date => sub { $_[0] . 'q' }
2943
    },
2944
);
2945
$dbi->insert({key1 => '1'}, table => 'table1');
2946
$result = $dbi->select(table => 'table1');
2947
$result->type_rule(
2948
    from1 => {
2949
        date => sub { $_[0] . 'd' }
2950
    },
2951
    from2 => {
2952
        date => sub { $_[0] . 'e' }
2953
    }
2954
);
2955
$result->filter(key1 => sub { $_[0] . 'f' });
2956
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2957

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

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

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

            
3001
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3002
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3003
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3004
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3005
        date => sub { $_[0] * 2 },
3006
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3007
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3008
        date => sub { $_[0] * 3 },
3009
    }
3010
);
3011
$dbi->insert({key1 => 2}, table => 'table1');
3012
$result = $dbi->select(table => 'table1');
3013
is($result->fetch->[0], 12);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3014

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3015
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3016
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3017
$dbi->register_filter(ppp => sub { uc $_[0] });
3018
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3019
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3020
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3021
    }
3022
);
3023
$dbi->insert({key1 => 'a'}, table => 'table1');
3024
$result = $dbi->select(table => 'table1');
3025
is($result->one->{key1}, 'A');
3026

            
3027
eval{$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 => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3030
    }
3031
)};
3032
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3033

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3034
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3035
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3036
eval {
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
        }
3041
    );
3042
};
3043
like($@, qr/lower/);
3044

            
3045
eval {
3046
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3047
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3048
            Date => sub { $_[0] * 2 },
3049
        }
3050
    );
3051
};
3052
like($@, qr/lower/);
3053

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

            
3069
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3070
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3071
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3072
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3073
        date => sub { $_[0] * 2 },
3074
        datetime => sub { $_[0] * 4 },
3075
    },
3076
);
3077
$dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3078
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3079
$result->type_rule(
3080
    from1 => {
3081
        date => sub { $_[0] * 3 }
3082
    }
3083
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3084
$row = $result->one;
3085
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3086
is($row->{key2}, 2);
3087

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3088
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3089
$result->type_rule(
3090
    from1 => {
3091
        date => sub { $_[0] * 3 }
3092
    }
3093
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3094
$row = $result->one;
3095
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3096
is($row->{key2}, 2);
3097

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3098
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3099
$result->type_rule(
3100
    from1 => {
3101
        date => sub { $_[0] * 3 }
3102
    }
3103
);
cleanup
Yuki Kimoto authored on 2011-06-15
3104
$row = $result->one;
3105
is($row->{key1}, 6);
3106
is($row->{key2}, 2);
3107
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3108
$result->type_rule(
3109
    from1 => [date => sub { $_[0] * 3 }]
3110
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3111
$row = $result->one;
3112
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3113
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3114
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3115
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3116
$result->type_rule(
3117
    from1 => [date => 'fivetimes']
3118
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3119
$row = $result->one;
3120
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3121
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3122
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3123
$result->type_rule(
3124
    from1 => [date => undef]
3125
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3126
$row = $result->one;
3127
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3128
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3129

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3130
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3131
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3132
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3133
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3134
        date => sub { $_[0] * 2 },
3135
    },
3136
);
3137
$dbi->insert({key1 => 2}, table => 'table1');
3138
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3139
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3140
is($result->one->{key1}, 12);
3141

            
3142
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3143
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3144
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3145
    from1 => {
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3146
        date => sub { $_[0] * 2 },
3147
    },
3148
);
3149
$dbi->insert({key1 => 2}, table => 'table1');
3150
$result = $dbi->select(table => 'table1');
3151
$result->filter(key1 => sub { $_[0] * 3 });
3152
is($result->fetch->[0], 12);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3153

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

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

            
3198
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3199
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3200
$dbi->type_rule(
3201
    into1 => {
3202
        date => sub { $_[0] . 'b' }
3203
    },
3204
    into2 => {
3205
        date => sub { $_[0] . 'c' }
3206
    },
3207
    from1 => {
3208
        date => sub { $_[0] . 'd' }
3209
    },
3210
    from2 => {
3211
        date => sub { $_[0] . 'e' }
3212
    }
3213
);
3214
$dbi->insert({key1 => '1'}, table => 'table1', type_rule2_off => 1);
3215
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3216
is($result->type_rule2_off->fetch_first->[0], '1bd');
3217
$result = $dbi->select(table => 'table1');
3218
is($result->type_rule2_on->fetch_first->[0], '1bde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3219

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3220
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3221
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3222
$dbi->execute($CREATE_TABLE->{0});
3223
$dbi->execute($CREATE_TABLE->{2});
3224

            
3225
$dbi->create_model(
3226
    table => 'table1',
3227
    join => [
3228
       'left outer join table2 on table1.key1 = table2.key1'
3229
    ],
3230
    primary_key => ['key1'],
3231
);
3232
$model2 = $dbi->create_model(
3233
    table => 'table2',
3234
);
3235
$dbi->setup_model;
3236
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3237
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3238
$model = $dbi->model('table1');
3239
$result = $model->select(
3240
    column => [
3241
        $model->mycolumn,
3242
        {table2 => [qw/key1 key3/]}
3243
    ],
3244
    where => {'table1.key1' => 1}
3245
);
3246
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3247
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3248
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3249

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3250
$dbi->separator('__');
3251
$model = $dbi->model('table1');
3252
$result = $model->select(
3253
    column => [
3254
        $model->mycolumn,
3255
        {table2 => [qw/key1 key3/]}
3256
    ],
3257
    where => {'table1.key1' => 1}
3258
);
3259
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3260
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3261
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3262

            
cleanup
Yuki Kimoto authored on 2011-06-13
3263
$dbi->separator('-');
3264
$model = $dbi->model('table1');
3265
$result = $model->select(
3266
    column => [
3267
        $model->mycolumn,
3268
        {table2 => [qw/key1 key3/]}
3269
    ],
3270
    where => {'table1.key1' => 1}
3271
);
3272
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3273
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3274
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3275

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3277
test 'filter_off';
3278
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3279
$dbi->execute($CREATE_TABLE->{0});
3280
$dbi->execute($CREATE_TABLE->{2});
3281

            
3282
$dbi->create_model(
3283
    table => 'table1',
3284
    join => [
3285
       'left outer join table2 on table1.key1 = table2.key1'
3286
    ],
3287
    primary_key => ['key1'],
3288
);
3289
$dbi->setup_model;
3290
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3291
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3292
$result = $model->select(column => 'key1');
3293
$result->filter(key1 => sub { $_[0] * 2 });
3294
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3295

            
3296
test 'available_date_type';
3297
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3298
ok($dbi->can('available_data_type'));
3299

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

            
3301
test 'select prefix option';
3302
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3303
$dbi->execute($CREATE_TABLE->{0});
3304
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3305
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3306
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3307

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

            
3309
test 'separator';
3310
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3311
is($dbi->separator, '.');
3312
$dbi->separator('-');
3313
is($dbi->separator, '-');
3314
$dbi->separator('__');
3315
is($dbi->separator, '__');
3316
eval { $dbi->separator('?') };
3317
like($@, qr/Separator/);
3318

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

            
3320
test 'map_param';
3321
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3322
$param = $dbi->map_param(
3323
    {id => 1, author => 'Ken', price => 1900},
3324
    id => 'book.id',
3325
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3326
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3327
);
3328
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3329
  'book.price' => 1900});
3330

            
3331
$param = $dbi->map_param(
3332
    {id => 0, author => 0, price => 0},
3333
    id => 'book.id',
3334
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3335
    price => ['book.price', sub { '%' . $_[0] . '%' },
3336
      {if => sub { $_[0] eq 0 }}]
3337
);
3338
is_deeply($param, {'book.id' => 0, 'book.author' => '%0%', 'book.price' => '%0%'});
3339

            
3340
$param = $dbi->map_param(
3341
    {id => '', author => '', price => ''},
3342
    id => 'book.id',
3343
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3344
    price => ['book.price', sub { '%' . $_[0] . '%' },
3345
      {if => sub { $_[0] eq 1 }}]
3346
);
3347
is_deeply($param, {});
3348

            
3349
$param = $dbi->map_param(
3350
    {id => undef, author => undef, price => undef},
3351
    id => 'book.id',
3352
    price => ['book.price', {if => 'exists'}]
3353
);
3354
is_deeply($param, {'book.price' => undef});
3355

            
3356
$param = $dbi->map_param(
3357
    {price => 'a'},
3358
    id => ['book.id', {if => 'exists'}],
3359
    price => ['book.price', sub { '%' . $_[0] }, {if => 'exists'}]
3360
);
3361
is_deeply($param, {'book.price' => '%a'});
3362

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

            
3364
test 'table_alias';
3365
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3366
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3367
$dbi->type_rule(
3368
    into1 => {
3369
        date => sub { uc $_[0] }
3370
    }
3371
);
3372
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3373
  table_alias => {table2 => 'table1'});
3374
$result = $dbi->select(table => 'table1');
3375
is($result->one->{key1}, 'A');
3376

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

            
3378
test 'order';
3379
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3380
{
3381
    $dbi->execute("create table table1 (key1, key2)");
3382
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3383
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3384
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3385
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3386
    my $order = $dbi->order;
3387
    $order->prepend('key1', 'key2 desc');
3388
    $result = $dbi->select(table => 'table1', append => "$order");
3389
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3390
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3391
    $order->prepend('key1 desc');
3392
    $result = $dbi->select(table => 'table1', append => "$order");
3393
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3394
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
added DBIx::Cusotm::Order pr...
Yuki Kimoto authored on 2011-07-11
3395

            
3396
    $order = $dbi->order;
3397
    $order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
3398
    $result = $dbi->select(table => 'table1',
3399
      column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
3400
      append => "$order");
3401
    is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
3402
      {'table1-key1' => 1, 'table1-key2' => 1},
3403
      {'table1-key1' => 2, 'table1-key2' => 4},
3404
      {'table1-key1' => 2, 'table1-key2' => 2}]);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3405
}
3406

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3407
test 'tag_parse';
3408
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3409
$dbi->tag_parse(0);
3410
{
3411
    $dbi->execute("create table table1 (key1, key2)");
3412
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3413
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3414
    ok($@);
3415
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3416

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3417
test 'last_sql';
3418
{
3419
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3420
    $dbi->execute("create table table1 (key1, key2)");
3421
    $dbi->execute('select * from table1');
3422
    is($dbi->last_sql, 'select * from table1;');
3423
    
3424
    eval{$dbi->execute("aaa")};
3425
    is($dbi->last_sql, 'aaa;');
3426
    
3427
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3428

            
3429
test 'DBIx::Custom header';
3430
{
3431
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3432
    $dbi->execute("create table table1 (key1, key2)");
3433
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3434
    
3435
    is_deeply($result->header, [qw/h1 h2/]);
3436
    
3437
}
3438

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

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

            
3450
$source = "select * from table1 where :key1{ = } and :key2{=}";
3451
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
3452
$rows = $result->all;
3453
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3454

            
3455
$source = "select * from table1 where :key1{<} and :key2{=}";
3456
$result = $dbi->execute($source, param => {key1 => 5, key2 => 2});
3457
$rows = $result->all;
3458
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3459

            
3460
$source = "select * from table1 where :table1.key1{=} and :table1.key2{=}";
3461
$result = $dbi->execute(
3462
    $source,
3463
    param => {'table1.key1' => 1, 'table1.key2' => 1},
3464
    filter => {'table1.key2' => sub { $_[0] * 2 }}
3465
);
3466
$rows = $result->all;
3467
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3468

            
cleanup
Yuki Kimoto authored on 2011-07-30
3469
test 'high perfomance way';
3470
$dbi->execute($DROP_TABLE->{0});
3471
$dbi->execute("create table table1 (ab, bc, ik, hi, ui, pq, dc);");
3472
$rows = [
3473
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3474
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3475
];
3476
{
3477
    my $query;
3478
    my $sth;
3479
    foreach my $row (@$rows) {
3480
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
3481
      $sth ||= $query->sth;
3482
      $sth->execute(map { $row->{$_} } sort keys %$row);
3483
    }
3484
    is_deeply($dbi->select(table => 'table1')->all,
3485
      [
3486
          {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3487
          {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3488
      ]
3489
    );
3490
}
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3491
=cut