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

            
fixed DBIx::Custom::Where to...
Yuki Kimoto authored on 2011-06-27
1345
$where = $dbi->where(
1346
    clause => ['and', ['or'], ['and', 'key1 = :key1', 'key2 = :key2']],
1347
    param => {key1 => 1, key2 => 2}
1348
);
1349
$result = $dbi->select(
1350
    table => 'table1',
1351
    where => $where,
1352
);
1353
$row = $result->all;
1354
is_deeply($row, [{key1 => 1, key2 => 2}]);
1355

            
1356

            
1357
$where = $dbi->where(
1358
    clause => ['and', ['or'], ['or', ':key1', ':key2']],
1359
    param => {}
1360
);
1361
$result = $dbi->select(
1362
    table => 'table1',
1363
    where => $where,
1364
);
1365
$row = $result->all;
1366
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1367

            
1368

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1373
test 'register_tag_processor';
1374
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1375
$dbi->register_tag_processor(
1376
    a => sub { 1 }
1377
);
1378
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1379

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1380
test 'register_tag';
1381
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1382
$dbi->register_tag(
1383
    b => sub { 2 }
1384
);
1385
is($dbi->query_builder->tags->{b}->(), 2);
1386

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1387
test 'table not specify exception';
1388
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1389
eval {$dbi->insert};
1390
like($@, qr/table/);
1391
eval {$dbi->update};
1392
like($@, qr/table/);
1393
eval {$dbi->delete};
1394
like($@, qr/table/);
1395
eval {$dbi->select};
1396
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1397

            
1398

            
1399
test 'more tests';
1400
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1401
eval{$dbi->apply_filter('table', 'column', [])};
1402
like($@, qr/apply_filter/);
1403

            
1404
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1405
like($@, qr/apply_filter/);
1406

            
1407
$dbi->apply_filter(
1408

            
1409
);
1410
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1411
$dbi->execute($CREATE_TABLE->{0});
1412
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1413
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1414
$dbi->apply_filter('table1', 'key2', 
1415
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1416
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1417
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1418

            
1419
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1420
$dbi->execute($CREATE_TABLE->{0});
1421
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1422
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1423
$dbi->apply_filter('table1', 'key2', {});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1424
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1425
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1426

            
1427
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1428
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1429
like($@, qr/not registered/);
1430
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1431
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1432
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1433
is($dbi->one, 1);
1434

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

            
1438
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1439
$dbi->execute($CREATE_TABLE->{0});
1440
$dbi->register_filter(twice => sub { $_[0] * 2 });
1441
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1442
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1443
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1444
is_deeply($row, {key1 => 2, key2 => 2});
1445
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1446
             filter => {key1 => 'no'}) };
1447
like($@, qr//);
1448

            
1449
$dbi->register_filter(one => sub { });
1450
$dbi->default_fetch_filter('one');
1451
ok($dbi->default_fetch_filter);
1452
$dbi->default_bind_filter('one');
1453
ok($dbi->default_bind_filter);
1454
eval{$dbi->default_fetch_filter('no')};
1455
like($@, qr/not registered/);
1456
eval{$dbi->default_bind_filter('no')};
1457
like($@, qr/not registered/);
1458
$dbi->default_bind_filter(undef);
1459
ok(!defined $dbi->default_bind_filter);
1460
$dbi->default_fetch_filter(undef);
1461
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1462
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1463
like($@, qr/Tag not finished/);
1464

            
1465
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1466
$dbi->execute($CREATE_TABLE->{0});
1467
$dbi->register_filter(one => sub { 1 });
1468
$result = $dbi->select(table => 'table1');
1469
eval {$result->filter(key1 => 'no')};
1470
like($@, qr/not registered/);
1471
eval {$result->end_filter(key1 => 'no')};
1472
like($@, qr/not registered/);
1473
$result->default_filter(undef);
1474
ok(!defined $result->default_filter);
1475
$result->default_filter('one');
1476
is($result->default_filter->(), 1);
1477

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1478
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1479
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1480
                             dbi_option => {PrintError => 1});
1481
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1482
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1483
                             dbi_options => {PrintError => 1});
1484
ok($dbi->dbh->{PrintError});
1485

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1486
test 'DBIx::Custom::Result stash()';
1487
$result = DBIx::Custom::Result->new;
1488
is_deeply($result->stash, {}, 'default');
1489
$result->stash->{foo} = 1;
1490
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1491

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1492
test 'filter __ expression';
1493
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1494
$dbi->execute('create table company (id, name, location_id)');
1495
$dbi->execute('create table location (id, name)');
1496
$dbi->apply_filter('location',
1497
  name => {in => sub { uc $_[0] } }
1498
);
1499

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

            
1503
$result = $dbi->select(
1504
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1505
    column => ['location.name as location__name']
1506
);
1507
is($result->fetch_first->[0], 'B');
1508

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1509
$result = $dbi->select(
1510
    table => 'company', relation => {'company.location_id' => 'location.id'},
1511
    column => ['location.name as location__name']
1512
);
1513
is($result->fetch_first->[0], 'B');
1514

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1515
$result = $dbi->select(
1516
    table => 'company', relation => {'company.location_id' => 'location.id'},
1517
    column => ['location.name as "location.name"']
1518
);
1519
is($result->fetch_first->[0], 'B');
1520

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1521
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1522
use MyDBI1;
1523
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1524
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1525
$model = $dbi->model('book');
1526
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1527
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1528
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1529
$model = $dbi->model('company');
1530
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1531
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1532
is($dbi->models->{'book'}, $dbi->model('book'));
1533
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1534

            
1535
{
1536
    package MyDBI4;
1537

            
1538
    use strict;
1539
    use warnings;
1540

            
1541
    use base 'DBIx::Custom';
1542

            
1543
    sub connect {
1544
        my $self = shift->SUPER::connect(@_);
1545
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1546
        $self->include_model(
1547
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1548
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1549
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1550
            ]
1551
        );
1552
    }
1553

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

            
1556
    use strict;
1557
    use warnings;
1558

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

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

            
1563
    use strict;
1564
    use warnings;
1565

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

            
1568
    sub insert {
1569
        my ($self, $param) = @_;
1570
        
1571
        return $self->SUPER::insert(param => $param);
1572
    }
1573

            
1574
    sub list { shift->select; }
1575

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

            
1578
    use strict;
1579
    use warnings;
1580

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

            
1583
    sub insert {
1584
        my ($self, $param) = @_;
1585
        
1586
        return $self->SUPER::insert(param => $param);
1587
    }
1588

            
1589
    sub list { shift->select; }
1590
}
1591
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1592
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1593
$model = $dbi->model('book');
1594
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1595
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1596
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1597
$model = $dbi->model('company');
1598
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1599
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1600

            
1601
{
1602
     package MyDBI5;
1603

            
1604
    use strict;
1605
    use warnings;
1606

            
1607
    use base 'DBIx::Custom';
1608

            
1609
    sub connect {
1610
        my $self = shift->SUPER::connect(@_);
1611
        
1612
        $self->include_model('MyModel4');
1613
    }
1614
}
1615
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1616
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1617
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1618
$model = $dbi->model('company');
1619
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1620
is_deeply($model->list->all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1621
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1622
$model = $dbi->model('book');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1623
is_deeply($model->list->all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1624

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1625
test 'primary_key';
1626
use MyDBI1;
1627
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1628
$model = $dbi->model('book');
1629
$model->primary_key(['id', 'number']);
1630
is_deeply($model->primary_key, ['id', 'number']);
1631

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1632
test 'columns';
1633
use MyDBI1;
1634
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1635
$model = $dbi->model('book');
1636
$model->columns(['id', 'number']);
1637
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1638

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1639
test 'setup_model';
1640
use MyDBI1;
1641
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1642
$dbi->execute('create table book (id)');
1643
$dbi->execute('create table company (id, name);');
1644
$dbi->execute('create table test (id, name, primary key (id, name));');
1645
$dbi->setup_model;
1646
is_deeply($dbi->model('book')->columns, ['id']);
1647
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1648

            
1649
test 'delete_at';
1650
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1651
$dbi->execute($CREATE_TABLE->{1});
1652
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1653
$dbi->delete_at(
1654
    table => 'table1',
1655
    primary_key => ['key1', 'key2'],
1656
    where => [1, 2],
1657
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1658
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1659

            
1660
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1661
$dbi->delete_at(
1662
    table => 'table1',
1663
    primary_key => 'key1',
1664
    where => 1,
1665
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1666
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1667

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1668
test 'insert_at';
1669
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1670
$dbi->execute($CREATE_TABLE->{1});
1671
$dbi->insert_at(
1672
    primary_key => ['key1', 'key2'], 
1673
    table => 'table1',
1674
    where => [1, 2],
1675
    param => {key3 => 3}
1676
);
added tests
Yuki Kimoto authored on 2011-06-08
1677
is($dbi->select(table => 'table1')->one->{key1}, 1);
1678
is($dbi->select(table => 'table1')->one->{key2}, 2);
1679
is($dbi->select(table => 'table1')->one->{key3}, 3);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1680

            
1681
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1682
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1683
$dbi->insert_at(
1684
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1685
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1686
    where => 1,
1687
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1688
);
1689

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

            
1694
eval {
1695
    $dbi->insert_at(
1696
        table => 'table1',
1697
        primary_key => ['key1', 'key2'],
1698
        where => {},
1699
        param => {key1 => 1, key2 => 2, key3 => 3},
1700
    );
1701
};
1702
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1703

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1704
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1705
$dbi->execute($CREATE_TABLE->{1});
1706
$dbi->insert_at(
1707
    {key3 => 3},
1708
    primary_key => ['key1', 'key2'], 
1709
    table => 'table1',
1710
    where => [1, 2],
1711
);
added tests
Yuki Kimoto authored on 2011-06-08
1712
is($dbi->select(table => 'table1')->one->{key1}, 1);
1713
is($dbi->select(table => 'table1')->one->{key2}, 2);
1714
is($dbi->select(table => 'table1')->one->{key3}, 3);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1715

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

            
1730
$dbi->delete_all(table => 'table1');
1731
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1732
$dbi->update_at(
1733
    table => 'table1',
1734
    primary_key => 'key1',
1735
    where => 1,
1736
    param => {key3 => 4}
1737
);
added tests
Yuki Kimoto authored on 2011-06-08
1738
is($dbi->select(table => 'table1')->one->{key1}, 1);
1739
is($dbi->select(table => 'table1')->one->{key2}, 2);
1740
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1741

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1755
test 'select_at';
1756
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1757
$dbi->execute($CREATE_TABLE->{1});
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'],
1762
    where => [1, 2]
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

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

            
1781
$dbi->delete_all(table => 'table1');
1782
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1783
$result = $dbi->select_at(
1784
    table => 'table1',
1785
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1786
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1787
);
added tests
Yuki Kimoto authored on 2011-06-08
1788
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1789
is($row->{key1}, 1);
1790
is($row->{key2}, 2);
1791
is($row->{key3}, 3);
1792

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1793
eval {
1794
    $result = $dbi->select_at(
1795
        table => 'table1',
1796
        primary_key => ['key1', 'key2'],
1797
        where => {},
1798
    );
1799
};
1800
like($@, qr/must be/);
1801

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1802
eval {
1803
    $result = $dbi->select_at(
1804
        table => 'table1',
1805
        primary_key => ['key1', 'key2'],
1806
        where => [1],
1807
    );
1808
};
1809
like($@, qr/same/);
1810

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

            
1821
eval {
1822
    $result = $dbi->delete_at(
1823
        table => 'table1',
1824
        primary_key => ['key1', 'key2'],
1825
        where => {},
1826
    );
1827
};
1828
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1829

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1830
test 'columns';
1831
use MyDBI1;
1832
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1833
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1834

            
1835

            
1836
test 'model delete_at';
1837
{
1838
    package MyDBI6;
1839
    
1840
    use base 'DBIx::Custom';
1841
    
1842
    sub connect {
1843
        my $self = shift->SUPER::connect(@_);
1844
        
1845
        $self->include_model('MyModel5');
1846
        
1847
        return $self;
1848
    }
1849
}
1850
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1851
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1852
$dbi->execute("create table table2 (key1, key2, key3)");
1853
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1854
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1855
$dbi->model('table1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1856
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1857
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1858
$dbi->model('table1_1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1859
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1860
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1861
$dbi->model('table1_3')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1862
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1863

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

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1877
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1878
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1879
$dbi->execute($CREATE_TABLE->{1});
1880
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1881
$dbi->model('table1')->update_at(
1882
    where => [1, 2],
1883
    param => {key3 => 4}
1884
);
1885
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1886
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1887
is($row->{key1}, 1);
1888
is($row->{key2}, 2);
1889
is($row->{key3}, 4);
1890

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1891
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1892
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1893
$dbi->execute($CREATE_TABLE->{1});
1894
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1895
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1896
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1897
is($row->{key1}, 1);
1898
is($row->{key2}, 2);
1899
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1900

            
1901

            
cleanup
Yuki Kimoto authored on 2011-03-21
1902
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1903
{
1904
    package MyDBI7;
1905
    
1906
    use base 'DBIx::Custom';
1907
    
1908
    sub connect {
1909
        my $self = shift->SUPER::connect(@_);
1910
        
1911
        $self->include_model('MyModel6');
1912
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1913
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1914
        return $self;
1915
    }
1916
}
1917
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1918
$dbi->execute($CREATE_TABLE->{0});
1919
$dbi->execute($CREATE_TABLE->{2});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
1920
$dbi->separator('__');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1921
$dbi->setup_model;
1922
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1923
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1924
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1925
$result = $model->select(
1926
    column => [$model->mycolumn, $model->column('table2')],
1927
    where => {'table1.key1' => 1}
1928
);
added tests
Yuki Kimoto authored on 2011-06-08
1929
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1930
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1931

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

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

            
1951

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

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

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

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

            
1992

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

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

            
2012

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2013
test 'insert_param';
2014
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2015
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2016
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2017
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2018
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2019
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2020
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2021
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2022
is($dbi->select(table => 'table1')->one->{key1}, 1);
2023
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2024

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2025
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2026
$dbi->quote('"');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2027
$dbi->execute($CREATE_TABLE->{1});
2028
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2029
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2030
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2031
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2032
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2033
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2034
is($dbi->select(table => 'table1')->one->{key1}, 1);
2035
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
2036

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

            
2040

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2041
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
2042
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2043
$dbi->execute($CREATE_TABLE->{0});
2044
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2045
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
2046
$dbi->execute($CREATE_TABLE->{2});
2047
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2048
$dbi->execute($CREATE_TABLE->{4});
2049
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
2050
$rows = $dbi->select(
2051
    table => 'table1',
2052
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2053
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2054
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2055
)->all;
cleanup
Yuki Kimoto authored on 2011-03-08
2056
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
2057

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2058
$rows = $dbi->select(
2059
    table => 'table1',
2060
    where   => {'key1' => 1},
2061
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2062
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2063
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2064

            
cleanup
Yuki Kimoto authored on 2011-03-08
2065
eval {
2066
    $rows = $dbi->select(
2067
        table => 'table1',
2068
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2069
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2070
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2071
    );
2072
};
2073
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2074

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

            
2083
$rows = $dbi->select(
2084
    column => 'table3.key4 as table3__key4',
2085
    table => 'table1',
2086
    where   => {'table1.key1' => 1},
2087
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2088
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2089
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2090
is_deeply($rows, [{table3__key4 => 4}]);
2091

            
2092
$rows = $dbi->select(
2093
    column => 'table1.key1 as table1__key1',
2094
    table => 'table1',
2095
    where   => {'table3.key4' => 4},
2096
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2097
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2098
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2099
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2100

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2101
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2102
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2103
$dbi->execute($CREATE_TABLE->{0});
2104
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2105
$dbi->execute($CREATE_TABLE->{2});
2106
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2107
$rows = $dbi->select(
2108
    table => 'table1',
2109
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2110
    where   => {'table1.key2' => 2},
2111
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2112
)->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2113
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
2114
          'quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2115

            
2116
{
2117
    package MyDBI8;
2118
    
2119
    use base 'DBIx::Custom';
2120
    
2121
    sub connect {
2122
        my $self = shift->SUPER::connect(@_);
2123
        
2124
        $self->include_model('MyModel7');
2125
        
2126
        return $self;
2127
    }
2128
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2129

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2130
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2131
$dbi->execute($CREATE_TABLE->{0});
2132
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2133
$sql = <<"EOS";
2134
left outer join (
2135
  select * from table1 as t1
2136
  where t1.key2 = (
2137
    select max(t2.key2) from table1 as t2
2138
    where t1.key1 = t2.key1
2139
  )
2140
) as latest_table1 on table1.key1 = latest_table1.key1
2141
EOS
2142
$join = [$sql];
2143
$rows = $dbi->select(
2144
    table => 'table1',
2145
    column => 'latest_table1.key1 as latest_table1__key1',
2146
    join  => $join
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2147
)->all;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2148
is_deeply($rows, [{latest_table1__key1 => 1}]);
2149

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2150
test 'mycolumn';
2151
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2152
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2153
$dbi->execute($CREATE_TABLE->{2});
2154
$dbi->setup_model;
2155
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2156
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2157
$model = $dbi->model('table1');
2158
$result = $model->select_at(
2159
    column => [
2160
        $model->mycolumn,
2161
        $model->column('table2')
2162
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2163
);
added tests
Yuki Kimoto authored on 2011-06-08
2164
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2165
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2166

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2167
$result = $model->select_at(
2168
    column => [
2169
        $model->mycolumn(['key1']),
2170
        $model->column(table2 => ['key1'])
2171
    ]
2172
);
added tests
Yuki Kimoto authored on 2011-06-08
2173
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2174
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2175
$result = $model->select_at(
2176
    column => [
2177
        $model->mycolumn(['key1']),
2178
        {table2 => ['key1']}
2179
    ]
2180
);
added tests
Yuki Kimoto authored on 2011-06-08
2181
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2182
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2183

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2184
$result = $model->select_at(
2185
    column => [
2186
        $model->mycolumn(['key1']),
2187
        ['table2.key1', as => 'table2.key1']
2188
    ]
2189
);
2190
is_deeply($result->one,
2191
          {key1 => 1, 'table2.key1' => 1});
2192

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2193
$result = $model->select_at(
2194
    column => [
2195
        $model->mycolumn(['key1']),
2196
        ['table2.key1' => 'table2.key1']
2197
    ]
2198
);
2199
is_deeply($result->one,
2200
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2201

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2202
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2203
{
2204
    package MyDBI9;
2205
    
2206
    use base 'DBIx::Custom';
2207
    
2208
    sub connect {
2209
        my $self = shift->SUPER::connect(@_);
2210
        
2211
        $self->include_model('MyModel8')->setup_model;
2212
        
2213
        return $self;
2214
    }
2215
}
2216
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2217
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2218
$model = $dbi->model('table1');
2219
eval{$model->execute('select * from table1')};
2220
ok(!$@);
2221

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2222
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2223
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2224
$dbi->execute($CREATE_TABLE->{0});
2225
$dbi->execute($CREATE_TABLE->{2});
2226
$dbi->setup_model;
2227
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2228
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2229
$model = $dbi->model('table1');
2230
$result = $model->select(
2231
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2232
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2233
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2234
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2235
);
added tests
Yuki Kimoto authored on 2011-06-08
2236
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2237
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2238

            
cleanup
Yuki Kimoto authored on 2011-06-13
2239
$dbi->separator('__');
2240
$result = $model->select(
2241
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2242
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2243
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2244
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2245
);
2246
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2247
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2248

            
2249
$dbi->separator('-');
2250
$result = $model->select(
2251
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2252
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2253
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2254
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2255
);
2256
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2257
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2258

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2259
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2260
$dbi = DBIx::Custom->connect(
2261
    data_source => 'dbi:SQLite:dbname=:memory:',
2262
    dbi_option => {
2263
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2264
    }
2265
);
2266
my $binary = pack("I3", 1, 2, 3);
2267
$dbi->execute('create table table1(key1, key2)');
2268
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2269
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2270
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2271
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2272
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2273
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2274
is($row->{key1_length}, length $binary);
2275

            
2276
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2277
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2278
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2279
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2280
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2281
$row = $result->one;
2282
is($row->{key1_length}, length $binary);
2283

            
2284

            
2285
test 'bind_type option';
2286
$dbi = DBIx::Custom->connect(
2287
    data_source => 'dbi:SQLite:dbname=:memory:',
2288
    dbi_option => {
2289
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2290
    }
2291
);
2292
$binary = pack("I3", 1, 2, 3);
2293
$dbi->execute('create table table1(key1, key2)');
2294
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2295
$result = $dbi->select(table => 'table1');
2296
$row   = $result->one;
2297
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2298
$result = $dbi->execute('select length(key1) as key1_length from table1');
2299
$row = $result->one;
2300
is($row->{key1_length}, length $binary);
2301

            
2302
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2303
$result = $dbi->select(table => 'table1');
2304
$row   = $result->one;
2305
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2306
$result = $dbi->execute('select length(key1) as key1_length from table1');
2307
$row = $result->one;
2308
is($row->{key1_length}, length $binary);
2309

            
2310
test 'model type attribute';
2311
$dbi = DBIx::Custom->connect(
2312
    data_source => 'dbi:SQLite:dbname=:memory:',
2313
    dbi_option => {
2314
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2315
    }
2316
);
2317
$binary = pack("I3", 1, 2, 3);
2318
$dbi->execute('create table table1(key1, key2)');
2319
$model = $dbi->create_model(table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
2320
$model->insert(param => {key1 => $binary, key2 => 'あ'});
2321
$result = $dbi->select(table => 'table1');
2322
$row   = $result->one;
2323
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2324
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2325
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2326
is($row->{key1_length}, length $binary);
2327

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2328
test 'create_model';
2329
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2330
$dbi->execute($CREATE_TABLE->{0});
2331
$dbi->execute($CREATE_TABLE->{2});
2332

            
2333
$dbi->create_model(
2334
    table => 'table1',
2335
    join => [
2336
       'left outer join table2 on table1.key1 = table2.key1'
2337
    ],
2338
    primary_key => ['key1']
2339
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2340
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2341
    table => 'table2'
2342
);
2343
$dbi->create_model(
2344
    table => 'table3',
2345
    filter => [
2346
        key1 => {in => sub { uc $_[0] }}
2347
    ]
2348
);
2349
$dbi->setup_model;
2350
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2351
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2352
$model = $dbi->model('table1');
2353
$result = $model->select(
2354
    column => [$model->mycolumn, $model->column('table2')],
2355
    where => {'table1.key1' => 1}
2356
);
added tests
Yuki Kimoto authored on 2011-06-08
2357
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2358
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2359
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2360

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2361
test 'model method';
2362
test 'create_model';
2363
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2364
$dbi->execute($CREATE_TABLE->{2});
2365
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2366
$model = $dbi->create_model(
2367
    table => 'table2'
2368
);
2369
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2370
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2371

            
2372
test 'merge_param';
2373
{
2374
    my $dbi = DBIx::Custom->new;
2375
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2376
    my $param2 = {key1 => 1, key2 => 2};
2377
    my $param3 = {key1 => 1};
2378
    my $param = $dbi->merge_param($param1, $param2, $param3);
2379
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2380
}
2381

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2382
{
2383
    my $dbi = DBIx::Custom->new;
2384
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2385
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2386
    my $param = $dbi->merge_param($param1, $param2);
2387
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2388
}
2389

            
cleanup
Yuki Kimoto authored on 2011-04-01
2390
test 'select() param option';
2391
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2392
$dbi->execute($CREATE_TABLE->{0});
2393
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2394
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2395
$dbi->execute($CREATE_TABLE->{2});
2396
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2397
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2398
$rows = $dbi->select(
2399
    table => 'table1',
2400
    column => 'table1.key1 as table1_key1, key2, key3',
2401
    where   => {'table1.key2' => 3},
2402
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2403
              ' as table2 on table1.key1 = table2.key1'],
2404
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2405
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2406
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2407

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

            
2409
test 'select() wrap option';
2410
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2411
$dbi->execute($CREATE_TABLE->{0});
2412
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2413
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2414
$rows = $dbi->select(
2415
    table => 'table1',
2416
    column => 'key1',
2417
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2418
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2419
is_deeply($rows, [{key1 => 1}]);
2420

            
2421
eval {
2422
$dbi->select(
2423
    table => 'table1',
2424
    column => 'key1',
2425
    wrap => 'select * from ('
2426
)
2427
};
cleanup
Yuki Kimoto authored on 2011-04-25
2428
like($@, qr/array/);
2429

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

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

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

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

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

            
2483
test 'update() string where';
2484
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2485
$dbi->execute($CREATE_TABLE->{0});
2486
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2487
$dbi->update(
2488
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2489
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2490
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2491
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2492
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2493
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2494
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2495

            
updated pod
Yuki Kimoto authored on 2011-06-21
2496
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2497
$dbi->execute($CREATE_TABLE->{0});
2498
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2499
$dbi->update(
2500
    table => 'table1',
2501
    param => {key1 => 5},
2502
    where => [
2503
        'key1 = :key1 and key2 = :key2',
2504
        {key1 => 1, key2 => 2}
2505
    ]
2506
);
2507
$rows = $dbi->select(table => 'table1')->all;
2508
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2509

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2510
test 'insert id and primary_key option';
2511
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2512
$dbi->execute($CREATE_TABLE->{1});
2513
$dbi->insert(
2514
    primary_key => ['key1', 'key2'], 
2515
    table => 'table1',
2516
    id => [1, 2],
2517
    param => {key3 => 3}
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

            
2523
$dbi->delete_all(table => 'table1');
2524
$dbi->insert(
2525
    primary_key => 'key1', 
2526
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2527
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2528
    param => {key2 => 2, key3 => 3}
2529
);
2530

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

            
2535
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2536
$dbi->execute($CREATE_TABLE->{1});
2537
$dbi->insert(
2538
    {key3 => 3},
2539
    primary_key => ['key1', 'key2'], 
2540
    table => 'table1',
2541
    id => [1, 2],
2542
);
2543
is($dbi->select(table => 'table1')->one->{key1}, 1);
2544
is($dbi->select(table => 'table1')->one->{key2}, 2);
2545
is($dbi->select(table => 'table1')->one->{key3}, 3);
2546

            
cleanup
Yuki Kimoto authored on 2011-06-08
2547

            
added tests
Yuki Kimoto authored on 2011-06-08
2548
test 'model insert id and primary_key option';
2549
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2550
$dbi->execute($CREATE_TABLE->{1});
2551
$dbi->model('table1')->insert(
2552
    id => [1, 2],
2553
    param => {key3 => 3}
2554
);
2555
$result = $dbi->model('table1')->select;
2556
$row = $result->one;
2557
is($row->{key1}, 1);
2558
is($row->{key2}, 2);
2559
is($row->{key3}, 3);
2560

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2561
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2562
$dbi->execute($CREATE_TABLE->{1});
2563
$dbi->model('table1')->insert(
2564
    {key3 => 3},
2565
    id => [1, 2]
2566
);
2567
$result = $dbi->model('table1')->select;
2568
$row = $result->one;
2569
is($row->{key1}, 1);
2570
is($row->{key2}, 2);
2571
is($row->{key3}, 3);
2572

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2573
test 'update and id option';
2574
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2575
$dbi->execute($CREATE_TABLE->{1});
2576
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2577
$dbi->update(
2578
    table => 'table1',
2579
    primary_key => ['key1', 'key2'],
2580
    id => [1, 2],
2581
    param => {key3 => 4}
2582
);
2583
is($dbi->select(table => 'table1')->one->{key1}, 1);
2584
is($dbi->select(table => 'table1')->one->{key2}, 2);
2585
is($dbi->select(table => 'table1')->one->{key3}, 4);
2586

            
2587
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2588
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2589
$dbi->update(
2590
    table => 'table1',
2591
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2592
    id => 0,
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2593
    param => {key3 => 4}
2594
);
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2595
is($dbi->select(table => 'table1')->one->{key1}, 0);
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2596
is($dbi->select(table => 'table1')->one->{key2}, 2);
2597
is($dbi->select(table => 'table1')->one->{key3}, 4);
2598

            
2599
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2600
$dbi->execute($CREATE_TABLE->{1});
2601
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2602
$dbi->update(
2603
    {key3 => 4},
2604
    table => 'table1',
2605
    primary_key => ['key1', 'key2'],
2606
    id => [1, 2]
2607
);
2608
is($dbi->select(table => 'table1')->one->{key1}, 1);
2609
is($dbi->select(table => 'table1')->one->{key2}, 2);
2610
is($dbi->select(table => 'table1')->one->{key3}, 4);
2611

            
2612

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2613
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2614
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2615
$dbi->execute($CREATE_TABLE->{1});
2616
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2617
$dbi->model('table1')->update(
2618
    id => [1, 2],
2619
    param => {key3 => 4}
2620
);
2621
$result = $dbi->model('table1')->select;
2622
$row = $result->one;
2623
is($row->{key1}, 1);
2624
is($row->{key2}, 2);
2625
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2626

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

            
2628
test 'delete and id option';
2629
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2630
$dbi->execute($CREATE_TABLE->{1});
2631
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2632
$dbi->delete(
2633
    table => 'table1',
2634
    primary_key => ['key1', 'key2'],
2635
    id => [1, 2],
2636
);
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

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2639
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2640
$dbi->delete(
2641
    table => 'table1',
2642
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2643
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2644
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2645
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2646

            
2647

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

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

            
2664
test 'select and id option';
2665
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2666
$dbi->execute($CREATE_TABLE->{1});
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
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2679
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2680
$result = $dbi->select(
2681
    table => 'table1',
2682
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2683
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2684
);
2685
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2686
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2687
is($row->{key2}, 2);
2688
is($row->{key3}, 3);
2689

            
2690
$dbi->delete_all(table => 'table1');
2691
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2692
$result = $dbi->select(
2693
    table => 'table1',
2694
    primary_key => ['key1', 'key2'],
2695
    id => [1, 2]
2696
);
2697
$row = $result->one;
2698
is($row->{key1}, 1);
2699
is($row->{key2}, 2);
2700
is($row->{key3}, 3);
2701

            
2702

            
2703
test 'model select_at';
2704
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2705
$dbi->execute($CREATE_TABLE->{1});
2706
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2707
$result = $dbi->model('table1')->select(id => [1, 2]);
2708
$row = $result->one;
2709
is($row->{key1}, 1);
2710
is($row->{key2}, 2);
2711
is($row->{key3}, 3);
2712

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2713
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2714
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2715
$dbi->execute($CREATE_TABLE->{0});
2716
$dbi->execute($CREATE_TABLE->{2});
2717
$dbi->setup_model;
2718
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2719
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2720
$model = $dbi->model('table1');
2721
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2722
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2723
    where => {'table1.key1' => 1}
2724
);
2725
is_deeply($result->one,
2726
          {'table2.key1' => 1, 'table2.key3' => 3});
2727

            
2728
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2729
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2730
    where => {'table1.key1' => 1}
2731
);
2732
is_deeply($result->one,
2733
          {'table2.key1' => 1, 'table2.key3' => 3});
2734

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

            
2736
test 'type_rule from';
2737
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2738
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2739
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2740
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2741
    }
2742
);
2743
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2744
$dbi->insert({key1 => 'a'}, table => 'table1');
2745
$result = $dbi->select(table => 'table1');
2746
is($result->fetch_first->[0], 'A');
2747

            
2748
$result = $dbi->select(table => 'table1');
2749
is($result->one->{key1}, 'A');
2750

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

            
2752
test 'type_rule into';
2753
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2754
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2755
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2756
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2757
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2758
    }
2759
);
2760
$dbi->insert({key1 => 'a'}, table => 'table1');
2761
$result = $dbi->select(table => 'table1');
2762
is($result->one->{key1}, 'A');
2763

            
2764
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2765
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2766
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2767
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2768
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2769
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2770
);
2771
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2772
$result = $dbi->select(table => 'table1');
2773
$row = $result->one;
2774
is($row->{key1}, 'A');
2775
is($row->{key2}, 'B');
2776

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

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

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2810
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2811
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2812
$dbi->register_filter(twice => sub { $_[0] * 2 });
2813
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2814
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2815
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2816
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2817
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2818
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2819
    }
2820
);
2821
$dbi->insert({key1 => 2}, table => 'table1');
2822
$result = $dbi->select(table => 'table1');
2823
is($result->fetch->[0], 8);
2824

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2825
test 'type_rule and filter order';
2826
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2827
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2828
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2829
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2830
        date => sub { $_[0] . 'b' }
2831
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2832
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2833
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2834
    },
2835
    from1 => {
2836
        date => sub { $_[0] . 'd' }
2837
    },
2838
    from2 => {
2839
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2840
    }
2841
);
2842
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2843
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2844
$result->filter(key1 => sub { $_[0] . 'f' });
2845
is($result->fetch_first->[0], '1abcdef');
2846

            
2847
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2848
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2849
$dbi->type_rule(
2850
    from1 => {
2851
        date => sub { $_[0] . 'p' }
2852
    },
2853
    from2 => {
2854
        date => sub { $_[0] . 'q' }
2855
    },
2856
);
2857
$dbi->insert({key1 => '1'}, table => 'table1');
2858
$result = $dbi->select(table => 'table1');
2859
$result->type_rule(
2860
    from1 => {
2861
        date => sub { $_[0] . 'd' }
2862
    },
2863
    from2 => {
2864
        date => sub { $_[0] . 'e' }
2865
    }
2866
);
2867
$result->filter(key1 => sub { $_[0] . 'f' });
2868
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2869

            
2870
test 'type_rule_off';
2871
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2872
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2873
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2874
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2875
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2876
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2877
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2878
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2879
    }
2880
);
2881
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2882
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2883
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2884

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

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

            
2913
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2914
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2915
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2916
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2917
        date => sub { $_[0] * 2 },
2918
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2919
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2920
        date => sub { $_[0] * 3 },
2921
    }
2922
);
2923
$dbi->insert({key1 => 2}, table => 'table1');
2924
$result = $dbi->select(table => 'table1');
2925
is($result->fetch->[0], 12);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2926

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2927
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2928
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2929
$dbi->register_filter(ppp => sub { uc $_[0] });
2930
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2931
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2932
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2933
    }
2934
);
2935
$dbi->insert({key1 => 'a'}, table => 'table1');
2936
$result = $dbi->select(table => 'table1');
2937
is($result->one->{key1}, 'A');
2938

            
2939
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2940
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2941
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
2942
    }
2943
)};
2944
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
2945

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2946
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2947
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2948
eval {
2949
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2950
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2951
            Date => sub { $_[0] * 2 },
2952
        }
2953
    );
2954
};
2955
like($@, qr/lower/);
2956

            
2957
eval {
2958
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2959
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2960
            Date => sub { $_[0] * 2 },
2961
        }
2962
    );
2963
};
2964
like($@, qr/lower/);
2965

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3000
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3001
$result->type_rule(
3002
    from1 => {
3003
        date => sub { $_[0] * 3 }
3004
    }
3005
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3006
$row = $result->one;
3007
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3008
is($row->{key2}, 2);
3009

            
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 => {
3013
        date => sub { $_[0] * 3 }
3014
    }
3015
);
cleanup
Yuki Kimoto authored on 2011-06-15
3016
$row = $result->one;
3017
is($row->{key1}, 6);
3018
is($row->{key2}, 2);
3019
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3020
$result->type_rule(
3021
    from1 => [date => sub { $_[0] * 3 }]
3022
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3023
$row = $result->one;
3024
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3025
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3026
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3027
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3028
$result->type_rule(
3029
    from1 => [date => 'fivetimes']
3030
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3031
$row = $result->one;
3032
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3033
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3034
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3035
$result->type_rule(
3036
    from1 => [date => undef]
3037
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3038
$row = $result->one;
3039
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3040
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3041

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3042
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3043
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3044
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3045
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3046
        date => sub { $_[0] * 2 },
3047
    },
3048
);
3049
$dbi->insert({key1 => 2}, table => 'table1');
3050
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3051
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3052
is($result->one->{key1}, 12);
3053

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

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

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

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

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3132
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3133
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3134
$dbi->execute($CREATE_TABLE->{0});
3135
$dbi->execute($CREATE_TABLE->{2});
3136

            
3137
$dbi->create_model(
3138
    table => 'table1',
3139
    join => [
3140
       'left outer join table2 on table1.key1 = table2.key1'
3141
    ],
3142
    primary_key => ['key1'],
3143
);
3144
$model2 = $dbi->create_model(
3145
    table => 'table2',
3146
);
3147
$dbi->setup_model;
3148
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3149
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3150
$model = $dbi->model('table1');
3151
$result = $model->select(
3152
    column => [
3153
        $model->mycolumn,
3154
        {table2 => [qw/key1 key3/]}
3155
    ],
3156
    where => {'table1.key1' => 1}
3157
);
3158
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3159
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3160
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3161

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3162
$dbi->separator('__');
3163
$model = $dbi->model('table1');
3164
$result = $model->select(
3165
    column => [
3166
        $model->mycolumn,
3167
        {table2 => [qw/key1 key3/]}
3168
    ],
3169
    where => {'table1.key1' => 1}
3170
);
3171
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3172
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3173
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3174

            
cleanup
Yuki Kimoto authored on 2011-06-13
3175
$dbi->separator('-');
3176
$model = $dbi->model('table1');
3177
$result = $model->select(
3178
    column => [
3179
        $model->mycolumn,
3180
        {table2 => [qw/key1 key3/]}
3181
    ],
3182
    where => {'table1.key1' => 1}
3183
);
3184
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3185
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3186
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3187

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3189
test 'filter_off';
3190
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3191
$dbi->execute($CREATE_TABLE->{0});
3192
$dbi->execute($CREATE_TABLE->{2});
3193

            
3194
$dbi->create_model(
3195
    table => 'table1',
3196
    join => [
3197
       'left outer join table2 on table1.key1 = table2.key1'
3198
    ],
3199
    primary_key => ['key1'],
3200
);
3201
$dbi->setup_model;
3202
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3203
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3204
$result = $model->select(column => 'key1');
3205
$result->filter(key1 => sub { $_[0] * 2 });
3206
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3207

            
3208
test 'available_date_type';
3209
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3210
ok($dbi->can('available_data_type'));
3211

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

            
3213
test 'select prefix option';
3214
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3215
$dbi->execute($CREATE_TABLE->{0});
3216
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3217
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3218
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3219

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

            
3221
test 'separator';
3222
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3223
is($dbi->separator, '.');
3224
$dbi->separator('-');
3225
is($dbi->separator, '-');
3226
$dbi->separator('__');
3227
is($dbi->separator, '__');
3228
eval { $dbi->separator('?') };
3229
like($@, qr/Separator/);
3230

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

            
3232
test 'map_param';
3233
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3234
$param = $dbi->map_param(
3235
    {id => 1, author => 'Ken', price => 1900},
3236
    id => 'book.id',
3237
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3238
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3239
);
3240
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3241
  'book.price' => 1900});
3242

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

            
3252
$param = $dbi->map_param(
3253
    {id => '', author => '', price => ''},
3254
    id => 'book.id',
3255
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3256
    price => ['book.price', sub { '%' . $_[0] . '%' },
3257
      {if => sub { $_[0] eq 1 }}]
3258
);
3259
is_deeply($param, {});
3260

            
3261
$param = $dbi->map_param(
3262
    {id => undef, author => undef, price => undef},
3263
    id => 'book.id',
3264
    price => ['book.price', {if => 'exists'}]
3265
);
3266
is_deeply($param, {'book.price' => undef});
3267

            
3268
$param = $dbi->map_param(
3269
    {price => 'a'},
3270
    id => ['book.id', {if => 'exists'}],
3271
    price => ['book.price', sub { '%' . $_[0] }, {if => 'exists'}]
3272
);
3273
is_deeply($param, {'book.price' => '%a'});
3274

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

            
3276
test 'table_alias';
3277
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3278
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3279
$dbi->type_rule(
3280
    into1 => {
3281
        date => sub { uc $_[0] }
3282
    }
3283
);
3284
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3285
  table_alias => {table2 => 'table1'});
3286
$result = $dbi->select(table => 'table1');
3287
is($result->one->{key1}, 'A');
3288

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

            
3290
test 'order';
3291
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3292
{
3293
    $dbi->execute("create table table1 (key1, key2)");
3294
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3295
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3296
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3297
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3298
    my $order = $dbi->order;
3299
    $order->prepend('key1', 'key2 desc');
3300
    $result = $dbi->select(table => 'table1', append => "$order");
3301
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3302
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3303
    $order->prepend('key1 desc');
3304
    $result = $dbi->select(table => 'table1', append => "$order");
3305
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3306
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
3307
}
3308

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3309
test 'tag_parse';
3310
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3311
$dbi->tag_parse(0);
3312
{
3313
    $dbi->execute("create table table1 (key1, key2)");
3314
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3315
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3316
    ok($@);
3317
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3318

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3319
test 'last_sql';
3320
{
3321
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3322
    $dbi->execute("create table table1 (key1, key2)");
3323
    $dbi->execute('select * from table1');
3324
    is($dbi->last_sql, 'select * from table1;');
3325
    
3326
    eval{$dbi->execute("aaa")};
3327
    is($dbi->last_sql, 'aaa;');
3328
    
3329
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3330

            
3331
test 'DBIx::Custom header';
3332
{
3333
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3334
    $dbi->execute("create table table1 (key1, key2)");
3335
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3336
    
3337
    is_deeply($result->header, [qw/h1 h2/]);
3338
    
3339
}
3340

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