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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
160
$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
161
$query = $dbi->execute($source, {}, query => 1);
removed register_format()
yuki-kimoto authored on 2010-05-26
162
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
163
$rows = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
164
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
removed register_format()
yuki-kimoto authored on 2010-05-26
165

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
457

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

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

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

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

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

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

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

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

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

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

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

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

            
552

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

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

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

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

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

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

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

            
589
$rows = $dbi->select(
590
    table => [qw/table1 table2/],
591
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
592
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
593
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
594
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where");
removed register_format()
yuki-kimoto authored on 2010-05-26
595

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
701

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

            
706
$dbi->begin_work;
707

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

            
714
$dbi->rollback if $@;
715

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

            
720
$dbi->begin_work;
721

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

            
727
$dbi->commit unless $@;
728

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1377

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

            
1389

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

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

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

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

            
1419

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

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

            
1428
$dbi->apply_filter(
1429

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1556
{
1557
    package MyDBI4;
1558

            
1559
    use strict;
1560
    use warnings;
1561

            
1562
    use base 'DBIx::Custom';
1563

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

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

            
1577
    use strict;
1578
    use warnings;
1579

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

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

            
1584
    use strict;
1585
    use warnings;
1586

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

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

            
1595
    sub list { shift->select; }
1596

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

            
1599
    use strict;
1600
    use warnings;
1601

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

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

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

            
1622
{
1623
     package MyDBI5;
1624

            
1625
    use strict;
1626
    use warnings;
1627

            
1628
    use base 'DBIx::Custom';
1629

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1856

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

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

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

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

            
1922

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

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

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

            
1972

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

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

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

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

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

            
2013

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

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

            
2033

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

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

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

            
2061

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2193
test 'mycolumn';
2194
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2195
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2196
$dbi->execute($CREATE_TABLE->{2});
2197
$dbi->setup_model;
2198
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2199
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2200
$model = $dbi->model('table1');
2201
$result = $model->select_at(
2202
    column => [
2203
        $model->mycolumn,
2204
        $model->column('table2')
2205
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2206
);
added tests
Yuki Kimoto authored on 2011-06-08
2207
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2208
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2209

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2210
$result = $model->select_at(
2211
    column => [
2212
        $model->mycolumn(['key1']),
2213
        $model->column(table2 => ['key1'])
2214
    ]
2215
);
added tests
Yuki Kimoto authored on 2011-06-08
2216
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2217
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2218
$result = $model->select_at(
2219
    column => [
2220
        $model->mycolumn(['key1']),
2221
        {table2 => ['key1']}
2222
    ]
2223
);
added tests
Yuki Kimoto authored on 2011-06-08
2224
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2225
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2226

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2227
$result = $model->select_at(
2228
    column => [
2229
        $model->mycolumn(['key1']),
2230
        ['table2.key1', as => 'table2.key1']
2231
    ]
2232
);
2233
is_deeply($result->one,
2234
          {key1 => 1, 'table2.key1' => 1});
2235

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2236
$result = $model->select_at(
2237
    column => [
2238
        $model->mycolumn(['key1']),
2239
        ['table2.key1' => 'table2.key1']
2240
    ]
2241
);
2242
is_deeply($result->one,
2243
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2244

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2245
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2246
{
2247
    package MyDBI9;
2248
    
2249
    use base 'DBIx::Custom';
2250
    
2251
    sub connect {
2252
        my $self = shift->SUPER::connect(@_);
2253
        
2254
        $self->include_model('MyModel8')->setup_model;
2255
        
2256
        return $self;
2257
    }
2258
}
2259
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2260
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2261
$model = $dbi->model('table1');
2262
eval{$model->execute('select * from table1')};
2263
ok(!$@);
2264

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2265
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2266
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2267
$dbi->execute($CREATE_TABLE->{0});
2268
$dbi->execute($CREATE_TABLE->{2});
2269
$dbi->setup_model;
2270
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2271
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2272
$model = $dbi->model('table1');
2273
$result = $model->select(
2274
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2275
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2276
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2277
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2278
);
added tests
Yuki Kimoto authored on 2011-06-08
2279
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2280
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2281

            
cleanup
Yuki Kimoto authored on 2011-06-13
2282
$dbi->separator('__');
2283
$result = $model->select(
2284
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2285
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2286
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2287
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2288
);
2289
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2290
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2291

            
2292
$dbi->separator('-');
2293
$result = $model->select(
2294
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2295
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2296
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2297
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2298
);
2299
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2300
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2301

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2302
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2303
$dbi = DBIx::Custom->connect(
2304
    data_source => 'dbi:SQLite:dbname=:memory:',
2305
    dbi_option => {
2306
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2307
    }
2308
);
2309
my $binary = pack("I3", 1, 2, 3);
2310
$dbi->execute('create table table1(key1, key2)');
2311
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2312
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2313
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2314
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2315
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2316
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2317
is($row->{key1_length}, length $binary);
2318

            
2319
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2320
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2321
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2322
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2323
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2324
$row = $result->one;
2325
is($row->{key1_length}, length $binary);
2326

            
2327

            
2328
test 'bind_type option';
2329
$dbi = DBIx::Custom->connect(
2330
    data_source => 'dbi:SQLite:dbname=:memory:',
2331
    dbi_option => {
2332
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2333
    }
2334
);
2335
$binary = pack("I3", 1, 2, 3);
2336
$dbi->execute('create table table1(key1, key2)');
2337
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2338
$result = $dbi->select(table => 'table1');
2339
$row   = $result->one;
2340
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2341
$result = $dbi->execute('select length(key1) as key1_length from table1');
2342
$row = $result->one;
2343
is($row->{key1_length}, length $binary);
2344

            
2345
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2346
$result = $dbi->select(table => 'table1');
2347
$row   = $result->one;
2348
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2349
$result = $dbi->execute('select length(key1) as key1_length from table1');
2350
$row = $result->one;
2351
is($row->{key1_length}, length $binary);
2352

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2371
test 'create_model';
2372
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2373
$dbi->execute($CREATE_TABLE->{0});
2374
$dbi->execute($CREATE_TABLE->{2});
2375

            
2376
$dbi->create_model(
2377
    table => 'table1',
2378
    join => [
2379
       'left outer join table2 on table1.key1 = table2.key1'
2380
    ],
2381
    primary_key => ['key1']
2382
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2383
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2384
    table => 'table2'
2385
);
2386
$dbi->create_model(
2387
    table => 'table3',
2388
    filter => [
2389
        key1 => {in => sub { uc $_[0] }}
2390
    ]
2391
);
2392
$dbi->setup_model;
2393
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2394
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2395
$model = $dbi->model('table1');
2396
$result = $model->select(
2397
    column => [$model->mycolumn, $model->column('table2')],
2398
    where => {'table1.key1' => 1}
2399
);
added tests
Yuki Kimoto authored on 2011-06-08
2400
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2401
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2402
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2403

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2404
test 'model method';
2405
test 'create_model';
2406
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2407
$dbi->execute($CREATE_TABLE->{2});
2408
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2409
$model = $dbi->create_model(
2410
    table => 'table2'
2411
);
2412
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2413
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2414

            
2415
test 'merge_param';
2416
{
2417
    my $dbi = DBIx::Custom->new;
2418
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2419
    my $param2 = {key1 => 1, key2 => 2};
2420
    my $param3 = {key1 => 1};
2421
    my $param = $dbi->merge_param($param1, $param2, $param3);
2422
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2423
}
2424

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2425
{
2426
    my $dbi = DBIx::Custom->new;
2427
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2428
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2429
    my $param = $dbi->merge_param($param1, $param2);
2430
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2431
}
2432

            
cleanup
Yuki Kimoto authored on 2011-04-01
2433
test 'select() param option';
2434
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2435
$dbi->execute($CREATE_TABLE->{0});
2436
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2437
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2438
$dbi->execute($CREATE_TABLE->{2});
2439
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2440
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2441
$rows = $dbi->select(
2442
    table => 'table1',
2443
    column => 'table1.key1 as table1_key1, key2, key3',
2444
    where   => {'table1.key2' => 3},
2445
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2446
              ' as table2 on table1.key1 = table2.key1'],
2447
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2448
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2449
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2450

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

            
2452
test 'select() wrap option';
2453
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2454
$dbi->execute($CREATE_TABLE->{0});
2455
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2456
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2457
$rows = $dbi->select(
2458
    table => 'table1',
2459
    column => 'key1',
2460
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2461
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2462
is_deeply($rows, [{key1 => 1}]);
2463

            
2464
eval {
2465
$dbi->select(
2466
    table => 'table1',
2467
    column => 'key1',
2468
    wrap => 'select * from ('
2469
)
2470
};
cleanup
Yuki Kimoto authored on 2011-04-25
2471
like($@, qr/array/);
2472

            
2473
test 'select() string where';
2474
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2475
$dbi->execute($CREATE_TABLE->{0});
2476
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2477
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2478
$rows = $dbi->select(
2479
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2480
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2481
    where_param => {key1 => 1, key2 => 2}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2482
)->all;
cleanup
Yuki Kimoto authored on 2011-04-25
2483
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2484

            
updated pod
Yuki Kimoto authored on 2011-06-21
2485
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2486
$dbi->execute($CREATE_TABLE->{0});
2487
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2488
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2489
$rows = $dbi->select(
2490
    table => 'table1',
2491
    where => [
2492
        'key1 = :key1 and key2 = :key2',
2493
        {key1 => 1, key2 => 2}
2494
    ]
2495
)->all;
2496
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2497

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

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

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

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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2553
test 'insert id and primary_key option';
2554
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2555
$dbi->execute($CREATE_TABLE->{1});
2556
$dbi->insert(
2557
    primary_key => ['key1', 'key2'], 
2558
    table => 'table1',
2559
    id => [1, 2],
2560
    param => {key3 => 3}
2561
);
2562
is($dbi->select(table => 'table1')->one->{key1}, 1);
2563
is($dbi->select(table => 'table1')->one->{key2}, 2);
2564
is($dbi->select(table => 'table1')->one->{key3}, 3);
2565

            
2566
$dbi->delete_all(table => 'table1');
2567
$dbi->insert(
2568
    primary_key => 'key1', 
2569
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2570
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2571
    param => {key2 => 2, key3 => 3}
2572
);
2573

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

            
2578
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2579
$dbi->execute($CREATE_TABLE->{1});
2580
$dbi->insert(
2581
    {key3 => 3},
2582
    primary_key => ['key1', 'key2'], 
2583
    table => 'table1',
2584
    id => [1, 2],
2585
);
2586
is($dbi->select(table => 'table1')->one->{key1}, 1);
2587
is($dbi->select(table => 'table1')->one->{key2}, 2);
2588
is($dbi->select(table => 'table1')->one->{key3}, 3);
2589

            
cleanup
Yuki Kimoto authored on 2011-06-08
2590

            
added tests
Yuki Kimoto authored on 2011-06-08
2591
test 'model insert id and primary_key option';
2592
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2593
$dbi->execute($CREATE_TABLE->{1});
2594
$dbi->model('table1')->insert(
2595
    id => [1, 2],
2596
    param => {key3 => 3}
2597
);
2598
$result = $dbi->model('table1')->select;
2599
$row = $result->one;
2600
is($row->{key1}, 1);
2601
is($row->{key2}, 2);
2602
is($row->{key3}, 3);
2603

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2604
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2605
$dbi->execute($CREATE_TABLE->{1});
2606
$dbi->model('table1')->insert(
2607
    {key3 => 3},
2608
    id => [1, 2]
2609
);
2610
$result = $dbi->model('table1')->select;
2611
$row = $result->one;
2612
is($row->{key1}, 1);
2613
is($row->{key2}, 2);
2614
is($row->{key3}, 3);
2615

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2616
test 'update and id option';
2617
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2618
$dbi->execute($CREATE_TABLE->{1});
2619
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2620
$dbi->update(
2621
    table => 'table1',
2622
    primary_key => ['key1', 'key2'],
2623
    id => [1, 2],
2624
    param => {key3 => 4}
2625
);
2626
is($dbi->select(table => 'table1')->one->{key1}, 1);
2627
is($dbi->select(table => 'table1')->one->{key2}, 2);
2628
is($dbi->select(table => 'table1')->one->{key3}, 4);
2629

            
2630
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2631
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2632
$dbi->update(
2633
    table => 'table1',
2634
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2635
    id => 0,
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2636
    param => {key3 => 4}
2637
);
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2638
is($dbi->select(table => 'table1')->one->{key1}, 0);
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2639
is($dbi->select(table => 'table1')->one->{key2}, 2);
2640
is($dbi->select(table => 'table1')->one->{key3}, 4);
2641

            
2642
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2643
$dbi->execute($CREATE_TABLE->{1});
2644
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2645
$dbi->update(
2646
    {key3 => 4},
2647
    table => 'table1',
2648
    primary_key => ['key1', 'key2'],
2649
    id => [1, 2]
2650
);
2651
is($dbi->select(table => 'table1')->one->{key1}, 1);
2652
is($dbi->select(table => 'table1')->one->{key2}, 2);
2653
is($dbi->select(table => 'table1')->one->{key3}, 4);
2654

            
2655

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2656
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2657
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2658
$dbi->execute($CREATE_TABLE->{1});
2659
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2660
$dbi->model('table1')->update(
2661
    id => [1, 2],
2662
    param => {key3 => 4}
2663
);
2664
$result = $dbi->model('table1')->select;
2665
$row = $result->one;
2666
is($row->{key1}, 1);
2667
is($row->{key2}, 2);
2668
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2669

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

            
2671
test 'delete and id option';
2672
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2673
$dbi->execute($CREATE_TABLE->{1});
2674
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2675
$dbi->delete(
2676
    table => 'table1',
2677
    primary_key => ['key1', 'key2'],
2678
    id => [1, 2],
2679
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2680
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2681

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2682
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2683
$dbi->delete(
2684
    table => 'table1',
2685
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2686
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2687
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2688
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2689

            
2690

            
2691
test 'model delete and id option';
2692
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2693
$dbi->execute($CREATE_TABLE->{1});
2694
$dbi->execute("create table table2 (key1, key2, key3)");
2695
$dbi->execute("create table table3 (key1, key2, key3)");
2696
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2697
$dbi->model('table1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2698
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2699
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2700
$dbi->model('table1_1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2701
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2702
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2703
$dbi->model('table1_3')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2704
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2705

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

            
2707
test 'select and id option';
2708
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2709
$dbi->execute($CREATE_TABLE->{1});
2710
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2711
$result = $dbi->select(
2712
    table => 'table1',
2713
    primary_key => ['key1', 'key2'],
2714
    id => [1, 2]
2715
);
2716
$row = $result->one;
2717
is($row->{key1}, 1);
2718
is($row->{key2}, 2);
2719
is($row->{key3}, 3);
2720

            
2721
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2722
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2723
$result = $dbi->select(
2724
    table => 'table1',
2725
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2726
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2727
);
2728
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2729
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2730
is($row->{key2}, 2);
2731
is($row->{key3}, 3);
2732

            
2733
$dbi->delete_all(table => 'table1');
2734
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2735
$result = $dbi->select(
2736
    table => 'table1',
2737
    primary_key => ['key1', 'key2'],
2738
    id => [1, 2]
2739
);
2740
$row = $result->one;
2741
is($row->{key1}, 1);
2742
is($row->{key2}, 2);
2743
is($row->{key3}, 3);
2744

            
2745

            
2746
test 'model select_at';
2747
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2748
$dbi->execute($CREATE_TABLE->{1});
2749
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2750
$result = $dbi->model('table1')->select(id => [1, 2]);
2751
$row = $result->one;
2752
is($row->{key1}, 1);
2753
is($row->{key2}, 2);
2754
is($row->{key3}, 3);
2755

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2756
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2757
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2758
$dbi->execute($CREATE_TABLE->{0});
2759
$dbi->execute($CREATE_TABLE->{2});
2760
$dbi->setup_model;
2761
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2762
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2763
$model = $dbi->model('table1');
2764
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2765
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2766
    where => {'table1.key1' => 1}
2767
);
2768
is_deeply($result->one,
2769
          {'table2.key1' => 1, 'table2.key3' => 3});
2770

            
2771
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2772
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2773
    where => {'table1.key1' => 1}
2774
);
2775
is_deeply($result->one,
2776
          {'table2.key1' => 1, 'table2.key3' => 3});
2777

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

            
2779
test 'type_rule from';
2780
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2781
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2782
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2783
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2784
    }
2785
);
2786
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2787
$dbi->insert({key1 => 'a'}, table => 'table1');
2788
$result = $dbi->select(table => 'table1');
2789
is($result->fetch_first->[0], 'A');
2790

            
2791
$result = $dbi->select(table => 'table1');
2792
is($result->one->{key1}, 'A');
2793

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

            
2795
test 'type_rule into';
2796
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2797
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2798
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2799
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2800
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2801
    }
2802
);
2803
$dbi->insert({key1 => 'a'}, table => 'table1');
2804
$result = $dbi->select(table => 'table1');
2805
is($result->one->{key1}, 'A');
2806

            
2807
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2808
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2809
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2810
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2811
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2812
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2813
);
2814
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2815
$result = $dbi->select(table => 'table1');
2816
$row = $result->one;
2817
is($row->{key1}, 'A');
2818
is($row->{key2}, 'B');
2819

            
2820
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2821
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2822
$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1');
2823
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2824
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2825
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2826
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2827
);
2828
$result = $dbi->execute(
2829
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2830
    param => {key1 => 'a', 'table1.key2' => 'b'}
2831
);
2832
$row = $result->one;
2833
is($row->{key1}, 'a');
2834
is($row->{key2}, 'B');
2835

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

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2853
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2854
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2855
$dbi->register_filter(twice => sub { $_[0] * 2 });
2856
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2857
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2858
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2859
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2860
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2861
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2862
    }
2863
);
2864
$dbi->insert({key1 => 2}, table => 'table1');
2865
$result = $dbi->select(table => 'table1');
2866
is($result->fetch->[0], 8);
2867

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2868
test 'type_rule and filter order';
2869
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2870
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2871
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2872
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2873
        date => sub { $_[0] . 'b' }
2874
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2875
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2876
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2877
    },
2878
    from1 => {
2879
        date => sub { $_[0] . 'd' }
2880
    },
2881
    from2 => {
2882
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2883
    }
2884
);
2885
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2886
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2887
$result->filter(key1 => sub { $_[0] . 'f' });
2888
is($result->fetch_first->[0], '1abcdef');
2889

            
2890
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2891
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2892
$dbi->type_rule(
2893
    from1 => {
2894
        date => sub { $_[0] . 'p' }
2895
    },
2896
    from2 => {
2897
        date => sub { $_[0] . 'q' }
2898
    },
2899
);
2900
$dbi->insert({key1 => '1'}, table => 'table1');
2901
$result = $dbi->select(table => 'table1');
2902
$result->type_rule(
2903
    from1 => {
2904
        date => sub { $_[0] . 'd' }
2905
    },
2906
    from2 => {
2907
        date => sub { $_[0] . 'e' }
2908
    }
2909
);
2910
$result->filter(key1 => sub { $_[0] . 'f' });
2911
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2912

            
2913
test 'type_rule_off';
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
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2918
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2919
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2920
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2921
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2922
    }
2923
);
2924
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2925
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2926
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2927

            
2928
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2929
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2930
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2931
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2932
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2933
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2934
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2935
        date => sub { $_[0] * 3 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2936
    }
2937
);
2938
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2939
$result = $dbi->select(table => 'table1', type_rule_off => 1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2940
is($result->one->{key1}, 4);
2941

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

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

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

            
2982
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2983
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2984
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2985
    }
2986
)};
2987
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
2988

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2989
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2990
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2991
eval {
2992
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2993
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2994
            Date => sub { $_[0] * 2 },
2995
        }
2996
    );
2997
};
2998
like($@, qr/lower/);
2999

            
3000
eval {
3001
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3002
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3003
            Date => sub { $_[0] * 2 },
3004
        }
3005
    );
3006
};
3007
like($@, qr/lower/);
3008

            
3009
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3010
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3011
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3012
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3013
        date => sub { $_[0] * 2 },
3014
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3015
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3016
        date => sub { $_[0] * 3 },
3017
    }
3018
);
3019
$dbi->insert({key1 => 2}, table => 'table1');
3020
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3021
$result->type_rule_off;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3022
is($result->one->{key1}, 6);
3023

            
3024
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3025
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3026
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3027
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3028
        date => sub { $_[0] * 2 },
3029
        datetime => sub { $_[0] * 4 },
3030
    },
3031
);
3032
$dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3033
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3034
$result->type_rule(
3035
    from1 => {
3036
        date => sub { $_[0] * 3 }
3037
    }
3038
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3039
$row = $result->one;
3040
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3041
is($row->{key2}, 2);
3042

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3043
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3044
$result->type_rule(
3045
    from1 => {
3046
        date => sub { $_[0] * 3 }
3047
    }
3048
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3049
$row = $result->one;
3050
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3051
is($row->{key2}, 2);
3052

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3053
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3054
$result->type_rule(
3055
    from1 => {
3056
        date => sub { $_[0] * 3 }
3057
    }
3058
);
cleanup
Yuki Kimoto authored on 2011-06-15
3059
$row = $result->one;
3060
is($row->{key1}, 6);
3061
is($row->{key2}, 2);
3062
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3063
$result->type_rule(
3064
    from1 => [date => sub { $_[0] * 3 }]
3065
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3066
$row = $result->one;
3067
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3068
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3069
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3070
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3071
$result->type_rule(
3072
    from1 => [date => 'fivetimes']
3073
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3074
$row = $result->one;
3075
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3076
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3077
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3078
$result->type_rule(
3079
    from1 => [date => undef]
3080
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3081
$row = $result->one;
3082
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3083
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3084

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3085
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3086
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3087
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3088
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3089
        date => sub { $_[0] * 2 },
3090
    },
3091
);
3092
$dbi->insert({key1 => 2}, table => 'table1');
3093
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3094
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3095
is($result->one->{key1}, 12);
3096

            
3097
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3098
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3099
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3100
    from1 => {
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3101
        date => sub { $_[0] * 2 },
3102
    },
3103
);
3104
$dbi->insert({key1 => 2}, table => 'table1');
3105
$result = $dbi->select(table => 'table1');
3106
$result->filter(key1 => sub { $_[0] * 3 });
3107
is($result->fetch->[0], 12);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3108

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3109
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3110
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3111
$dbi->type_rule(
3112
    into1 => {
3113
        date => sub { $_[0] . 'b' }
3114
    },
3115
    into2 => {
3116
        date => sub { $_[0] . 'c' }
3117
    },
3118
    from1 => {
3119
        date => sub { $_[0] . 'd' }
3120
    },
3121
    from2 => {
3122
        date => sub { $_[0] . 'e' }
3123
    }
3124
);
3125
$dbi->insert({key1 => '1'}, table => 'table1', type_rule_off => 1);
3126
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3127
is($result->type_rule_off->fetch_first->[0], '1');
3128
$result = $dbi->select(table => 'table1');
3129
is($result->type_rule_on->fetch_first->[0], '1de');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3130

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

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

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3175
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3176
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3177
$dbi->execute($CREATE_TABLE->{0});
3178
$dbi->execute($CREATE_TABLE->{2});
3179

            
3180
$dbi->create_model(
3181
    table => 'table1',
3182
    join => [
3183
       'left outer join table2 on table1.key1 = table2.key1'
3184
    ],
3185
    primary_key => ['key1'],
3186
);
3187
$model2 = $dbi->create_model(
3188
    table => 'table2',
3189
);
3190
$dbi->setup_model;
3191
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3192
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3193
$model = $dbi->model('table1');
3194
$result = $model->select(
3195
    column => [
3196
        $model->mycolumn,
3197
        {table2 => [qw/key1 key3/]}
3198
    ],
3199
    where => {'table1.key1' => 1}
3200
);
3201
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3202
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3203
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3204

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3205
$dbi->separator('__');
3206
$model = $dbi->model('table1');
3207
$result = $model->select(
3208
    column => [
3209
        $model->mycolumn,
3210
        {table2 => [qw/key1 key3/]}
3211
    ],
3212
    where => {'table1.key1' => 1}
3213
);
3214
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3215
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3216
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3217

            
cleanup
Yuki Kimoto authored on 2011-06-13
3218
$dbi->separator('-');
3219
$model = $dbi->model('table1');
3220
$result = $model->select(
3221
    column => [
3222
        $model->mycolumn,
3223
        {table2 => [qw/key1 key3/]}
3224
    ],
3225
    where => {'table1.key1' => 1}
3226
);
3227
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3228
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3229
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3230

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3232
test 'filter_off';
3233
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3234
$dbi->execute($CREATE_TABLE->{0});
3235
$dbi->execute($CREATE_TABLE->{2});
3236

            
3237
$dbi->create_model(
3238
    table => 'table1',
3239
    join => [
3240
       'left outer join table2 on table1.key1 = table2.key1'
3241
    ],
3242
    primary_key => ['key1'],
3243
);
3244
$dbi->setup_model;
3245
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3246
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3247
$result = $model->select(column => 'key1');
3248
$result->filter(key1 => sub { $_[0] * 2 });
3249
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3250

            
3251
test 'available_date_type';
3252
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3253
ok($dbi->can('available_data_type'));
3254

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

            
3256
test 'select prefix option';
3257
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3258
$dbi->execute($CREATE_TABLE->{0});
3259
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3260
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3261
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3262

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

            
3264
test 'separator';
3265
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3266
is($dbi->separator, '.');
3267
$dbi->separator('-');
3268
is($dbi->separator, '-');
3269
$dbi->separator('__');
3270
is($dbi->separator, '__');
3271
eval { $dbi->separator('?') };
3272
like($@, qr/Separator/);
3273

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

            
3275
test 'map_param';
3276
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3277
$param = $dbi->map_param(
3278
    {id => 1, author => 'Ken', price => 1900},
3279
    id => 'book.id',
3280
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3281
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3282
);
3283
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3284
  'book.price' => 1900});
3285

            
3286
$param = $dbi->map_param(
3287
    {id => 0, author => 0, price => 0},
3288
    id => 'book.id',
3289
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3290
    price => ['book.price', sub { '%' . $_[0] . '%' },
3291
      {if => sub { $_[0] eq 0 }}]
3292
);
3293
is_deeply($param, {'book.id' => 0, 'book.author' => '%0%', 'book.price' => '%0%'});
3294

            
3295
$param = $dbi->map_param(
3296
    {id => '', author => '', price => ''},
3297
    id => 'book.id',
3298
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3299
    price => ['book.price', sub { '%' . $_[0] . '%' },
3300
      {if => sub { $_[0] eq 1 }}]
3301
);
3302
is_deeply($param, {});
3303

            
3304
$param = $dbi->map_param(
3305
    {id => undef, author => undef, price => undef},
3306
    id => 'book.id',
3307
    price => ['book.price', {if => 'exists'}]
3308
);
3309
is_deeply($param, {'book.price' => undef});
3310

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

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

            
3319
test 'table_alias';
3320
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3321
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3322
$dbi->type_rule(
3323
    into1 => {
3324
        date => sub { uc $_[0] }
3325
    }
3326
);
3327
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3328
  table_alias => {table2 => 'table1'});
3329
$result = $dbi->select(table => 'table1');
3330
is($result->one->{key1}, 'A');
3331

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

            
3333
test 'order';
3334
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3335
{
3336
    $dbi->execute("create table table1 (key1, key2)");
3337
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3338
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3339
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3340
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3341
    my $order = $dbi->order;
3342
    $order->prepend('key1', 'key2 desc');
3343
    $result = $dbi->select(table => 'table1', append => "$order");
3344
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3345
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3346
    $order->prepend('key1 desc');
3347
    $result = $dbi->select(table => 'table1', append => "$order");
3348
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3349
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
added DBIx::Cusotm::Order pr...
Yuki Kimoto authored on 2011-07-11
3350

            
3351
    $order = $dbi->order;
3352
    $order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
3353
    $result = $dbi->select(table => 'table1',
3354
      column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
3355
      append => "$order");
3356
    is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
3357
      {'table1-key1' => 1, 'table1-key2' => 1},
3358
      {'table1-key1' => 2, 'table1-key2' => 4},
3359
      {'table1-key1' => 2, 'table1-key2' => 2}]);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3360
}
3361

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3362
test 'tag_parse';
3363
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3364
$dbi->tag_parse(0);
3365
{
3366
    $dbi->execute("create table table1 (key1, key2)");
3367
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3368
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3369
    ok($@);
3370
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3371

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3372
test 'last_sql';
3373
{
3374
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3375
    $dbi->execute("create table table1 (key1, key2)");
3376
    $dbi->execute('select * from table1');
3377
    is($dbi->last_sql, 'select * from table1;');
3378
    
3379
    eval{$dbi->execute("aaa")};
3380
    is($dbi->last_sql, 'aaa;');
3381
    
3382
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3383

            
3384
test 'DBIx::Custom header';
3385
{
3386
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3387
    $dbi->execute("create table table1 (key1, key2)");
3388
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3389
    
3390
    is_deeply($result->header, [qw/h1 h2/]);
3391
    
3392
}
3393

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