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

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
353
eval{$dbi->update(table => 'table1', 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

            
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
486
eval{$dbi->delete(table => 'table1', 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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2171
test 'mycolumn';
2172
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2173
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2174
$dbi->execute($CREATE_TABLE->{2});
2175
$dbi->setup_model;
2176
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2177
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2178
$model = $dbi->model('table1');
2179
$result = $model->select_at(
2180
    column => [
2181
        $model->mycolumn,
2182
        $model->column('table2')
2183
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2184
);
added tests
Yuki Kimoto authored on 2011-06-08
2185
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2186
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2187

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2188
$result = $model->select_at(
2189
    column => [
2190
        $model->mycolumn(['key1']),
2191
        $model->column(table2 => ['key1'])
2192
    ]
2193
);
added tests
Yuki Kimoto authored on 2011-06-08
2194
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2195
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2196
$result = $model->select_at(
2197
    column => [
2198
        $model->mycolumn(['key1']),
2199
        {table2 => ['key1']}
2200
    ]
2201
);
added tests
Yuki Kimoto authored on 2011-06-08
2202
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2203
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2204

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2205
$result = $model->select_at(
2206
    column => [
2207
        $model->mycolumn(['key1']),
2208
        ['table2.key1', as => 'table2.key1']
2209
    ]
2210
);
2211
is_deeply($result->one,
2212
          {key1 => 1, 'table2.key1' => 1});
2213

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2214
$result = $model->select_at(
2215
    column => [
2216
        $model->mycolumn(['key1']),
2217
        ['table2.key1' => 'table2.key1']
2218
    ]
2219
);
2220
is_deeply($result->one,
2221
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2222

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2223
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2224
{
2225
    package MyDBI9;
2226
    
2227
    use base 'DBIx::Custom';
2228
    
2229
    sub connect {
2230
        my $self = shift->SUPER::connect(@_);
2231
        
2232
        $self->include_model('MyModel8')->setup_model;
2233
        
2234
        return $self;
2235
    }
2236
}
2237
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2238
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2239
$model = $dbi->model('table1');
2240
eval{$model->execute('select * from table1')};
2241
ok(!$@);
2242

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2243
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2244
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2245
$dbi->execute($CREATE_TABLE->{0});
2246
$dbi->execute($CREATE_TABLE->{2});
2247
$dbi->setup_model;
2248
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2249
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2250
$model = $dbi->model('table1');
2251
$result = $model->select(
2252
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2253
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2254
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2255
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2256
);
added tests
Yuki Kimoto authored on 2011-06-08
2257
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2258
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2259

            
cleanup
Yuki Kimoto authored on 2011-06-13
2260
$dbi->separator('__');
2261
$result = $model->select(
2262
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2263
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2264
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2265
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2266
);
2267
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2268
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2269

            
2270
$dbi->separator('-');
2271
$result = $model->select(
2272
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2273
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2274
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2275
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2276
);
2277
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2278
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2279

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2280
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2281
$dbi = DBIx::Custom->connect(
2282
    data_source => 'dbi:SQLite:dbname=:memory:',
2283
    dbi_option => {
2284
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2285
    }
2286
);
2287
my $binary = pack("I3", 1, 2, 3);
2288
$dbi->execute('create table table1(key1, key2)');
2289
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2290
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2291
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2292
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2293
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2294
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2295
is($row->{key1_length}, length $binary);
2296

            
2297
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2298
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2299
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2300
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2301
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2302
$row = $result->one;
2303
is($row->{key1_length}, length $binary);
2304

            
2305

            
2306
test 'bind_type option';
2307
$dbi = DBIx::Custom->connect(
2308
    data_source => 'dbi:SQLite:dbname=:memory:',
2309
    dbi_option => {
2310
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2311
    }
2312
);
2313
$binary = pack("I3", 1, 2, 3);
2314
$dbi->execute('create table table1(key1, key2)');
2315
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2316
$result = $dbi->select(table => 'table1');
2317
$row   = $result->one;
2318
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2319
$result = $dbi->execute('select length(key1) as key1_length from table1');
2320
$row = $result->one;
2321
is($row->{key1_length}, length $binary);
2322

            
2323
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2324
$result = $dbi->select(table => 'table1');
2325
$row   = $result->one;
2326
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2327
$result = $dbi->execute('select length(key1) as key1_length from table1');
2328
$row = $result->one;
2329
is($row->{key1_length}, length $binary);
2330

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2349
test 'create_model';
2350
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2351
$dbi->execute($CREATE_TABLE->{0});
2352
$dbi->execute($CREATE_TABLE->{2});
2353

            
2354
$dbi->create_model(
2355
    table => 'table1',
2356
    join => [
2357
       'left outer join table2 on table1.key1 = table2.key1'
2358
    ],
2359
    primary_key => ['key1']
2360
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2361
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2362
    table => 'table2'
2363
);
2364
$dbi->create_model(
2365
    table => 'table3',
2366
    filter => [
2367
        key1 => {in => sub { uc $_[0] }}
2368
    ]
2369
);
2370
$dbi->setup_model;
2371
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2372
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2373
$model = $dbi->model('table1');
2374
$result = $model->select(
2375
    column => [$model->mycolumn, $model->column('table2')],
2376
    where => {'table1.key1' => 1}
2377
);
added tests
Yuki Kimoto authored on 2011-06-08
2378
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2379
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2380
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2381

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2382
test 'model method';
2383
test 'create_model';
2384
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2385
$dbi->execute($CREATE_TABLE->{2});
2386
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2387
$model = $dbi->create_model(
2388
    table => 'table2'
2389
);
2390
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2391
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2392

            
2393
test 'merge_param';
2394
{
2395
    my $dbi = DBIx::Custom->new;
2396
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2397
    my $param2 = {key1 => 1, key2 => 2};
2398
    my $param3 = {key1 => 1};
2399
    my $param = $dbi->merge_param($param1, $param2, $param3);
2400
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2401
}
2402

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2403
{
2404
    my $dbi = DBIx::Custom->new;
2405
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2406
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2407
    my $param = $dbi->merge_param($param1, $param2);
2408
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2409
}
2410

            
cleanup
Yuki Kimoto authored on 2011-04-01
2411
test 'select() param option';
2412
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2413
$dbi->execute($CREATE_TABLE->{0});
2414
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2415
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2416
$dbi->execute($CREATE_TABLE->{2});
2417
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2418
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2419
$rows = $dbi->select(
2420
    table => 'table1',
2421
    column => 'table1.key1 as table1_key1, key2, key3',
2422
    where   => {'table1.key2' => 3},
2423
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2424
              ' as table2 on table1.key1 = table2.key1'],
2425
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2426
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2427
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2428

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

            
2430
test 'select() wrap option';
2431
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2432
$dbi->execute($CREATE_TABLE->{0});
2433
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2434
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2435
$rows = $dbi->select(
2436
    table => 'table1',
2437
    column => 'key1',
2438
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2439
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2440
is_deeply($rows, [{key1 => 1}]);
2441

            
2442
eval {
2443
$dbi->select(
2444
    table => 'table1',
2445
    column => 'key1',
2446
    wrap => 'select * from ('
2447
)
2448
};
cleanup
Yuki Kimoto authored on 2011-04-25
2449
like($@, qr/array/);
2450

            
2451
test 'select() string where';
2452
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2453
$dbi->execute($CREATE_TABLE->{0});
2454
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2455
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2456
$rows = $dbi->select(
2457
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2458
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2459
    where_param => {key1 => 1, key2 => 2}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2460
)->all;
cleanup
Yuki Kimoto authored on 2011-04-25
2461
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2462

            
updated pod
Yuki Kimoto authored on 2011-06-21
2463
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2464
$dbi->execute($CREATE_TABLE->{0});
2465
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2466
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2467
$rows = $dbi->select(
2468
    table => 'table1',
2469
    where => [
2470
        'key1 = :key1 and key2 = :key2',
2471
        {key1 => 1, key2 => 2}
2472
    ]
2473
)->all;
2474
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2475

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

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

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

            
2504
test 'update() string where';
2505
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2506
$dbi->execute($CREATE_TABLE->{0});
2507
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2508
$dbi->update(
2509
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2510
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2511
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2512
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2513
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2514
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2515
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2516

            
updated pod
Yuki Kimoto authored on 2011-06-21
2517
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2518
$dbi->execute($CREATE_TABLE->{0});
2519
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2520
$dbi->update(
2521
    table => 'table1',
2522
    param => {key1 => 5},
2523
    where => [
2524
        'key1 = :key1 and key2 = :key2',
2525
        {key1 => 1, key2 => 2}
2526
    ]
2527
);
2528
$rows = $dbi->select(table => 'table1')->all;
2529
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2530

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2531
test 'insert id and primary_key option';
2532
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2533
$dbi->execute($CREATE_TABLE->{1});
2534
$dbi->insert(
2535
    primary_key => ['key1', 'key2'], 
2536
    table => 'table1',
2537
    id => [1, 2],
2538
    param => {key3 => 3}
2539
);
2540
is($dbi->select(table => 'table1')->one->{key1}, 1);
2541
is($dbi->select(table => 'table1')->one->{key2}, 2);
2542
is($dbi->select(table => 'table1')->one->{key3}, 3);
2543

            
2544
$dbi->delete_all(table => 'table1');
2545
$dbi->insert(
2546
    primary_key => 'key1', 
2547
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2548
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2549
    param => {key2 => 2, key3 => 3}
2550
);
2551

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

            
2556
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2557
$dbi->execute($CREATE_TABLE->{1});
2558
$dbi->insert(
2559
    {key3 => 3},
2560
    primary_key => ['key1', 'key2'], 
2561
    table => 'table1',
2562
    id => [1, 2],
2563
);
2564
is($dbi->select(table => 'table1')->one->{key1}, 1);
2565
is($dbi->select(table => 'table1')->one->{key2}, 2);
2566
is($dbi->select(table => 'table1')->one->{key3}, 3);
2567

            
cleanup
Yuki Kimoto authored on 2011-06-08
2568

            
added tests
Yuki Kimoto authored on 2011-06-08
2569
test 'model insert id and primary_key option';
2570
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2571
$dbi->execute($CREATE_TABLE->{1});
2572
$dbi->model('table1')->insert(
2573
    id => [1, 2],
2574
    param => {key3 => 3}
2575
);
2576
$result = $dbi->model('table1')->select;
2577
$row = $result->one;
2578
is($row->{key1}, 1);
2579
is($row->{key2}, 2);
2580
is($row->{key3}, 3);
2581

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2582
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2583
$dbi->execute($CREATE_TABLE->{1});
2584
$dbi->model('table1')->insert(
2585
    {key3 => 3},
2586
    id => [1, 2]
2587
);
2588
$result = $dbi->model('table1')->select;
2589
$row = $result->one;
2590
is($row->{key1}, 1);
2591
is($row->{key2}, 2);
2592
is($row->{key3}, 3);
2593

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

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

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

            
2633

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

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

            
2649
test 'delete and id option';
2650
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2651
$dbi->execute($CREATE_TABLE->{1});
2652
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2653
$dbi->delete(
2654
    table => 'table1',
2655
    primary_key => ['key1', 'key2'],
2656
    id => [1, 2],
2657
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2658
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2659

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2660
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2661
$dbi->delete(
2662
    table => 'table1',
2663
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2664
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2665
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2666
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2667

            
2668

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

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

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

            
2699
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2700
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2701
$result = $dbi->select(
2702
    table => 'table1',
2703
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2704
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2705
);
2706
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2707
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2708
is($row->{key2}, 2);
2709
is($row->{key3}, 3);
2710

            
2711
$dbi->delete_all(table => 'table1');
2712
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2713
$result = $dbi->select(
2714
    table => 'table1',
2715
    primary_key => ['key1', 'key2'],
2716
    id => [1, 2]
2717
);
2718
$row = $result->one;
2719
is($row->{key1}, 1);
2720
is($row->{key2}, 2);
2721
is($row->{key3}, 3);
2722

            
2723

            
2724
test 'model select_at';
2725
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2726
$dbi->execute($CREATE_TABLE->{1});
2727
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2728
$result = $dbi->model('table1')->select(id => [1, 2]);
2729
$row = $result->one;
2730
is($row->{key1}, 1);
2731
is($row->{key2}, 2);
2732
is($row->{key3}, 3);
2733

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2734
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2735
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2736
$dbi->execute($CREATE_TABLE->{0});
2737
$dbi->execute($CREATE_TABLE->{2});
2738
$dbi->setup_model;
2739
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2740
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2741
$model = $dbi->model('table1');
2742
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2743
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2744
    where => {'table1.key1' => 1}
2745
);
2746
is_deeply($result->one,
2747
          {'table2.key1' => 1, 'table2.key3' => 3});
2748

            
2749
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2750
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2751
    where => {'table1.key1' => 1}
2752
);
2753
is_deeply($result->one,
2754
          {'table2.key1' => 1, 'table2.key3' => 3});
2755

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

            
2757
test 'type_rule from';
2758
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2759
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2760
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2761
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2762
    }
2763
);
2764
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2765
$dbi->insert({key1 => 'a'}, table => 'table1');
2766
$result = $dbi->select(table => 'table1');
2767
is($result->fetch_first->[0], 'A');
2768

            
2769
$result = $dbi->select(table => 'table1');
2770
is($result->one->{key1}, 'A');
2771

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

            
2773
test 'type_rule into';
2774
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2775
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2776
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2777
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2778
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2779
    }
2780
);
2781
$dbi->insert({key1 => 'a'}, table => 'table1');
2782
$result = $dbi->select(table => 'table1');
2783
is($result->one->{key1}, 'A');
2784

            
2785
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2786
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2787
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2788
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2789
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2790
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2791
);
2792
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2793
$result = $dbi->select(table => 'table1');
2794
$row = $result->one;
2795
is($row->{key1}, 'A');
2796
is($row->{key2}, 'B');
2797

            
2798
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2799
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2800
$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1');
2801
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2802
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2803
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2804
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2805
);
2806
$result = $dbi->execute(
2807
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2808
    param => {key1 => 'a', 'table1.key2' => 'b'}
2809
);
2810
$row = $result->one;
2811
is($row->{key1}, 'a');
2812
is($row->{key2}, 'B');
2813

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

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2831
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2832
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2833
$dbi->register_filter(twice => sub { $_[0] * 2 });
2834
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2835
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2836
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2837
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2838
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2839
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2840
    }
2841
);
2842
$dbi->insert({key1 => 2}, table => 'table1');
2843
$result = $dbi->select(table => 'table1');
2844
is($result->fetch->[0], 8);
2845

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2846
test 'type_rule and filter order';
2847
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2848
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2849
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2850
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2851
        date => sub { $_[0] . 'b' }
2852
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2853
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2854
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2855
    },
2856
    from1 => {
2857
        date => sub { $_[0] . 'd' }
2858
    },
2859
    from2 => {
2860
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2861
    }
2862
);
2863
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2864
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2865
$result->filter(key1 => sub { $_[0] . 'f' });
2866
is($result->fetch_first->[0], '1abcdef');
2867

            
2868
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2869
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2870
$dbi->type_rule(
2871
    from1 => {
2872
        date => sub { $_[0] . 'p' }
2873
    },
2874
    from2 => {
2875
        date => sub { $_[0] . 'q' }
2876
    },
2877
);
2878
$dbi->insert({key1 => '1'}, table => 'table1');
2879
$result = $dbi->select(table => 'table1');
2880
$result->type_rule(
2881
    from1 => {
2882
        date => sub { $_[0] . 'd' }
2883
    },
2884
    from2 => {
2885
        date => sub { $_[0] . 'e' }
2886
    }
2887
);
2888
$result->filter(key1 => sub { $_[0] . 'f' });
2889
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2890

            
2891
test 'type_rule_off';
2892
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2893
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2894
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2895
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2896
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2897
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2898
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2899
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2900
    }
2901
);
2902
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2903
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2904
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2905

            
2906
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2907
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2908
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2909
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2910
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2911
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2912
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2913
        date => sub { $_[0] * 3 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2914
    }
2915
);
2916
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2917
$result = $dbi->select(table => 'table1', type_rule_off => 1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2918
is($result->one->{key1}, 4);
2919

            
2920
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2921
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2922
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2923
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2924
        date => sub { $_[0] * 2 },
2925
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2926
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2927
        date => sub { $_[0] * 3 },
2928
    }
2929
);
2930
$dbi->insert({key1 => 2}, table => 'table1');
2931
$result = $dbi->select(table => 'table1');
2932
is($result->one->{key1}, 12);
2933

            
2934
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2935
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2936
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2937
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2938
        date => sub { $_[0] * 2 },
2939
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2940
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2941
        date => sub { $_[0] * 3 },
2942
    }
2943
);
2944
$dbi->insert({key1 => 2}, table => 'table1');
2945
$result = $dbi->select(table => 'table1');
2946
is($result->fetch->[0], 12);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2947

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2948
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2949
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2950
$dbi->register_filter(ppp => sub { uc $_[0] });
2951
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2952
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2953
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2954
    }
2955
);
2956
$dbi->insert({key1 => 'a'}, table => 'table1');
2957
$result = $dbi->select(table => 'table1');
2958
is($result->one->{key1}, 'A');
2959

            
2960
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2961
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2962
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2963
    }
2964
)};
2965
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
2966

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2967
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2968
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2969
eval {
2970
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2971
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2972
            Date => sub { $_[0] * 2 },
2973
        }
2974
    );
2975
};
2976
like($@, qr/lower/);
2977

            
2978
eval {
2979
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2980
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2981
            Date => sub { $_[0] * 2 },
2982
        }
2983
    );
2984
};
2985
like($@, qr/lower/);
2986

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3021
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3022
$result->type_rule(
3023
    from1 => {
3024
        date => sub { $_[0] * 3 }
3025
    }
3026
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3027
$row = $result->one;
3028
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3029
is($row->{key2}, 2);
3030

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3031
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3032
$result->type_rule(
3033
    from1 => {
3034
        date => sub { $_[0] * 3 }
3035
    }
3036
);
cleanup
Yuki Kimoto authored on 2011-06-15
3037
$row = $result->one;
3038
is($row->{key1}, 6);
3039
is($row->{key2}, 2);
3040
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3041
$result->type_rule(
3042
    from1 => [date => sub { $_[0] * 3 }]
3043
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3044
$row = $result->one;
3045
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3046
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3047
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3048
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3049
$result->type_rule(
3050
    from1 => [date => 'fivetimes']
3051
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3052
$row = $result->one;
3053
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3054
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3055
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3056
$result->type_rule(
3057
    from1 => [date => undef]
3058
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3059
$row = $result->one;
3060
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3061
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3062

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3063
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3064
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3065
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3066
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3067
        date => sub { $_[0] * 2 },
3068
    },
3069
);
3070
$dbi->insert({key1 => 2}, table => 'table1');
3071
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3072
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3073
is($result->one->{key1}, 12);
3074

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3087
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3088
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3089
$dbi->type_rule(
3090
    into1 => {
3091
        date => sub { $_[0] . 'b' }
3092
    },
3093
    into2 => {
3094
        date => sub { $_[0] . 'c' }
3095
    },
3096
    from1 => {
3097
        date => sub { $_[0] . 'd' }
3098
    },
3099
    from2 => {
3100
        date => sub { $_[0] . 'e' }
3101
    }
3102
);
3103
$dbi->insert({key1 => '1'}, table => 'table1', type_rule_off => 1);
3104
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3105
is($result->type_rule_off->fetch_first->[0], '1');
3106
$result = $dbi->select(table => 'table1');
3107
is($result->type_rule_on->fetch_first->[0], '1de');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3108

            
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_rule1_off => 1);
3126
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3127
is($result->type_rule1_off->fetch_first->[0], '1ce');
3128
$result = $dbi->select(table => 'table1');
3129
is($result->type_rule1_on->fetch_first->[0], '1cde');
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_rule2_off => 1);
3148
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3149
is($result->type_rule2_off->fetch_first->[0], '1bd');
3150
$result = $dbi->select(table => 'table1');
3151
is($result->type_rule2_on->fetch_first->[0], '1bde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3152

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3153
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3154
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3155
$dbi->execute($CREATE_TABLE->{0});
3156
$dbi->execute($CREATE_TABLE->{2});
3157

            
3158
$dbi->create_model(
3159
    table => 'table1',
3160
    join => [
3161
       'left outer join table2 on table1.key1 = table2.key1'
3162
    ],
3163
    primary_key => ['key1'],
3164
);
3165
$model2 = $dbi->create_model(
3166
    table => 'table2',
3167
);
3168
$dbi->setup_model;
3169
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3170
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3171
$model = $dbi->model('table1');
3172
$result = $model->select(
3173
    column => [
3174
        $model->mycolumn,
3175
        {table2 => [qw/key1 key3/]}
3176
    ],
3177
    where => {'table1.key1' => 1}
3178
);
3179
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3180
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3181
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3182

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3183
$dbi->separator('__');
3184
$model = $dbi->model('table1');
3185
$result = $model->select(
3186
    column => [
3187
        $model->mycolumn,
3188
        {table2 => [qw/key1 key3/]}
3189
    ],
3190
    where => {'table1.key1' => 1}
3191
);
3192
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3193
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3194
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3195

            
cleanup
Yuki Kimoto authored on 2011-06-13
3196
$dbi->separator('-');
3197
$model = $dbi->model('table1');
3198
$result = $model->select(
3199
    column => [
3200
        $model->mycolumn,
3201
        {table2 => [qw/key1 key3/]}
3202
    ],
3203
    where => {'table1.key1' => 1}
3204
);
3205
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3206
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3207
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3208

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3210
test 'filter_off';
3211
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3212
$dbi->execute($CREATE_TABLE->{0});
3213
$dbi->execute($CREATE_TABLE->{2});
3214

            
3215
$dbi->create_model(
3216
    table => 'table1',
3217
    join => [
3218
       'left outer join table2 on table1.key1 = table2.key1'
3219
    ],
3220
    primary_key => ['key1'],
3221
);
3222
$dbi->setup_model;
3223
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3224
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3225
$result = $model->select(column => 'key1');
3226
$result->filter(key1 => sub { $_[0] * 2 });
3227
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3228

            
3229
test 'available_date_type';
3230
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3231
ok($dbi->can('available_data_type'));
3232

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

            
3234
test 'select prefix option';
3235
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3236
$dbi->execute($CREATE_TABLE->{0});
3237
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3238
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3239
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3240

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

            
3242
test 'separator';
3243
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3244
is($dbi->separator, '.');
3245
$dbi->separator('-');
3246
is($dbi->separator, '-');
3247
$dbi->separator('__');
3248
is($dbi->separator, '__');
3249
eval { $dbi->separator('?') };
3250
like($@, qr/Separator/);
3251

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

            
3253
test 'map_param';
3254
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3255
$param = $dbi->map_param(
3256
    {id => 1, author => 'Ken', price => 1900},
3257
    id => 'book.id',
3258
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3259
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3260
);
3261
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3262
  'book.price' => 1900});
3263

            
3264
$param = $dbi->map_param(
3265
    {id => 0, author => 0, price => 0},
3266
    id => 'book.id',
3267
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3268
    price => ['book.price', sub { '%' . $_[0] . '%' },
3269
      {if => sub { $_[0] eq 0 }}]
3270
);
3271
is_deeply($param, {'book.id' => 0, 'book.author' => '%0%', 'book.price' => '%0%'});
3272

            
3273
$param = $dbi->map_param(
3274
    {id => '', author => '', price => ''},
3275
    id => 'book.id',
3276
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3277
    price => ['book.price', sub { '%' . $_[0] . '%' },
3278
      {if => sub { $_[0] eq 1 }}]
3279
);
3280
is_deeply($param, {});
3281

            
3282
$param = $dbi->map_param(
3283
    {id => undef, author => undef, price => undef},
3284
    id => 'book.id',
3285
    price => ['book.price', {if => 'exists'}]
3286
);
3287
is_deeply($param, {'book.price' => undef});
3288

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

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

            
3297
test 'table_alias';
3298
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3299
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3300
$dbi->type_rule(
3301
    into1 => {
3302
        date => sub { uc $_[0] }
3303
    }
3304
);
3305
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3306
  table_alias => {table2 => 'table1'});
3307
$result = $dbi->select(table => 'table1');
3308
is($result->one->{key1}, 'A');
3309

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

            
3311
test 'order';
3312
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3313
{
3314
    $dbi->execute("create table table1 (key1, key2)");
3315
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3316
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3317
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3318
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3319
    my $order = $dbi->order;
3320
    $order->prepend('key1', 'key2 desc');
3321
    $result = $dbi->select(table => 'table1', append => "$order");
3322
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3323
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3324
    $order->prepend('key1 desc');
3325
    $result = $dbi->select(table => 'table1', append => "$order");
3326
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3327
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
3328
}
3329

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3330
test 'tag_parse';
3331
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3332
$dbi->tag_parse(0);
3333
{
3334
    $dbi->execute("create table table1 (key1, key2)");
3335
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3336
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3337
    ok($@);
3338
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3339

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3340
test 'last_sql';
3341
{
3342
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3343
    $dbi->execute("create table table1 (key1, key2)");
3344
    $dbi->execute('select * from table1');
3345
    is($dbi->last_sql, 'select * from table1;');
3346
    
3347
    eval{$dbi->execute("aaa")};
3348
    is($dbi->last_sql, 'aaa;');
3349
    
3350
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3351

            
3352
test 'DBIx::Custom header';
3353
{
3354
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3355
    $dbi->execute("create table table1 (key1, key2)");
3356
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3357
    
3358
    is_deeply($result->header, [qw/h1 h2/]);
3359
    
3360
}
3361

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