DBIx-Custom / t / dbix-custom-core-sqlite.t /
Newer Older
3251 lines | 103.918kb
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 auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
908

            
add examples
Yuki Kimoto authored on 2011-01-07
909
test 'limit';
910
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
911
$dbi->execute($CREATE_TABLE->{0});
912
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
913
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
914
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
915
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
916
    limit => sub {
917
        my ($count, $offset) = @_;
918
        
919
        my $s = '';
920
        $s .= "limit $count";
921
        $s .= " offset $offset" if defined $offset;
922
        
923
        return [$s, []];
924
    }
925
);
926
$rows = $dbi->select(
927
  table => 'table1',
928
  where => {key1 => 1},
929
  append => "order by key2 {limit 1 0}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
930
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
931
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
932
$rows = $dbi->select(
933
  table => 'table1',
934
  where => {key1 => 1},
935
  append => "order by key2 {limit 2 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
936
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
937
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
938
$rows = $dbi->select(
939
  table => 'table1',
940
  where => {key1 => 1},
941
  append => "order by key2 {limit 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
942
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
943
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
944

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
945
test 'connect super';
946
{
947
    package MyDBI;
948
    
949
    use base 'DBIx::Custom';
950
    sub connect {
951
        my $self = shift->SUPER::connect(@_);
952
        
953
        return $self;
954
    }
955
    
956
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
957
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
958
        
959
        return $self;
960
    }
961
}
962

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
974
{
975
    package MyDBI2;
976
    
977
    use base 'DBIx::Custom';
978
    sub connect {
979
        my $self = shift->SUPER::new(@_);
980
        $self->connect;
981
        
982
        return $self;
983
    }
984
}
985

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

            
991
test 'end_filter';
992
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
993
$dbi->execute($CREATE_TABLE->{0});
994
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
995
$result = $dbi->select(table => 'table1');
996
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
997
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
998
$row = $result->fetch_first;
999
is_deeply($row, [6, 40]);
1000

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1001
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1002
$dbi->execute($CREATE_TABLE->{0});
1003
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1004
$result = $dbi->select(table => 'table1');
1005
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
1006
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
1007
$row = $result->fetch_first;
1008
is_deeply($row, [6, 12]);
1009

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

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1026
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1027
$dbi->apply_filter('table1',
1028
    key1 => {end => sub { $_[0] * 3 } },
1029
    key2 => {end => 'five_times'}
1030
);
1031
$result = $dbi->select(table => 'table1');
1032
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
added tests
Yuki Kimoto authored on 2011-06-08
1033
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1034
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
1035

            
1036
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1037
$dbi->apply_filter('table1',
1038
    key1 => {end => sub { $_[0] * 3 } },
1039
    key2 => {end => 'five_times'}
1040
);
1041
$result = $dbi->select(table => 'table1');
1042
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1043
$result->filter(key1 => undef);
1044
$result->end_filter(key1 => undef);
added tests
Yuki Kimoto authored on 2011-06-08
1045
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1046
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1047

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1048
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1049
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1050
$dbi->execute($CREATE_TABLE->{0});
1051
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1052
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1053
$row = $result
1054
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1055
       ->remove_filter
1056
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1057
       ->remove_end_filter
1058
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1059
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1060

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1061
test 'empty where select';
1062
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1063
$dbi->execute($CREATE_TABLE->{0});
1064
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1065
$result = $dbi->select(table => 'table1', where => {});
added tests
Yuki Kimoto authored on 2011-06-08
1066
$row = $result->one;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1067
is_deeply($row, {key1 => 1, key2 => 2});
1068

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1069
test 'select query option';
1070
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1071
$dbi->execute($CREATE_TABLE->{0});
1072
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1073
is(ref $query, 'DBIx::Custom::Query');
1074
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1075
is(ref $query, 'DBIx::Custom::Query');
1076
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1077
is(ref $query, 'DBIx::Custom::Query');
1078
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1079
is(ref $query, 'DBIx::Custom::Query');
1080

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1081
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1082
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1083
$dbi->execute($CREATE_TABLE->{0});
1084
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1085
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
updated pod
Yuki Kimoto authored on 2011-06-21
1086
$where = $dbi->where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
1087
is("$where", "where ( key1 = :key1 and key2 = :key2 )", 'no param');
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1088

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1093
$result = $dbi->select(
1094
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1095
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1096
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1097
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1098
is_deeply($row, [{key1 => 1, key2 => 2}]);
1099

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1100
$result = $dbi->select(
1101
    table => 'table1',
1102
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
1103
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1104
        {key1 => 1}
1105
    ]
1106
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1107
$row = $result->all;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1108
is_deeply($row, [{key1 => 1, key2 => 2}]);
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, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1113
$result = $dbi->select(
1114
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1115
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1116
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1117
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1118
is_deeply($row, [{key1 => 1, key2 => 2}]);
1119

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1120
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1121
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1122
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1123
$result = $dbi->select(
1124
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1125
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1126
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1127
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1128
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1129

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

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1148
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1149
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1150
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1151
$result = $dbi->select(
1152
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1153
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1154
);
1155
};
1156
ok($@);
1157

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

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

            
1171
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1172
             ->clause(['or', ('key1 = :key1') x 2])
added test
Yuki Kimoto authored on 2011-01-19
1173
             ->param({key1 => [1]});
1174
$result = $dbi->select(
1175
    table => 'table1',
1176
    where => $where,
1177
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1178
$row = $result->all;
added test
Yuki Kimoto authored on 2011-01-19
1179
is_deeply($row, [{key1 => 1, key2 => 2}]);
1180

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

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

            
1201
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1202
             ->clause('key1 = :key1 key2 = :key2')
many changed
Yuki Kimoto authored on 2011-01-23
1203
             ->param({key1 => 1});
1204
eval{$where->to_string};
1205
like($@, qr/one column/);
1206

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1207
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1208
             ->clause('key1 = :key1')
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1209
             ->param([]);
1210
eval{$where->to_string};
1211
like($@, qr/Parameter/);
1212

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

            
1223
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1224
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1225
             ->param({key1 => [1, $dbi->not_exists, 3]});
1226
$result = $dbi->select(
1227
    table => 'table1',
1228
    where => $where,
1229
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1230
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1231
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1232

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

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

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

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

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

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

            
1293
$where = $dbi->where
1294
             ->clause(['and', '{> key1}', '{< key1}' ])
1295
             ->param({key1 => [2, $dbi->not_exists]});
1296
$result = $dbi->select(
1297
    table => 'table1',
1298
    where => $where,
1299
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1300
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1301
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1302

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

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

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

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1333
$where = $dbi->where
1334
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1335
$result = $dbi->select(
1336
    table => 'table1',
1337
    where => $where,
1338
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1339
$row = $result->all;
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1340
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1341

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

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1349
test 'register_tag_processor';
1350
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1351
$dbi->register_tag_processor(
1352
    a => sub { 1 }
1353
);
1354
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1355

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1356
test 'register_tag';
1357
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1358
$dbi->register_tag(
1359
    b => sub { 2 }
1360
);
1361
is($dbi->query_builder->tags->{b}->(), 2);
1362

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1363
test 'table not specify exception';
1364
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1365
eval {$dbi->insert};
1366
like($@, qr/table/);
1367
eval {$dbi->update};
1368
like($@, qr/table/);
1369
eval {$dbi->delete};
1370
like($@, qr/table/);
1371
eval {$dbi->select};
1372
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1373

            
1374

            
1375
test 'more tests';
1376
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1377
eval{$dbi->apply_filter('table', 'column', [])};
1378
like($@, qr/apply_filter/);
1379

            
1380
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1381
like($@, qr/apply_filter/);
1382

            
1383
$dbi->apply_filter(
1384

            
1385
);
1386
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1387
$dbi->execute($CREATE_TABLE->{0});
1388
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1389
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1390
$dbi->apply_filter('table1', 'key2', 
1391
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1392
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1393
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1394

            
1395
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1396
$dbi->execute($CREATE_TABLE->{0});
1397
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1398
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1399
$dbi->apply_filter('table1', 'key2', {});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1400
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1401
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1402

            
1403
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1404
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1405
like($@, qr/not registered/);
1406
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1407
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1408
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1409
is($dbi->one, 1);
1410

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

            
1414
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1415
$dbi->execute($CREATE_TABLE->{0});
1416
$dbi->register_filter(twice => sub { $_[0] * 2 });
1417
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1418
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1419
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1420
is_deeply($row, {key1 => 2, key2 => 2});
1421
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1422
             filter => {key1 => 'no'}) };
1423
like($@, qr//);
1424

            
1425
$dbi->register_filter(one => sub { });
1426
$dbi->default_fetch_filter('one');
1427
ok($dbi->default_fetch_filter);
1428
$dbi->default_bind_filter('one');
1429
ok($dbi->default_bind_filter);
1430
eval{$dbi->default_fetch_filter('no')};
1431
like($@, qr/not registered/);
1432
eval{$dbi->default_bind_filter('no')};
1433
like($@, qr/not registered/);
1434
$dbi->default_bind_filter(undef);
1435
ok(!defined $dbi->default_bind_filter);
1436
$dbi->default_fetch_filter(undef);
1437
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1438
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1439
like($@, qr/Tag not finished/);
1440

            
1441
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1442
$dbi->execute($CREATE_TABLE->{0});
1443
$dbi->register_filter(one => sub { 1 });
1444
$result = $dbi->select(table => 'table1');
1445
eval {$result->filter(key1 => 'no')};
1446
like($@, qr/not registered/);
1447
eval {$result->end_filter(key1 => 'no')};
1448
like($@, qr/not registered/);
1449
$result->default_filter(undef);
1450
ok(!defined $result->default_filter);
1451
$result->default_filter('one');
1452
is($result->default_filter->(), 1);
1453

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1454
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1455
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1456
                             dbi_option => {PrintError => 1});
1457
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1458
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1459
                             dbi_options => {PrintError => 1});
1460
ok($dbi->dbh->{PrintError});
1461

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1462
test 'DBIx::Custom::Result stash()';
1463
$result = DBIx::Custom::Result->new;
1464
is_deeply($result->stash, {}, 'default');
1465
$result->stash->{foo} = 1;
1466
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1467

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1468
test 'filter __ expression';
1469
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1470
$dbi->execute('create table company (id, name, location_id)');
1471
$dbi->execute('create table location (id, name)');
1472
$dbi->apply_filter('location',
1473
  name => {in => sub { uc $_[0] } }
1474
);
1475

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

            
1479
$result = $dbi->select(
1480
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1481
    column => ['location.name as location__name']
1482
);
1483
is($result->fetch_first->[0], 'B');
1484

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1485
$result = $dbi->select(
1486
    table => 'company', relation => {'company.location_id' => 'location.id'},
1487
    column => ['location.name as location__name']
1488
);
1489
is($result->fetch_first->[0], 'B');
1490

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1491
$result = $dbi->select(
1492
    table => 'company', relation => {'company.location_id' => 'location.id'},
1493
    column => ['location.name as "location.name"']
1494
);
1495
is($result->fetch_first->[0], 'B');
1496

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1497
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1498
use MyDBI1;
1499
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1500
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1501
$model = $dbi->model('book');
1502
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1503
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1504
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1505
$model = $dbi->model('company');
1506
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1507
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1508
is($dbi->models->{'book'}, $dbi->model('book'));
1509
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1510

            
1511
{
1512
    package MyDBI4;
1513

            
1514
    use strict;
1515
    use warnings;
1516

            
1517
    use base 'DBIx::Custom';
1518

            
1519
    sub connect {
1520
        my $self = shift->SUPER::connect(@_);
1521
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1522
        $self->include_model(
1523
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1524
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1525
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1526
            ]
1527
        );
1528
    }
1529

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

            
1532
    use strict;
1533
    use warnings;
1534

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

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

            
1539
    use strict;
1540
    use warnings;
1541

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

            
1544
    sub insert {
1545
        my ($self, $param) = @_;
1546
        
1547
        return $self->SUPER::insert(param => $param);
1548
    }
1549

            
1550
    sub list { shift->select; }
1551

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

            
1554
    use strict;
1555
    use warnings;
1556

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

            
1559
    sub insert {
1560
        my ($self, $param) = @_;
1561
        
1562
        return $self->SUPER::insert(param => $param);
1563
    }
1564

            
1565
    sub list { shift->select; }
1566
}
1567
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1568
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1569
$model = $dbi->model('book');
1570
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1571
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1572
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1573
$model = $dbi->model('company');
1574
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1575
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1576

            
1577
{
1578
     package MyDBI5;
1579

            
1580
    use strict;
1581
    use warnings;
1582

            
1583
    use base 'DBIx::Custom';
1584

            
1585
    sub connect {
1586
        my $self = shift->SUPER::connect(@_);
1587
        
1588
        $self->include_model('MyModel4');
1589
    }
1590
}
1591
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1592
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1593
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1594
$model = $dbi->model('company');
1595
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1596
is_deeply($model->list->all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1597
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1598
$model = $dbi->model('book');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1599
is_deeply($model->list->all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1600

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1601
test 'primary_key';
1602
use MyDBI1;
1603
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1604
$model = $dbi->model('book');
1605
$model->primary_key(['id', 'number']);
1606
is_deeply($model->primary_key, ['id', 'number']);
1607

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1608
test 'columns';
1609
use MyDBI1;
1610
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1611
$model = $dbi->model('book');
1612
$model->columns(['id', 'number']);
1613
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1614

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1615
test 'setup_model';
1616
use MyDBI1;
1617
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1618
$dbi->execute('create table book (id)');
1619
$dbi->execute('create table company (id, name);');
1620
$dbi->execute('create table test (id, name, primary key (id, name));');
1621
$dbi->setup_model;
1622
is_deeply($dbi->model('book')->columns, ['id']);
1623
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1624

            
1625
test 'delete_at';
1626
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1627
$dbi->execute($CREATE_TABLE->{1});
1628
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1629
$dbi->delete_at(
1630
    table => 'table1',
1631
    primary_key => ['key1', 'key2'],
1632
    where => [1, 2],
1633
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1634
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1635

            
1636
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1637
$dbi->delete_at(
1638
    table => 'table1',
1639
    primary_key => 'key1',
1640
    where => 1,
1641
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1642
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1643

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1644
test 'insert_at';
1645
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1646
$dbi->execute($CREATE_TABLE->{1});
1647
$dbi->insert_at(
1648
    primary_key => ['key1', 'key2'], 
1649
    table => 'table1',
1650
    where => [1, 2],
1651
    param => {key3 => 3}
1652
);
added tests
Yuki Kimoto authored on 2011-06-08
1653
is($dbi->select(table => 'table1')->one->{key1}, 1);
1654
is($dbi->select(table => 'table1')->one->{key2}, 2);
1655
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1656

            
1657
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1658
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1659
$dbi->insert_at(
1660
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1661
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1662
    where => 1,
1663
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1664
);
1665

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

            
1670
eval {
1671
    $dbi->insert_at(
1672
        table => 'table1',
1673
        primary_key => ['key1', 'key2'],
1674
        where => {},
1675
        param => {key1 => 1, key2 => 2, key3 => 3},
1676
    );
1677
};
1678
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1679

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1680
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1681
$dbi->execute($CREATE_TABLE->{1});
1682
$dbi->insert_at(
1683
    {key3 => 3},
1684
    primary_key => ['key1', 'key2'], 
1685
    table => 'table1',
1686
    where => [1, 2],
1687
);
added tests
Yuki Kimoto authored on 2011-06-08
1688
is($dbi->select(table => 'table1')->one->{key1}, 1);
1689
is($dbi->select(table => 'table1')->one->{key2}, 2);
1690
is($dbi->select(table => 'table1')->one->{key3}, 3);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1691

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1692
test 'update_at';
1693
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1694
$dbi->execute($CREATE_TABLE->{1});
1695
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1696
$dbi->update_at(
1697
    table => 'table1',
1698
    primary_key => ['key1', 'key2'],
1699
    where => [1, 2],
1700
    param => {key3 => 4}
1701
);
added tests
Yuki Kimoto authored on 2011-06-08
1702
is($dbi->select(table => 'table1')->one->{key1}, 1);
1703
is($dbi->select(table => 'table1')->one->{key2}, 2);
1704
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1705

            
1706
$dbi->delete_all(table => 'table1');
1707
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1708
$dbi->update_at(
1709
    table => 'table1',
1710
    primary_key => 'key1',
1711
    where => 1,
1712
    param => {key3 => 4}
1713
);
added tests
Yuki Kimoto authored on 2011-06-08
1714
is($dbi->select(table => 'table1')->one->{key1}, 1);
1715
is($dbi->select(table => 'table1')->one->{key2}, 2);
1716
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1717

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1718
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1719
$dbi->execute($CREATE_TABLE->{1});
1720
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1721
$dbi->update_at(
1722
    {key3 => 4},
1723
    table => 'table1',
1724
    primary_key => ['key1', 'key2'],
1725
    where => [1, 2]
1726
);
added tests
Yuki Kimoto authored on 2011-06-08
1727
is($dbi->select(table => 'table1')->one->{key1}, 1);
1728
is($dbi->select(table => 'table1')->one->{key2}, 2);
1729
is($dbi->select(table => 'table1')->one->{key3}, 4);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1730

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1731
test 'select_at';
1732
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1733
$dbi->execute($CREATE_TABLE->{1});
1734
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1735
$result = $dbi->select_at(
1736
    table => 'table1',
1737
    primary_key => ['key1', 'key2'],
1738
    where => [1, 2]
1739
);
added tests
Yuki Kimoto authored on 2011-06-08
1740
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1741
is($row->{key1}, 1);
1742
is($row->{key2}, 2);
1743
is($row->{key3}, 3);
1744

            
1745
$dbi->delete_all(table => 'table1');
1746
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1747
$result = $dbi->select_at(
1748
    table => 'table1',
1749
    primary_key => 'key1',
1750
    where => 1,
1751
);
added tests
Yuki Kimoto authored on 2011-06-08
1752
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1753
is($row->{key1}, 1);
1754
is($row->{key2}, 2);
1755
is($row->{key3}, 3);
1756

            
1757
$dbi->delete_all(table => 'table1');
1758
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1759
$result = $dbi->select_at(
1760
    table => 'table1',
1761
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1762
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1763
);
added tests
Yuki Kimoto authored on 2011-06-08
1764
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1765
is($row->{key1}, 1);
1766
is($row->{key2}, 2);
1767
is($row->{key3}, 3);
1768

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1769
eval {
1770
    $result = $dbi->select_at(
1771
        table => 'table1',
1772
        primary_key => ['key1', 'key2'],
1773
        where => {},
1774
    );
1775
};
1776
like($@, qr/must be/);
1777

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1778
eval {
1779
    $result = $dbi->select_at(
1780
        table => 'table1',
1781
        primary_key => ['key1', 'key2'],
1782
        where => [1],
1783
    );
1784
};
1785
like($@, qr/same/);
1786

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1787
eval {
1788
    $result = $dbi->update_at(
1789
        table => 'table1',
1790
        primary_key => ['key1', 'key2'],
1791
        where => {},
1792
        param => {key1 => 1, key2 => 2},
1793
    );
1794
};
1795
like($@, qr/must be/);
1796

            
1797
eval {
1798
    $result = $dbi->delete_at(
1799
        table => 'table1',
1800
        primary_key => ['key1', 'key2'],
1801
        where => {},
1802
    );
1803
};
1804
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1805

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1806
test 'columns';
1807
use MyDBI1;
1808
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1809
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1810

            
1811

            
1812
test 'model delete_at';
1813
{
1814
    package MyDBI6;
1815
    
1816
    use base 'DBIx::Custom';
1817
    
1818
    sub connect {
1819
        my $self = shift->SUPER::connect(@_);
1820
        
1821
        $self->include_model('MyModel5');
1822
        
1823
        return $self;
1824
    }
1825
}
1826
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1827
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1828
$dbi->execute("create table table2 (key1, key2, key3)");
1829
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1830
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1831
$dbi->model('table1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1832
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1833
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1834
$dbi->model('table1_1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1835
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1836
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1837
$dbi->model('table1_3')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1838
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1839

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1840
test 'model insert_at';
1841
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1842
$dbi->execute($CREATE_TABLE->{1});
1843
$dbi->model('table1')->insert_at(
1844
    where => [1, 2],
1845
    param => {key3 => 3}
1846
);
1847
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1848
$row = $result->one;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1849
is($row->{key1}, 1);
1850
is($row->{key2}, 2);
1851
is($row->{key3}, 3);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1852

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1853
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1854
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1855
$dbi->execute($CREATE_TABLE->{1});
1856
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1857
$dbi->model('table1')->update_at(
1858
    where => [1, 2],
1859
    param => {key3 => 4}
1860
);
1861
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1862
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1863
is($row->{key1}, 1);
1864
is($row->{key2}, 2);
1865
is($row->{key3}, 4);
1866

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1867
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1868
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1869
$dbi->execute($CREATE_TABLE->{1});
1870
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1871
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1872
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1873
is($row->{key1}, 1);
1874
is($row->{key2}, 2);
1875
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1876

            
1877

            
cleanup
Yuki Kimoto authored on 2011-03-21
1878
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1879
{
1880
    package MyDBI7;
1881
    
1882
    use base 'DBIx::Custom';
1883
    
1884
    sub connect {
1885
        my $self = shift->SUPER::connect(@_);
1886
        
1887
        $self->include_model('MyModel6');
1888
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1889
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1890
        return $self;
1891
    }
1892
}
1893
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1894
$dbi->execute($CREATE_TABLE->{0});
1895
$dbi->execute($CREATE_TABLE->{2});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
1896
$dbi->separator('__');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1897
$dbi->setup_model;
1898
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1899
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1900
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1901
$result = $model->select(
1902
    column => [$model->mycolumn, $model->column('table2')],
1903
    where => {'table1.key1' => 1}
1904
);
added tests
Yuki Kimoto authored on 2011-06-08
1905
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1906
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1907

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

            
1914
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1915
$update_param = $dbi->update_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1916
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1917
update table1 $update_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1918
where key1 = 1
1919
EOS
1920
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1921
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1922
$rows   = $result->all;
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1923
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1924
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1925
                  "basic");
1926

            
1927

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

            
1933
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1934
$update_param = $dbi->update_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1935
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1936
update table1 $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1937
where key1 = 1
1938
EOS
1939
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1940
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1941
$rows   = $result->all;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1942
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1943
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1944
                  "basic");
1945

            
1946
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1947
$dbi->execute($CREATE_TABLE->{1});
1948
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1949
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1950

            
1951
$param = {key2 => 11, key3 => 33};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1952
$update_param = $dbi->update_param($param, {no_set => 1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1953
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1954
update table1 set $update_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1955
where key1 = 1
1956
EOS
1957
$dbi->execute($sql, param => $param);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1958
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1959
$rows   = $result->all;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1960
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
1961
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1962
                  "update param no_set");
1963

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

            
1968

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

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

            
1988

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1989
test 'insert_param';
1990
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1991
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1992
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1993
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1994
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1995
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1996
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1997
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
1998
is($dbi->select(table => 'table1')->one->{key1}, 1);
1999
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2000

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2001
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2002
$dbi->quote('"');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2003
$dbi->execute($CREATE_TABLE->{1});
2004
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2005
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2006
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2007
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2008
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2009
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2010
is($dbi->select(table => 'table1')->one->{key1}, 1);
2011
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
2012

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

            
2016

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2017
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
2018
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2019
$dbi->execute($CREATE_TABLE->{0});
2020
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2021
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
2022
$dbi->execute($CREATE_TABLE->{2});
2023
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2024
$dbi->execute($CREATE_TABLE->{4});
2025
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
2026
$rows = $dbi->select(
2027
    table => 'table1',
2028
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2029
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2030
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2031
)->all;
cleanup
Yuki Kimoto authored on 2011-03-08
2032
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
2033

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2034
$rows = $dbi->select(
2035
    table => 'table1',
2036
    where   => {'key1' => 1},
2037
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2038
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2039
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2040

            
cleanup
Yuki Kimoto authored on 2011-03-08
2041
eval {
2042
    $rows = $dbi->select(
2043
        table => 'table1',
2044
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2045
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2046
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2047
    );
2048
};
2049
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2050

            
2051
$rows = $dbi->select(
2052
    table => 'table1',
2053
    where   => {'key1' => 1},
2054
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2055
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2056
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2057
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2058

            
2059
$rows = $dbi->select(
2060
    column => 'table3.key4 as table3__key4',
2061
    table => 'table1',
2062
    where   => {'table1.key1' => 1},
2063
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2064
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2065
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2066
is_deeply($rows, [{table3__key4 => 4}]);
2067

            
2068
$rows = $dbi->select(
2069
    column => 'table1.key1 as table1__key1',
2070
    table => 'table1',
2071
    where   => {'table3.key4' => 4},
2072
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2073
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2074
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2075
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2076

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2077
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2078
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2079
$dbi->execute($CREATE_TABLE->{0});
2080
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2081
$dbi->execute($CREATE_TABLE->{2});
2082
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2083
$rows = $dbi->select(
2084
    table => 'table1',
2085
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2086
    where   => {'table1.key2' => 2},
2087
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2088
)->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2089
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
2090
          'quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2091

            
2092
{
2093
    package MyDBI8;
2094
    
2095
    use base 'DBIx::Custom';
2096
    
2097
    sub connect {
2098
        my $self = shift->SUPER::connect(@_);
2099
        
2100
        $self->include_model('MyModel7');
2101
        
2102
        return $self;
2103
    }
2104
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2105

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2106
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2107
$dbi->execute($CREATE_TABLE->{0});
2108
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2109
$sql = <<"EOS";
2110
left outer join (
2111
  select * from table1 as t1
2112
  where t1.key2 = (
2113
    select max(t2.key2) from table1 as t2
2114
    where t1.key1 = t2.key1
2115
  )
2116
) as latest_table1 on table1.key1 = latest_table1.key1
2117
EOS
2118
$join = [$sql];
2119
$rows = $dbi->select(
2120
    table => 'table1',
2121
    column => 'latest_table1.key1 as latest_table1__key1',
2122
    join  => $join
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2123
)->all;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2124
is_deeply($rows, [{latest_table1__key1 => 1}]);
2125

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2126
test 'mycolumn';
2127
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2128
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2129
$dbi->execute($CREATE_TABLE->{2});
2130
$dbi->setup_model;
2131
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2132
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2133
$model = $dbi->model('table1');
2134
$result = $model->select_at(
2135
    column => [
2136
        $model->mycolumn,
2137
        $model->column('table2')
2138
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2139
);
added tests
Yuki Kimoto authored on 2011-06-08
2140
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2141
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2142

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2143
$result = $model->select_at(
2144
    column => [
2145
        $model->mycolumn(['key1']),
2146
        $model->column(table2 => ['key1'])
2147
    ]
2148
);
added tests
Yuki Kimoto authored on 2011-06-08
2149
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2150
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2151
$result = $model->select_at(
2152
    column => [
2153
        $model->mycolumn(['key1']),
2154
        {table2 => ['key1']}
2155
    ]
2156
);
added tests
Yuki Kimoto authored on 2011-06-08
2157
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2158
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2159

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2160
$result = $model->select_at(
2161
    column => [
2162
        $model->mycolumn(['key1']),
2163
        ['table2.key1', as => 'table2.key1']
2164
    ]
2165
);
2166
is_deeply($result->one,
2167
          {key1 => 1, 'table2.key1' => 1});
2168

            
2169
eval{
2170
    $result = $model->select_at(
2171
        column => [
2172
            ['table2.key1', asaaaa => 'table2.key1']
2173
        ]
2174
    );
2175
};
2176
like($@, qr/COLUMN/);
2177

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2178
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2179
{
2180
    package MyDBI9;
2181
    
2182
    use base 'DBIx::Custom';
2183
    
2184
    sub connect {
2185
        my $self = shift->SUPER::connect(@_);
2186
        
2187
        $self->include_model('MyModel8')->setup_model;
2188
        
2189
        return $self;
2190
    }
2191
}
2192
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2193
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2194
$model = $dbi->model('table1');
2195
eval{$model->execute('select * from table1')};
2196
ok(!$@);
2197

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2198
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2199
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2200
$dbi->execute($CREATE_TABLE->{0});
2201
$dbi->execute($CREATE_TABLE->{2});
2202
$dbi->setup_model;
2203
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2204
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2205
$model = $dbi->model('table1');
2206
$result = $model->select(
2207
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2208
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2209
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2210
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2211
);
added tests
Yuki Kimoto authored on 2011-06-08
2212
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2213
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2214

            
cleanup
Yuki Kimoto authored on 2011-06-13
2215
$dbi->separator('__');
2216
$result = $model->select(
2217
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2218
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2219
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2220
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2221
);
2222
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2223
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2224

            
2225
$dbi->separator('-');
2226
$result = $model->select(
2227
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2228
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2229
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2230
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2231
);
2232
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2233
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2234

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2235
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2236
$dbi = DBIx::Custom->connect(
2237
    data_source => 'dbi:SQLite:dbname=:memory:',
2238
    dbi_option => {
2239
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2240
    }
2241
);
2242
my $binary = pack("I3", 1, 2, 3);
2243
$dbi->execute('create table table1(key1, key2)');
2244
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2245
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2246
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2247
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2248
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2249
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2250
is($row->{key1_length}, length $binary);
2251

            
2252
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2253
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2254
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2255
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2256
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2257
$row = $result->one;
2258
is($row->{key1_length}, length $binary);
2259

            
2260

            
2261
test 'bind_type option';
2262
$dbi = DBIx::Custom->connect(
2263
    data_source => 'dbi:SQLite:dbname=:memory:',
2264
    dbi_option => {
2265
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2266
    }
2267
);
2268
$binary = pack("I3", 1, 2, 3);
2269
$dbi->execute('create table table1(key1, key2)');
2270
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2271
$result = $dbi->select(table => 'table1');
2272
$row   = $result->one;
2273
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2274
$result = $dbi->execute('select length(key1) as key1_length from table1');
2275
$row = $result->one;
2276
is($row->{key1_length}, length $binary);
2277

            
2278
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2279
$result = $dbi->select(table => 'table1');
2280
$row   = $result->one;
2281
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2282
$result = $dbi->execute('select length(key1) as key1_length from table1');
2283
$row = $result->one;
2284
is($row->{key1_length}, length $binary);
2285

            
2286
test 'model type attribute';
2287
$dbi = DBIx::Custom->connect(
2288
    data_source => 'dbi:SQLite:dbname=:memory:',
2289
    dbi_option => {
2290
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2291
    }
2292
);
2293
$binary = pack("I3", 1, 2, 3);
2294
$dbi->execute('create table table1(key1, key2)');
2295
$model = $dbi->create_model(table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
2296
$model->insert(param => {key1 => $binary, key2 => 'あ'});
2297
$result = $dbi->select(table => 'table1');
2298
$row   = $result->one;
2299
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2300
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2301
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2302
is($row->{key1_length}, length $binary);
2303

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2304
test 'create_model';
2305
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2306
$dbi->execute($CREATE_TABLE->{0});
2307
$dbi->execute($CREATE_TABLE->{2});
2308

            
2309
$dbi->create_model(
2310
    table => 'table1',
2311
    join => [
2312
       'left outer join table2 on table1.key1 = table2.key1'
2313
    ],
2314
    primary_key => ['key1']
2315
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2316
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2317
    table => 'table2'
2318
);
2319
$dbi->create_model(
2320
    table => 'table3',
2321
    filter => [
2322
        key1 => {in => sub { uc $_[0] }}
2323
    ]
2324
);
2325
$dbi->setup_model;
2326
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2327
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2328
$model = $dbi->model('table1');
2329
$result = $model->select(
2330
    column => [$model->mycolumn, $model->column('table2')],
2331
    where => {'table1.key1' => 1}
2332
);
added tests
Yuki Kimoto authored on 2011-06-08
2333
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2334
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2335
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2336

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2337
test 'model method';
2338
test 'create_model';
2339
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2340
$dbi->execute($CREATE_TABLE->{2});
2341
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2342
$model = $dbi->create_model(
2343
    table => 'table2'
2344
);
2345
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2346
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2347

            
2348
test 'merge_param';
2349
{
2350
    my $dbi = DBIx::Custom->new;
2351
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2352
    my $param2 = {key1 => 1, key2 => 2};
2353
    my $param3 = {key1 => 1};
2354
    my $param = $dbi->merge_param($param1, $param2, $param3);
2355
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2356
}
2357

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2358
{
2359
    my $dbi = DBIx::Custom->new;
2360
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2361
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2362
    my $param = $dbi->merge_param($param1, $param2);
2363
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2364
}
2365

            
cleanup
Yuki Kimoto authored on 2011-04-01
2366
test 'select() param option';
2367
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2368
$dbi->execute($CREATE_TABLE->{0});
2369
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2370
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2371
$dbi->execute($CREATE_TABLE->{2});
2372
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2373
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2374
$rows = $dbi->select(
2375
    table => 'table1',
2376
    column => 'table1.key1 as table1_key1, key2, key3',
2377
    where   => {'table1.key2' => 3},
2378
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2379
              ' as table2 on table1.key1 = table2.key1'],
2380
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2381
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2382
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2383

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

            
2385
test 'select() wrap option';
2386
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2387
$dbi->execute($CREATE_TABLE->{0});
2388
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2389
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2390
$rows = $dbi->select(
2391
    table => 'table1',
2392
    column => 'key1',
2393
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2394
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2395
is_deeply($rows, [{key1 => 1}]);
2396

            
2397
eval {
2398
$dbi->select(
2399
    table => 'table1',
2400
    column => 'key1',
2401
    wrap => 'select * from ('
2402
)
2403
};
cleanup
Yuki Kimoto authored on 2011-04-25
2404
like($@, qr/array/);
2405

            
2406
test 'select() string where';
2407
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2408
$dbi->execute($CREATE_TABLE->{0});
2409
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2410
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2411
$rows = $dbi->select(
2412
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2413
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2414
    where_param => {key1 => 1, key2 => 2}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2415
)->all;
cleanup
Yuki Kimoto authored on 2011-04-25
2416
is_deeply($rows, [{key1 => 1, key2 => 2}]);
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2417

            
updated pod
Yuki Kimoto authored on 2011-06-21
2418
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2419
$dbi->execute($CREATE_TABLE->{0});
2420
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2421
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2422
$rows = $dbi->select(
2423
    table => 'table1',
2424
    where => [
2425
        'key1 = :key1 and key2 = :key2',
2426
        {key1 => 1, key2 => 2}
2427
    ]
2428
)->all;
2429
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2430

            
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2431
test 'delete() string where';
2432
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2433
$dbi->execute($CREATE_TABLE->{0});
2434
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2435
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2436
$dbi->delete(
2437
    table => 'table1',
updated pod
Yuki Kimoto authored on 2011-06-21
2438
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2439
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2440
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2441
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2442
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2443

            
updated pod
Yuki Kimoto authored on 2011-06-21
2444
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2445
$dbi->execute($CREATE_TABLE->{0});
2446
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2447
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2448
$dbi->delete(
2449
    table => 'table1',
2450
    where => [
2451
        'key1 = :key1 and key2 = :key2',
2452
         {key1 => 1, key2 => 2}
2453
    ]
2454
);
2455
$rows = $dbi->select(table => 'table1')->all;
2456
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2457

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

            
2459
test 'update() string where';
2460
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2461
$dbi->execute($CREATE_TABLE->{0});
2462
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2463
$dbi->update(
2464
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2465
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2466
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2467
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2468
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2469
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2470
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2471

            
updated pod
Yuki Kimoto authored on 2011-06-21
2472
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2473
$dbi->execute($CREATE_TABLE->{0});
2474
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2475
$dbi->update(
2476
    table => 'table1',
2477
    param => {key1 => 5},
2478
    where => [
2479
        'key1 = :key1 and key2 = :key2',
2480
        {key1 => 1, key2 => 2}
2481
    ]
2482
);
2483
$rows = $dbi->select(table => 'table1')->all;
2484
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2485

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2486
test 'insert id and primary_key option';
2487
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2488
$dbi->execute($CREATE_TABLE->{1});
2489
$dbi->insert(
2490
    primary_key => ['key1', 'key2'], 
2491
    table => 'table1',
2492
    id => [1, 2],
2493
    param => {key3 => 3}
2494
);
2495
is($dbi->select(table => 'table1')->one->{key1}, 1);
2496
is($dbi->select(table => 'table1')->one->{key2}, 2);
2497
is($dbi->select(table => 'table1')->one->{key3}, 3);
2498

            
2499
$dbi->delete_all(table => 'table1');
2500
$dbi->insert(
2501
    primary_key => 'key1', 
2502
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2503
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2504
    param => {key2 => 2, key3 => 3}
2505
);
2506

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

            
2511
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2512
$dbi->execute($CREATE_TABLE->{1});
2513
$dbi->insert(
2514
    {key3 => 3},
2515
    primary_key => ['key1', 'key2'], 
2516
    table => 'table1',
2517
    id => [1, 2],
2518
);
2519
is($dbi->select(table => 'table1')->one->{key1}, 1);
2520
is($dbi->select(table => 'table1')->one->{key2}, 2);
2521
is($dbi->select(table => 'table1')->one->{key3}, 3);
2522

            
cleanup
Yuki Kimoto authored on 2011-06-08
2523

            
added tests
Yuki Kimoto authored on 2011-06-08
2524
test 'model insert id and primary_key option';
2525
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2526
$dbi->execute($CREATE_TABLE->{1});
2527
$dbi->model('table1')->insert(
2528
    id => [1, 2],
2529
    param => {key3 => 3}
2530
);
2531
$result = $dbi->model('table1')->select;
2532
$row = $result->one;
2533
is($row->{key1}, 1);
2534
is($row->{key2}, 2);
2535
is($row->{key3}, 3);
2536

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2537
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2538
$dbi->execute($CREATE_TABLE->{1});
2539
$dbi->model('table1')->insert(
2540
    {key3 => 3},
2541
    id => [1, 2]
2542
);
2543
$result = $dbi->model('table1')->select;
2544
$row = $result->one;
2545
is($row->{key1}, 1);
2546
is($row->{key2}, 2);
2547
is($row->{key3}, 3);
2548

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

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

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

            
2588

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

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

            
2604
test 'delete and id option';
2605
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2606
$dbi->execute($CREATE_TABLE->{1});
2607
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2608
$dbi->delete(
2609
    table => 'table1',
2610
    primary_key => ['key1', 'key2'],
2611
    id => [1, 2],
2612
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2613
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2614

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2615
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2616
$dbi->delete(
2617
    table => 'table1',
2618
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2619
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2620
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2621
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2622

            
2623

            
2624
test 'model delete and id option';
2625
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2626
$dbi->execute($CREATE_TABLE->{1});
2627
$dbi->execute("create table table2 (key1, key2, key3)");
2628
$dbi->execute("create table table3 (key1, key2, key3)");
2629
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2630
$dbi->model('table1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2631
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2632
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2633
$dbi->model('table1_1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2634
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2635
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2636
$dbi->model('table1_3')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2637
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2638

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

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

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

            
2666
$dbi->delete_all(table => 'table1');
2667
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2668
$result = $dbi->select(
2669
    table => 'table1',
2670
    primary_key => ['key1', 'key2'],
2671
    id => [1, 2]
2672
);
2673
$row = $result->one;
2674
is($row->{key1}, 1);
2675
is($row->{key2}, 2);
2676
is($row->{key3}, 3);
2677

            
2678

            
2679
test 'model select_at';
2680
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2681
$dbi->execute($CREATE_TABLE->{1});
2682
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2683
$result = $dbi->model('table1')->select(id => [1, 2]);
2684
$row = $result->one;
2685
is($row->{key1}, 1);
2686
is($row->{key2}, 2);
2687
is($row->{key3}, 3);
2688

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2689
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2690
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2691
$dbi->execute($CREATE_TABLE->{0});
2692
$dbi->execute($CREATE_TABLE->{2});
2693
$dbi->setup_model;
2694
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2695
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2696
$model = $dbi->model('table1');
2697
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2698
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2699
    where => {'table1.key1' => 1}
2700
);
2701
is_deeply($result->one,
2702
          {'table2.key1' => 1, 'table2.key3' => 3});
2703

            
2704
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2705
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2706
    where => {'table1.key1' => 1}
2707
);
2708
is_deeply($result->one,
2709
          {'table2.key1' => 1, 'table2.key3' => 3});
2710

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

            
2712
test 'type_rule from';
2713
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2714
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2715
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2716
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2717
    }
2718
);
2719
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2720
$dbi->insert({key1 => 'a'}, table => 'table1');
2721
$result = $dbi->select(table => 'table1');
2722
is($result->fetch_first->[0], 'A');
2723

            
2724
$result = $dbi->select(table => 'table1');
2725
is($result->one->{key1}, 'A');
2726

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

            
2728
test 'type_rule into';
2729
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2730
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2731
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2732
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2733
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2734
    }
2735
);
2736
$dbi->insert({key1 => 'a'}, table => 'table1');
2737
$result = $dbi->select(table => 'table1');
2738
is($result->one->{key1}, 'A');
2739

            
2740
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2741
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2742
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2743
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2744
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2745
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2746
);
2747
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2748
$result = $dbi->select(table => 'table1');
2749
$row = $result->one;
2750
is($row->{key1}, 'A');
2751
is($row->{key2}, 'B');
2752

            
2753
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2754
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2755
$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1');
2756
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2757
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2758
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2759
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2760
);
2761
$result = $dbi->execute(
2762
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2763
    param => {key1 => 'a', 'table1.key2' => 'b'}
2764
);
2765
$row = $result->one;
2766
is($row->{key1}, 'a');
2767
is($row->{key2}, 'B');
2768

            
2769
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2770
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2771
$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1');
2772
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2773
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2774
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2775
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2776
);
2777
$result = $dbi->execute(
2778
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2779
    param => {key1 => 'a', 'table1.key2' => 'b'},
2780
    table => 'table1'
2781
);
2782
$row = $result->one;
2783
is($row->{key1}, 'A');
2784
is($row->{key2}, 'B');
2785

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2786
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2787
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2788
$dbi->register_filter(twice => sub { $_[0] * 2 });
2789
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2790
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2791
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2792
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2793
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2794
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2795
    }
2796
);
2797
$dbi->insert({key1 => 2}, table => 'table1');
2798
$result = $dbi->select(table => 'table1');
2799
is($result->fetch->[0], 8);
2800

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2801
test 'type_rule and filter order';
2802
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2803
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2804
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2805
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2806
        date => sub { $_[0] . 'b' }
2807
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2808
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2809
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2810
    },
2811
    from1 => {
2812
        date => sub { $_[0] . 'd' }
2813
    },
2814
    from2 => {
2815
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2816
    }
2817
);
2818
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2819
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2820
$result->filter(key1 => sub { $_[0] . 'f' });
2821
is($result->fetch_first->[0], '1abcdef');
2822

            
2823
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2824
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2825
$dbi->type_rule(
2826
    from1 => {
2827
        date => sub { $_[0] . 'p' }
2828
    },
2829
    from2 => {
2830
        date => sub { $_[0] . 'q' }
2831
    },
2832
);
2833
$dbi->insert({key1 => '1'}, table => 'table1');
2834
$result = $dbi->select(table => 'table1');
2835
$result->type_rule(
2836
    from1 => {
2837
        date => sub { $_[0] . 'd' }
2838
    },
2839
    from2 => {
2840
        date => sub { $_[0] . 'e' }
2841
    }
2842
);
2843
$result->filter(key1 => sub { $_[0] . 'f' });
2844
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2845

            
2846
test 'type_rule_off';
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
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2851
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2852
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2853
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2854
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2855
    }
2856
);
2857
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2858
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2859
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2860

            
2861
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2862
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2863
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2864
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2865
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2866
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2867
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2868
        date => sub { $_[0] * 3 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2869
    }
2870
);
2871
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2872
$result = $dbi->select(table => 'table1', type_rule_off => 1);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2873
is($result->one->{key1}, 4);
2874

            
2875
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2876
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2877
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2878
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2879
        date => sub { $_[0] * 2 },
2880
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2881
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2882
        date => sub { $_[0] * 3 },
2883
    }
2884
);
2885
$dbi->insert({key1 => 2}, table => 'table1');
2886
$result = $dbi->select(table => 'table1');
2887
is($result->one->{key1}, 12);
2888

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2903
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2904
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2905
$dbi->register_filter(ppp => sub { uc $_[0] });
2906
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2907
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2908
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2909
    }
2910
);
2911
$dbi->insert({key1 => 'a'}, table => 'table1');
2912
$result = $dbi->select(table => 'table1');
2913
is($result->one->{key1}, 'A');
2914

            
2915
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2916
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2917
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2918
    }
2919
)};
2920
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
2921

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2922
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2923
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2924
eval {
2925
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2926
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2927
            Date => sub { $_[0] * 2 },
2928
        }
2929
    );
2930
};
2931
like($@, qr/lower/);
2932

            
2933
eval {
2934
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2935
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2936
            Date => sub { $_[0] * 2 },
2937
        }
2938
    );
2939
};
2940
like($@, qr/lower/);
2941

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2976
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2977
$result->type_rule(
2978
    from1 => {
2979
        date => sub { $_[0] * 3 }
2980
    }
2981
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2982
$row = $result->one;
2983
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2984
is($row->{key2}, 2);
2985

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2986
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2987
$result->type_rule(
2988
    from1 => {
2989
        date => sub { $_[0] * 3 }
2990
    }
2991
);
cleanup
Yuki Kimoto authored on 2011-06-15
2992
$row = $result->one;
2993
is($row->{key1}, 6);
2994
is($row->{key2}, 2);
2995
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2996
$result->type_rule(
2997
    from1 => [date => sub { $_[0] * 3 }]
2998
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2999
$row = $result->one;
3000
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3001
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3002
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3003
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3004
$result->type_rule(
3005
    from1 => [date => 'fivetimes']
3006
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3007
$row = $result->one;
3008
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3009
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3010
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3011
$result->type_rule(
3012
    from1 => [date => undef]
3013
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3014
$row = $result->one;
3015
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3016
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3017

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3018
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3019
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3020
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3021
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3022
        date => sub { $_[0] * 2 },
3023
    },
3024
);
3025
$dbi->insert({key1 => 2}, table => 'table1');
3026
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3027
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3028
is($result->one->{key1}, 12);
3029

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3042
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3043
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3044
$dbi->type_rule(
3045
    into1 => {
3046
        date => sub { $_[0] . 'b' }
3047
    },
3048
    into2 => {
3049
        date => sub { $_[0] . 'c' }
3050
    },
3051
    from1 => {
3052
        date => sub { $_[0] . 'd' }
3053
    },
3054
    from2 => {
3055
        date => sub { $_[0] . 'e' }
3056
    }
3057
);
3058
$dbi->insert({key1 => '1'}, table => 'table1', type_rule_off => 1);
3059
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3060
is($result->type_rule_off->fetch_first->[0], '1');
3061
$result = $dbi->select(table => 'table1');
3062
is($result->type_rule_on->fetch_first->[0], '1de');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3063

            
3064
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3065
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3066
$dbi->type_rule(
3067
    into1 => {
3068
        date => sub { $_[0] . 'b' }
3069
    },
3070
    into2 => {
3071
        date => sub { $_[0] . 'c' }
3072
    },
3073
    from1 => {
3074
        date => sub { $_[0] . 'd' }
3075
    },
3076
    from2 => {
3077
        date => sub { $_[0] . 'e' }
3078
    }
3079
);
3080
$dbi->insert({key1 => '1'}, table => 'table1', type_rule1_off => 1);
3081
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3082
is($result->type_rule1_off->fetch_first->[0], '1ce');
3083
$result = $dbi->select(table => 'table1');
3084
is($result->type_rule1_on->fetch_first->[0], '1cde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3085

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

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3108
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3109
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3110
$dbi->execute($CREATE_TABLE->{0});
3111
$dbi->execute($CREATE_TABLE->{2});
3112

            
3113
$dbi->create_model(
3114
    table => 'table1',
3115
    join => [
3116
       'left outer join table2 on table1.key1 = table2.key1'
3117
    ],
3118
    primary_key => ['key1'],
3119
);
3120
$model2 = $dbi->create_model(
3121
    table => 'table2',
3122
);
3123
$dbi->setup_model;
3124
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3125
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3126
$model = $dbi->model('table1');
3127
$result = $model->select(
3128
    column => [
3129
        $model->mycolumn,
3130
        {table2 => [qw/key1 key3/]}
3131
    ],
3132
    where => {'table1.key1' => 1}
3133
);
3134
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3135
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3136
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3137

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3138
$dbi->separator('__');
3139
$model = $dbi->model('table1');
3140
$result = $model->select(
3141
    column => [
3142
        $model->mycolumn,
3143
        {table2 => [qw/key1 key3/]}
3144
    ],
3145
    where => {'table1.key1' => 1}
3146
);
3147
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3148
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3149
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3150

            
cleanup
Yuki Kimoto authored on 2011-06-13
3151
$dbi->separator('-');
3152
$model = $dbi->model('table1');
3153
$result = $model->select(
3154
    column => [
3155
        $model->mycolumn,
3156
        {table2 => [qw/key1 key3/]}
3157
    ],
3158
    where => {'table1.key1' => 1}
3159
);
3160
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3161
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3162
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3163

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3165
test 'filter_off';
3166
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3167
$dbi->execute($CREATE_TABLE->{0});
3168
$dbi->execute($CREATE_TABLE->{2});
3169

            
3170
$dbi->create_model(
3171
    table => 'table1',
3172
    join => [
3173
       'left outer join table2 on table1.key1 = table2.key1'
3174
    ],
3175
    primary_key => ['key1'],
3176
);
3177
$dbi->setup_model;
3178
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3179
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3180
$result = $model->select(column => 'key1');
3181
$result->filter(key1 => sub { $_[0] * 2 });
3182
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3183

            
3184
test 'available_date_type';
3185
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3186
ok($dbi->can('available_data_type'));
3187

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

            
3189
test 'select prefix option';
3190
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3191
$dbi->execute($CREATE_TABLE->{0});
3192
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3193
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3194
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3195

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

            
3197
test 'separator';
3198
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3199
is($dbi->separator, '.');
3200
$dbi->separator('-');
3201
is($dbi->separator, '-');
3202
$dbi->separator('__');
3203
is($dbi->separator, '__');
3204
eval { $dbi->separator('?') };
3205
like($@, qr/Separator/);
3206

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

            
3208
test 'map_param';
3209
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3210
$param = $dbi->map_param(
3211
    {id => 1, author => 'Ken', price => 1900},
3212
    id => 'book.id',
3213
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3214
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3215
);
3216
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3217
  'book.price' => 1900});
3218

            
3219
$param = $dbi->map_param(
3220
    {id => 0, author => 0, price => 0},
3221
    id => 'book.id',
3222
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3223
    price => ['book.price', sub { '%' . $_[0] . '%' },
3224
      {if => sub { $_[0] eq 0 }}]
3225
);
3226
is_deeply($param, {'book.id' => 0, 'book.author' => '%0%', 'book.price' => '%0%'});
3227

            
3228
$param = $dbi->map_param(
3229
    {id => '', author => '', price => ''},
3230
    id => 'book.id',
3231
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3232
    price => ['book.price', sub { '%' . $_[0] . '%' },
3233
      {if => sub { $_[0] eq 1 }}]
3234
);
3235
is_deeply($param, {});
3236

            
3237
$param = $dbi->map_param(
3238
    {id => undef, author => undef, price => undef},
3239
    id => 'book.id',
3240
    price => ['book.price', {if => 'exists'}]
3241
);
3242
is_deeply($param, {'book.price' => undef});
3243

            
3244
$param = $dbi->map_param(
3245
    {price => 'a'},
3246
    id => ['book.id', {if => 'exists'}],
3247
    price => ['book.price', sub { '%' . $_[0] }, {if => 'exists'}]
3248
);
3249
is_deeply($param, {'book.price' => '%a'});
3250

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