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

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

            
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
9
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
10

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
214
test 'Named placeholder';
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
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

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
244
$dbi->execute($DROP_TABLE->{0});
245
$dbi->execute($CREATE_TABLE->{0});
246
$dbi->insert(table => 'table1', param => {key1 => '2011-10-14 12:19:18', key2 => 2});
247
$source = "select * from table1 where key1 = '2011-10-14 12:19:18' and key2 = :key2";
248
$result = $dbi->execute(
249
    $source,
250
    param => {'key2' => 2},
251
);
252

            
253
$rows = $result->all;
254
is_deeply($rows, [{key1 => '2011-10-14 12:19:18', key2 => 2}]);
255

            
256
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
257
$dbi->execute($CREATE_TABLE->{0});
258
$dbi->insert(table => 'table1', param => {key1 => 'a:b c:d', key2 => 2});
259
$source = "select * from table1 where key1 = 'a\\:b c\\:d' and key2 = :key2";
260
$result = $dbi->execute(
261
    $source,
262
    param => {'key2' => 2},
263
);
264
$rows = $result->all;
265
is_deeply($rows, [{key1 => 'a:b c:d', key2 => 2}]);
266

            
267

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

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

            
276
test 'insert';
277
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
278
$dbi->execute($CREATE_TABLE->{0});
279
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
280
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
add tests
yuki-kimoto authored on 2010-08-10
281
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
282
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
283
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
284

            
285
$dbi->execute('delete from table1');
286
$dbi->register_filter(
287
    twice       => sub { $_[0] * 2 },
288
    three_times => sub { $_[0] * 3 }
289
);
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
290
$dbi->default_bind_filter('twice');
removed register_format()
yuki-kimoto authored on 2010-05-26
291
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
add tests
yuki-kimoto authored on 2010-08-10
292
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
293
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
294
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
295
$dbi->default_bind_filter(undef);
removed register_format()
yuki-kimoto authored on 2010-05-26
296

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

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
309
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
310
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
311
$dbi->execute('create table "table" ("select")');
312
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
313
$dbi->insert(table => 'table', param => {select => 1});
314
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
315
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
316
is_deeply($rows, [{select => 2}], "reserved word");
317

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
318
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
319
$dbi->execute($CREATE_TABLE->{0});
320
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
321
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
322
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
323
$rows   = $result->all;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
324
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
325

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
326
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
327
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
328
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
329
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
330
$result = $dbi->execute($SELECT_SOURCES->{0});
331
$rows   = $result->all;
332
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
333

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
334
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
335
$dbi->execute($CREATE_TABLE->{0});
336
$dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
337
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
338
$result = $dbi->execute($SELECT_SOURCES->{0});
339
$rows   = $result->all;
340
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
341

            
removed register_format()
yuki-kimoto authored on 2010-05-26
342
test 'update';
343
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
344
$dbi->execute($CREATE_TABLE->{1});
345
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
346
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
347
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
348
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
349
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
350
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
351
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
352
                  "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
353
                  
354
$dbi->execute("delete from table1");
355
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
356
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
357
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
add tests
yuki-kimoto authored on 2010-08-10
358
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
359
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
360
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
361
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
362
                  "update key same as search key");
removed register_format()
yuki-kimoto authored on 2010-05-26
363

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
371
$dbi->execute("delete from table1");
372
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
373
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
374
$dbi->register_filter(twice => sub { $_[0] * 2 });
375
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
many changed
Yuki Kimoto authored on 2011-01-23
376
              filter => {key2 => sub { $_[0] * 2 }});
add tests
yuki-kimoto authored on 2010-08-10
377
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
378
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
379
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
380
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
381
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
382

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

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

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
391
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
392
$dbi->execute($CREATE_TABLE->{0});
393
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
394
$where = $dbi->where;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
395
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
396
$where->param({key1 => 1, key2 => 2});
397
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
398
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
399
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
400

            
401
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
402
$dbi->execute($CREATE_TABLE->{0});
403
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
404
$dbi->update(
405
    table => 'table1',
406
    param => {key1 => 3},
407
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
408
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
409
        {key1 => 1, key2 => 2}
410
    ]
411
);
412
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
413
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
414

            
415
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
416
$dbi->execute($CREATE_TABLE->{0});
417
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
418
$where = $dbi->where;
updated pod
Yuki Kimoto authored on 2011-06-21
419
$where->clause(['and', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
420
$where->param({key2 => 2});
421
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
422
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
423
is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
424

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
431
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
432
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
433
$dbi->execute('create table "table" ("select", "update")');
434
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
435
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
436
$dbi->insert(table => 'table', param => {select => 1});
437
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
438
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
439
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
440
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
441

            
442
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
443
like($@, qr/safety/);
444

            
445
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
446
$dbi->reserved_word_quote('"');
447
$dbi->execute('create table "table" ("select", "update")');
448
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
449
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
450
$dbi->insert(table => 'table', param => {select => 1});
451
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
452
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
453
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
454
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
455

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
456
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
457
$dbi->execute($CREATE_TABLE->{1});
458
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
459
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
460
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
461
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
462
$rows   = $result->all;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
463
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
464
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
465
                  "basic");
466

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
467
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
468
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
469
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
470
$dbi->update(table => 'table1', param => {key2 => 4},
471
  where => {key1 => 1}, prefix => 'or replace');
472
$result = $dbi->execute($SELECT_SOURCES->{0});
473
$rows   = $result->all;
474
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
475

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
476
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
477
$dbi->execute($CREATE_TABLE->{1});
478
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
479
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
480
$dbi->update(table => 'table1', param => {key2 => \"'11'"}, where => {key1 => 1});
481
$result = $dbi->execute($SELECT_SOURCES->{0});
482
$rows   = $result->all;
483
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
484
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
485
                  "basic");
486

            
removed register_format()
yuki-kimoto authored on 2010-05-26
487
test 'update_all';
488
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
489
$dbi->execute($CREATE_TABLE->{1});
490
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
491
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
492
$dbi->register_filter(twice => sub { $_[0] * 2 });
493
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
494
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
495
$rows   = $result->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
496
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
497
                  {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
cleanup
Yuki Kimoto authored on 2011-01-23
498
                  "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
499

            
500

            
501
test 'delete';
502
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
503
$dbi->execute($CREATE_TABLE->{0});
504
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
505
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
506
$dbi->delete(table => 'table1', where => {key1 => 1});
add tests
yuki-kimoto authored on 2010-08-10
507
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
508
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
509
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
510

            
511
$dbi->execute("delete from table1;");
512
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
513
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
514
$dbi->register_filter(twice => sub { $_[0] * 2 });
515
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
add tests
yuki-kimoto authored on 2010-08-10
516
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
517
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
518
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
519

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

            
522
$dbi->delete_all(table => 'table1');
523
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
524
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
525
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
526
$rows = $dbi->select(table => 'table1')->all;
cleanup
Yuki Kimoto authored on 2011-01-23
527
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
removed register_format()
yuki-kimoto authored on 2010-05-26
528

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

            
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
532
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
533
$dbi->execute($CREATE_TABLE->{0});
534
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
535
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
536
$where = $dbi->where;
updated pod
Yuki Kimoto authored on 2011-06-21
537
$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
538
$where->param({ke1 => 1, key2 => 2});
539
$dbi->delete(table => 'table1', where => $where);
540
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
541
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
542

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
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(
548
    table => 'table1',
549
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
550
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
551
        {ke1 => 1, key2 => 2}
552
    ]
553
);
554
$result = $dbi->select(table => 'table1');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
555
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
556

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
557
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
558
$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
559
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
560
$dbi->delete(table => 'table1', where => {key1 => 1}, prefix => '    ');
561
$result = $dbi->execute($SELECT_SOURCES->{0});
562
$rows   = $result->all;
563
is_deeply($rows, [], "basic");
564

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
575
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
576
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
577
$dbi->execute('create table "table" ("select", "update")');
578
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
579
$dbi->insert(table => 'table', param => {select => 1});
580
$dbi->delete(table => 'table', where => {select => 1});
581
$result = $dbi->execute('select * from "table"');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
582
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
583
is_deeply($rows, [], "reserved word");
584

            
removed register_format()
yuki-kimoto authored on 2010-05-26
585
test 'delete_all';
586
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
587
$dbi->execute($CREATE_TABLE->{0});
588
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
589
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
590
$dbi->delete_all(table => 'table1');
add tests
yuki-kimoto authored on 2010-08-10
591
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
592
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
593
is_deeply($rows, [], "basic");
removed register_format()
yuki-kimoto authored on 2010-05-26
594

            
595

            
596
test 'select';
597
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
598
$dbi->execute($CREATE_TABLE->{0});
599
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
600
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
601
$rows = $dbi->select(table => 'table1')->all;
removed register_format()
yuki-kimoto authored on 2010-05-26
602
is_deeply($rows, [{key1 => 1, key2 => 2},
cleanup
Yuki Kimoto authored on 2011-01-23
603
                  {key1 => 3, key2 => 4}], "table");
removed register_format()
yuki-kimoto authored on 2010-05-26
604

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

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

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

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

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

            
622
$dbi->execute($CREATE_TABLE->{2});
623
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
624
$rows = $dbi->select(
625
    table => [qw/table1 table2/],
select method column option ...
Yuki Kimoto authored on 2011-02-22
626
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
removed register_format()
yuki-kimoto authored on 2010-05-26
627
    where   => {'table1.key2' => 2},
added commit method
yuki-kimoto authored on 2010-05-27
628
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
629
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
630
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
631

            
632
$rows = $dbi->select(
633
    table => [qw/table1 table2/],
634
    column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
635
    relation  => {'table1.key1' => 'table2.key1'}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
636
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
637
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
638

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
642
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
643
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
644
$dbi->execute('create table "table" ("select", "update")');
645
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
646
$dbi->insert(table => 'table', param => {select => 1, update => 2});
647
$result = $dbi->select(table => 'table', where => {select => 1});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
648
$rows   = $result->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
649
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
650

            
removed register_format()
yuki-kimoto authored on 2010-05-26
651
test 'fetch filter';
652
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
653
$dbi->register_filter(
654
    twice       => sub { $_[0] * 2 },
655
    three_times => sub { $_[0] * 3 }
656
);
657
$dbi->default_fetch_filter('twice');
658
$dbi->execute($CREATE_TABLE->{0});
659
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
660
$result = $dbi->select(table => 'table1');
661
$result->filter({key1 => 'three_times'});
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
662
$row = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
663
is_deeply($row, {key1 => 3, key2 => 4}, "default_fetch_filter and filter");
removed register_format()
yuki-kimoto authored on 2010-05-26
664

            
665
test 'filters';
666
$dbi = DBIx::Custom->new;
667

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

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

            
added commit method
yuki-kimoto authored on 2010-05-27
674
test 'transaction';
675
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
676
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
677
$dbi->dbh->begin_work;
added commit method
yuki-kimoto authored on 2010-05-27
678
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
679
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
680
$dbi->dbh->commit;
added commit method
yuki-kimoto authored on 2010-05-27
681
$result = $dbi->select(table => 'table1');
- added DBIx::Custom::Result...
Yuki Kimoto authored on 2011-06-07
682
is_deeply(scalar $result->all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}],
cleanup
Yuki Kimoto authored on 2011-01-23
683
          "commit");
added commit method
yuki-kimoto authored on 2010-05-27
684

            
685
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
686
$dbi->execute($CREATE_TABLE->{0});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
687
$dbi->dbh->begin_work(0);
added commit method
yuki-kimoto authored on 2010-05-27
688
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
689
$dbi->dbh->rollback;
added commit method
yuki-kimoto authored on 2010-05-27
690

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

            
694
test 'cache';
695
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
696
$dbi->cache(1);
add cache attribute
yuki-kimoto authored on 2010-06-14
697
$dbi->execute($CREATE_TABLE->{0});
updated pod
Yuki Kimoto authored on 2011-06-21
698
$source = 'select * from table1 where key1 = :key1 and key2 = :key2;';
699
$dbi->execute($source, {}, query => 1);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
700
is_deeply($dbi->{_cached}->{$source}, 
add table tag
Yuki Kimoto authored on 2011-02-09
701
          {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
add cache attribute
yuki-kimoto authored on 2010-06-14
702

            
703
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
704
$dbi->execute($CREATE_TABLE->{0});
705
$dbi->{_cached} = {};
706
$dbi->cache(0);
707
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
708
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
709

            
add tests
yuki-kimoto authored on 2010-08-10
710
test 'execute';
711
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
712
$dbi->execute($CREATE_TABLE->{0});
removed experimental registe...
yuki-kimoto authored on 2010-08-24
713
{
714
    local $Carp::Verbose = 0;
715
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
716
    like($@, qr/\Qselect * frm table1;/, "fail prepare");
717
    like($@, qr/\.t /, "fail : not verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
718
}
719
{
720
    local $Carp::Verbose = 1;
721
    eval{$dbi->execute('select * frm table1')};
cleanup
Yuki Kimoto authored on 2011-01-23
722
    like($@, qr/Custom.*\.t /s, "fail : verbose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
723
}
add tests
yuki-kimoto authored on 2010-08-10
724

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

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

            
removed experimental registe...
yuki-kimoto authored on 2010-08-24
733
{
734
    local $Carp::Verbose = 0;
updated pod
Yuki Kimoto authored on 2011-06-21
735
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
736
    like($@, qr/\Q.t /, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
737
}
738
{
739
    local $Carp::Verbose = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
740
    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
cleanup
Yuki Kimoto authored on 2011-01-23
741
    like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
removed experimental registe...
yuki-kimoto authored on 2010-08-24
742
}
cleanup
yuki-kimoto authored on 2010-10-17
743

            
744

            
745
test 'transaction';
746
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
747
$dbi->execute($CREATE_TABLE->{0});
748

            
749
$dbi->begin_work;
750

            
751
eval {
752
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
753
    die "Error";
754
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
755
};
756

            
757
$dbi->rollback if $@;
758

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

            
763
$dbi->begin_work;
764

            
765
eval {
766
    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
767
    $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
768
};
769

            
770
$dbi->commit unless $@;
771

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

            
776
$dbi->dbh->{AutoCommit} = 0;
777
eval{ $dbi->begin_work };
cleanup
Yuki Kimoto authored on 2011-01-23
778
ok($@, "exception");
cleanup
yuki-kimoto authored on 2010-10-17
779
$dbi->dbh->{AutoCommit} = 1;
780

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
782
test 'method';
added helper method
yuki-kimoto authored on 2010-10-17
783
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
784
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
785
    one => sub { 1 }
786
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
787
$dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
788
    two => sub { 2 }
789
);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
790
$dbi->method({
added helper method
yuki-kimoto authored on 2010-10-17
791
    twice => sub {
792
        my $self = shift;
793
        return $_[0] * 2;
794
    }
795
});
796

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
804
test 'out filter';
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
805
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
806
$dbi->execute($CREATE_TABLE->{0});
807
$dbi->register_filter(twice => sub { $_[0] * 2 });
808
$dbi->register_filter(three_times => sub { $_[0] * 3});
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
809
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
810
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
811
              'key2' => {out => 'three_times', in => 'twice'});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
812
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
813
$result = $dbi->execute($SELECT_SOURCES->{0});
814
$row   = $result->fetch_hash_first;
cleanup
Yuki Kimoto authored on 2011-01-23
815
is_deeply($row, {key1 => 2, key2 => 6}, "insert");
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
816
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
817
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
818
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
819

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
820
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
821
$dbi->execute($CREATE_TABLE->{0});
822
$dbi->register_filter(twice => sub { $_[0] * 2 });
823
$dbi->register_filter(three_times => sub { $_[0] * 3});
824
$dbi->apply_filter(
825
    'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
826
              'key2' => {out => 'three_times', in => 'twice'});
827
$dbi->apply_filter(
828
    'table1', 'key1' => {out => undef}
829
); 
830
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
831
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
832
$row   = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
833
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
834

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
835
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
836
$dbi->execute($CREATE_TABLE->{0});
837
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
838
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
839
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
840
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
841
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef});
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
842
$dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
843
$result = $dbi->execute($SELECT_SOURCES->{0});
added tests
Yuki Kimoto authored on 2011-06-08
844
$row   = $result->one;
cleanup
Yuki Kimoto authored on 2011-01-23
845
is_deeply($row, {key1 => 4, key2 => 2}, "update");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
846

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

            
859
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
860
$dbi->execute($CREATE_TABLE->{0});
861
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
862
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
863
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
864
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
865
$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
866
$result = $dbi->select(table => 'table1', where => {key1 => 1});
867
$result->filter({'key2' => 'twice'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
868
$rows   = $result->all;
cleanup
Yuki Kimoto authored on 2011-01-23
869
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
870

            
871
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
872
$dbi->execute($CREATE_TABLE->{0});
873
$dbi->register_filter(twice => sub { $_[0] * 2 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
874
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
875
    'table1', 'key1' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
876
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
877
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
878
$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
879
                        param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
880
                        table => ['table1']);
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, [{key1 => 4, key2 => 2}], "execute");
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
883

            
add table tag
Yuki Kimoto authored on 2011-02-09
884
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
885
$dbi->execute($CREATE_TABLE->{0});
886
$dbi->register_filter(twice => sub { $_[0] * 2 });
887
$dbi->apply_filter(
888
    'table1', 'key1' => {out => 'twice', in => 'twice'}
889
);
890
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
updated pod
Yuki Kimoto authored on 2011-06-21
891
$result = $dbi->execute("select * from {table table1} where key1 = :key1 and key2 = :key2;",
add table tag
Yuki Kimoto authored on 2011-02-09
892
                        param => {key1 => 1, key2 => 2});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
893
$rows   = $result->all;
add table tag
Yuki Kimoto authored on 2011-02-09
894
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
895

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
896
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
897
$dbi->execute($CREATE_TABLE->{0});
898
$dbi->execute($CREATE_TABLE->{2});
899
$dbi->register_filter(twice => sub { $_[0] * 2 });
900
$dbi->register_filter(three_times => sub { $_[0] * 3 });
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
901
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
902
    'table1', 'key2' => {out => 'twice', in => 'twice'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
903
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
904
$dbi->apply_filter(
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
905
    'table2', 'key3' => {out => 'three_times', in => 'three_times'}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
906
);
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
907
$dbi->insert(table => 'table1', param => {key1 => 5, key2 => 2}, filter => {key2 => undef});
908
$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
909
$result = $dbi->select(
910
     table => ['table1', 'table2'],
911
     column => ['key2', 'key3'],
912
     where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
913

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

            
918
$result = $dbi->select(
919
     table => ['table1', 'table2'],
920
     column => ['key2', 'key3'],
921
     where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
922

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
927
test 'each_column';
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
928
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
929
$dbi->execute($CREATE_TABLE->{2});
930
$dbi->execute($CREATE_TABLE->{3});
931

            
932
$infos = [];
pod fix
Yuki Kimoto authored on 2011-01-21
933
$dbi->each_column(sub {
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
934
    my ($self, $table, $column, $cinfo) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
935
    
936
    if ($table =~ /^table/) {
937
         my $info = [$table, $column, $cinfo->{COLUMN_NAME}];
938
         push @$infos, $info;
939
    }
940
});
941
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
942
is_deeply($infos, 
943
    [
944
        ['table1', 'key1', 'key1'],
945
        ['table1', 'key2', 'key2'],
946
        ['table2', 'key1', 'key1'],
947
        ['table2', 'key3', 'key3']
948
    ]
cleanup
Yuki Kimoto authored on 2011-01-23
949
    
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
950
);
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
951
test 'each_table';
952
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
953
$dbi->execute($CREATE_TABLE->{2});
954
$dbi->execute($CREATE_TABLE->{3});
955

            
956
$infos = [];
957
$dbi->each_table(sub {
958
    my ($self, $table, $table_info) = @_;
959
    
960
    if ($table =~ /^table/) {
961
         my $info = [$table, $table_info->{TABLE_NAME}];
962
         push @$infos, $info;
963
    }
964
});
965
$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos];
966
is_deeply($infos, 
967
    [
968
        ['table1', 'table1'],
969
        ['table2', 'table2'],
970
    ]
971
);
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
972

            
add examples
Yuki Kimoto authored on 2011-01-07
973
test 'limit';
974
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
975
$dbi->execute($CREATE_TABLE->{0});
976
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
977
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
978
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
979
$dbi->register_tag(
add examples
Yuki Kimoto authored on 2011-01-07
980
    limit => sub {
981
        my ($count, $offset) = @_;
982
        
983
        my $s = '';
984
        $s .= "limit $count";
985
        $s .= " offset $offset" if defined $offset;
986
        
987
        return [$s, []];
988
    }
989
);
990
$rows = $dbi->select(
991
  table => 'table1',
992
  where => {key1 => 1},
993
  append => "order by key2 {limit 1 0}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
994
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
995
is_deeply($rows, [{key1 => 1, key2 => 2}]);
add examples
Yuki Kimoto authored on 2011-01-07
996
$rows = $dbi->select(
997
  table => 'table1',
998
  where => {key1 => 1},
999
  append => "order by key2 {limit 2 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1000
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
1001
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
add examples
Yuki Kimoto authored on 2011-01-07
1002
$rows = $dbi->select(
1003
  table => 'table1',
1004
  where => {key1 => 1},
1005
  append => "order by key2 {limit 1}"
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1006
)->all;
cleanup
Yuki Kimoto authored on 2011-01-23
1007
is_deeply($rows, [{key1 => 1, key2 => 2}]);
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1008

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1009
test 'connect super';
1010
{
1011
    package MyDBI;
1012
    
1013
    use base 'DBIx::Custom';
1014
    sub connect {
1015
        my $self = shift->SUPER::connect(@_);
1016
        
1017
        return $self;
1018
    }
1019
    
1020
    sub new {
cleanup
Yuki Kimoto authored on 2011-01-25
1021
        my $self = shift->SUPER::new(@_);
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1022
        
1023
        return $self;
1024
    }
1025
}
1026

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1038
{
1039
    package MyDBI2;
1040
    
1041
    use base 'DBIx::Custom';
1042
    sub connect {
1043
        my $self = shift->SUPER::new(@_);
1044
        $self->connect;
1045
        
1046
        return $self;
1047
    }
1048
}
1049

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

            
1055
test 'end_filter';
1056
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1057
$dbi->execute($CREATE_TABLE->{0});
1058
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1059
$result = $dbi->select(table => 'table1');
1060
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1061
$result->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 });
1062
$row = $result->fetch_first;
1063
is_deeply($row, [6, 40]);
1064

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1065
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1066
$dbi->execute($CREATE_TABLE->{0});
1067
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1068
$result = $dbi->select(table => 'table1');
1069
$result->filter([qw/key1 key2/] => sub { $_[0] * 2 });
1070
$result->end_filter([[qw/key1 key2/] => sub { $_[0] * 3 }]);
1071
$row = $result->fetch_first;
1072
is_deeply($row, [6, 12]);
1073

            
1074
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1075
$dbi->execute($CREATE_TABLE->{0});
1076
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1077
$result = $dbi->select(table => 'table1');
1078
$result->filter([[qw/key1 key2/] => sub { $_[0] * 2 }]);
1079
$result->end_filter([qw/key1 key2/] => sub { $_[0] * 3 });
1080
$row = $result->fetch_first;
1081
is_deeply($row, [6, 12]);
1082

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

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1090
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1091
$dbi->apply_filter('table1',
1092
    key1 => {end => sub { $_[0] * 3 } },
1093
    key2 => {end => 'five_times'}
1094
);
1095
$result = $dbi->select(table => 'table1');
1096
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
added tests
Yuki Kimoto authored on 2011-06-08
1097
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1098
is_deeply($row, {key1 => 6, key2 => 40}, 'apply_filter');
1099

            
1100
$dbi->register_filter(five_times => sub { $_[0] * 5 });
1101
$dbi->apply_filter('table1',
1102
    key1 => {end => sub { $_[0] * 3 } },
1103
    key2 => {end => 'five_times'}
1104
);
1105
$result = $dbi->select(table => 'table1');
1106
$result->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 });
1107
$result->filter(key1 => undef);
1108
$result->end_filter(key1 => undef);
added tests
Yuki Kimoto authored on 2011-06-08
1109
$row = $result->one;
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1110
is_deeply($row, {key1 => 1, key2 => 40}, 'apply_filter overwrite');
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1111

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1112
test 'remove_end_filter and remove_filter';
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1113
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1114
$dbi->execute($CREATE_TABLE->{0});
1115
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1116
$result = $dbi->select(table => 'table1');
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1117
$row = $result
1118
       ->filter(key1 => sub { $_[0] * 2 }, key2 => sub { $_[0] * 4 })
1119
       ->remove_filter
1120
       ->end_filter(key1 => sub { $_[0] * 3 }, key2 => sub { $_[0] * 5 })
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1121
       ->remove_end_filter
1122
       ->fetch_first;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1123
is_deeply($row, [1, 2]);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1124

            
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1125
test 'empty where select';
1126
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1127
$dbi->execute($CREATE_TABLE->{0});
1128
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1129
$result = $dbi->select(table => 'table1', where => {});
added tests
Yuki Kimoto authored on 2011-06-08
1130
$row = $result->one;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
1131
is_deeply($row, {key1 => 1, key2 => 2});
1132

            
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1133
test 'select query option';
1134
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1135
$dbi->execute($CREATE_TABLE->{0});
1136
$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
1137
is(ref $query, 'DBIx::Custom::Query');
1138
$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
1139
is(ref $query, 'DBIx::Custom::Query');
1140
$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
1141
is(ref $query, 'DBIx::Custom::Query');
1142
$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
1143
is(ref $query, 'DBIx::Custom::Query');
1144

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1145
test 'DBIx::Custom::Where';
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1146
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1147
$dbi->execute($CREATE_TABLE->{0});
1148
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1149
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
updated pod
Yuki Kimoto authored on 2011-06-21
1150
$where = $dbi->where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
1151
is("$where", "where ( key1 = :key1 and key2 = :key2 )", 'no param');
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1152

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

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1157
$result = $dbi->select(
1158
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1159
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1160
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1161
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1162
is_deeply($row, [{key1 => 1, key2 => 2}]);
1163

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1164
$result = $dbi->select(
1165
    table => 'table1',
1166
    where => [
updated pod
Yuki Kimoto authored on 2011-06-21
1167
        ['and', 'key1 = :key1', 'key2 = :key2'],
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1168
        {key1 => 1}
1169
    ]
1170
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1171
$row = $result->all;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1172
is_deeply($row, [{key1 => 1, key2 => 2}]);
1173

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1174
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1175
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1176
             ->param({key1 => 1, key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1177
$result = $dbi->select(
1178
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1179
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1180
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1181
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1182
is_deeply($row, [{key1 => 1, key2 => 2}]);
1183

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1184
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1185
             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1186
             ->param({});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1187
$result = $dbi->select(
1188
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1189
    where => $where,
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1190
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1191
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1192
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1193

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1194
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-07
1195
             ->clause(['and', ['or', 'key1 > :key1', 'key1 < :key1'], 'key2 = :key2'])
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1196
             ->param({key1 => [0, 3], key2 => 2});
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1197
$result = $dbi->select(
1198
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1199
    where => $where,
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1200
); 
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1201
$row = $result->all;
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1202
is_deeply($row, [{key1 => 1, key2 => 2}]);
1203

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1204
$where = $dbi->where;
1205
$result = $dbi->select(
1206
    table => 'table1',
1207
    where => $where
1208
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1209
$row = $result->all;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1210
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1211

            
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1212
eval {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1213
$where = $dbi->where
added test
Yuki Kimoto authored on 2011-01-19
1214
             ->clause(['uuu']);
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1215
$result = $dbi->select(
1216
    table => 'table1',
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1217
    where => $where
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1218
);
1219
};
1220
ok($@);
1221

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

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

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

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

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

            
1265
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1266
             ->clause('key1 = :key1 key2 = :key2')
many changed
Yuki Kimoto authored on 2011-01-23
1267
             ->param({key1 => 1});
1268
eval{$where->to_string};
1269
like($@, qr/one column/);
1270

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1271
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1272
             ->clause('key1 = :key1')
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1273
             ->param([]);
1274
eval{$where->to_string};
1275
like($@, qr/Parameter/);
1276

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

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

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

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

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

            
1327
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1328
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1329
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1330
$result = $dbi->select(
1331
    table => 'table1',
1332
    where => $where,
1333
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1334
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1335
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1336

            
1337
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1338
             ->clause(['or', ('key1 = :key1') x 3])
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1339
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1340
$result = $dbi->select(
1341
    table => 'table1',
1342
    where => $where,
1343
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1344
$row = $result->all;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1345
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1346

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1347
$where = $dbi->where
updated pod
Yuki Kimoto authored on 2011-06-21
1348
             ->clause(['or', ('key1 = :key1') x 3])
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1349
             ->param({key1 => []});
1350
$result = $dbi->select(
1351
    table => 'table1',
1352
    where => $where,
1353
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1354
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1355
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1356

            
1357
$where = $dbi->where
1358
             ->clause(['and', '{> key1}', '{< key1}' ])
1359
             ->param({key1 => [2, $dbi->not_exists]});
1360
$result = $dbi->select(
1361
    table => 'table1',
1362
    where => $where,
1363
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1364
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1365
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
1366

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

            
1377
$where = $dbi->where
1378
             ->clause(['and', '{> key1}', '{< key1}' ])
1379
             ->param({key1 => [$dbi->not_exists, $dbi->not_exists]});
1380
$result = $dbi->select(
1381
    table => 'table1',
1382
    where => $where,
1383
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1384
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1385
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
1386

            
1387
$where = $dbi->where
1388
             ->clause(['and', '{> key1}', '{< key1}' ])
1389
             ->param({key1 => [0, 2]});
1390
$result = $dbi->select(
1391
    table => 'table1',
1392
    where => $where,
1393
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1394
$row = $result->all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
1395
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1396

            
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1397
$where = $dbi->where
1398
             ->clause(['and', 'key1 is not null', 'key2 is not null' ]);
1399
$result = $dbi->select(
1400
    table => 'table1',
1401
    where => $where,
1402
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1403
$row = $result->all;
DBIx::Custom::Where clause a...
Yuki Kimoto authored on 2011-04-18
1404
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1405

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

            
fixed DBIx::Custom::Where to...
Yuki Kimoto authored on 2011-06-27
1409
$where = $dbi->where(
1410
    clause => ['and', ['or'], ['and', 'key1 = :key1', 'key2 = :key2']],
1411
    param => {key1 => 1, key2 => 2}
1412
);
1413
$result = $dbi->select(
1414
    table => 'table1',
1415
    where => $where,
1416
);
1417
$row = $result->all;
1418
is_deeply($row, [{key1 => 1, key2 => 2}]);
1419

            
1420

            
1421
$where = $dbi->where(
1422
    clause => ['and', ['or'], ['or', ':key1', ':key2']],
1423
    param => {}
1424
);
1425
$result = $dbi->select(
1426
    table => 'table1',
1427
    where => $where,
1428
);
1429
$row = $result->all;
1430
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1431

            
1432

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

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1437
test 'register_tag_processor';
1438
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1439
$dbi->register_tag_processor(
1440
    a => sub { 1 }
1441
);
1442
is($dbi->query_builder->tag_processors->{a}->(), 1);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1443

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1444
test 'register_tag';
1445
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1446
$dbi->register_tag(
1447
    b => sub { 2 }
1448
);
1449
is($dbi->query_builder->tags->{b}->(), 2);
1450

            
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
1451
test 'table not specify exception';
1452
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1453
eval {$dbi->insert};
1454
like($@, qr/table/);
1455
eval {$dbi->update};
1456
like($@, qr/table/);
1457
eval {$dbi->delete};
1458
like($@, qr/table/);
1459
eval {$dbi->select};
1460
like($@, qr/table/);
many changed
Yuki Kimoto authored on 2011-01-23
1461

            
1462

            
1463
test 'more tests';
1464
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1465
eval{$dbi->apply_filter('table', 'column', [])};
1466
like($@, qr/apply_filter/);
1467

            
1468
eval{$dbi->apply_filter('table', 'column', {outer => 2})};
1469
like($@, qr/apply_filter/);
1470

            
1471
$dbi->apply_filter(
1472

            
1473
);
1474
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1475
$dbi->execute($CREATE_TABLE->{0});
1476
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1477
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1478
$dbi->apply_filter('table1', 'key2', 
1479
                   {in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1480
$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1481
is_deeply($rows, [{key1 => 1, key2 => 6}]);
1482

            
1483
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1484
$dbi->execute($CREATE_TABLE->{0});
1485
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1486
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1487
$dbi->apply_filter('table1', 'key2', {});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1488
$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
many changed
Yuki Kimoto authored on 2011-01-23
1489
is_deeply($rows, [{key1 => 1, key2 => 2}]);
1490

            
1491
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1492
eval {$dbi->apply_filter('table1', 'key2', {out => 'no'})};
1493
like($@, qr/not registered/);
1494
eval {$dbi->apply_filter('table1', 'key2', {in => 'no'})};
1495
like($@, qr/not registered/);
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1496
$dbi->method({one => sub { 1 }});
many changed
Yuki Kimoto authored on 2011-01-23
1497
is($dbi->one, 1);
1498

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

            
1502
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1503
$dbi->execute($CREATE_TABLE->{0});
1504
$dbi->register_filter(twice => sub { $_[0] * 2 });
1505
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1506
             filter => {key1 => 'twice'});
added tests
Yuki Kimoto authored on 2011-06-08
1507
$row = $dbi->select(table => 'table1')->one;
many changed
Yuki Kimoto authored on 2011-01-23
1508
is_deeply($row, {key1 => 2, key2 => 2});
1509
eval {$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2},
1510
             filter => {key1 => 'no'}) };
1511
like($@, qr//);
1512

            
1513
$dbi->register_filter(one => sub { });
1514
$dbi->default_fetch_filter('one');
1515
ok($dbi->default_fetch_filter);
1516
$dbi->default_bind_filter('one');
1517
ok($dbi->default_bind_filter);
1518
eval{$dbi->default_fetch_filter('no')};
1519
like($@, qr/not registered/);
1520
eval{$dbi->default_bind_filter('no')};
1521
like($@, qr/not registered/);
1522
$dbi->default_bind_filter(undef);
1523
ok(!defined $dbi->default_bind_filter);
1524
$dbi->default_fetch_filter(undef);
1525
ok(!defined $dbi->default_fetch_filter);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1526
eval {$dbi->execute('select * from table1 {} {= author') };
many changed
Yuki Kimoto authored on 2011-01-23
1527
like($@, qr/Tag not finished/);
1528

            
1529
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1530
$dbi->execute($CREATE_TABLE->{0});
1531
$dbi->register_filter(one => sub { 1 });
1532
$result = $dbi->select(table => 'table1');
1533
eval {$result->filter(key1 => 'no')};
1534
like($@, qr/not registered/);
1535
eval {$result->end_filter(key1 => 'no')};
1536
like($@, qr/not registered/);
1537
$result->default_filter(undef);
1538
ok(!defined $result->default_filter);
1539
$result->default_filter('one');
1540
is($result->default_filter->(), 1);
1541

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1542
test 'dbi_option';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1543
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1544
                             dbi_option => {PrintError => 1});
1545
ok($dbi->dbh->{PrintError});
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1546
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1547
                             dbi_options => {PrintError => 1});
1548
ok($dbi->dbh->{PrintError});
1549

            
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-25
1550
test 'DBIx::Custom::Result stash()';
1551
$result = DBIx::Custom::Result->new;
1552
is_deeply($result->stash, {}, 'default');
1553
$result->stash->{foo} = 1;
1554
is($result->stash->{foo}, 1, 'get and set');
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
1555

            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1556
test 'filter __ expression';
1557
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1558
$dbi->execute('create table company (id, name, location_id)');
1559
$dbi->execute('create table location (id, name)');
1560
$dbi->apply_filter('location',
1561
  name => {in => sub { uc $_[0] } }
1562
);
1563

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

            
1567
$result = $dbi->select(
1568
    table => ['company', 'location'], relation => {'company.location_id' => 'location.id'},
1569
    column => ['location.name as location__name']
1570
);
1571
is($result->fetch_first->[0], 'B');
1572

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1573
$result = $dbi->select(
1574
    table => 'company', relation => {'company.location_id' => 'location.id'},
1575
    column => ['location.name as location__name']
1576
);
1577
is($result->fetch_first->[0], 'B');
1578

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
1579
$result = $dbi->select(
1580
    table => 'company', relation => {'company.location_id' => 'location.id'},
1581
    column => ['location.name as "location.name"']
1582
);
1583
is($result->fetch_first->[0], 'B');
1584

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1585
test 'Model class';
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1586
use MyDBI1;
1587
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1588
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1589
$model = $dbi->model('book');
1590
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1591
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1592
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1593
$model = $dbi->model('company');
1594
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1595
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add models() attribute
Yuki Kimoto authored on 2011-02-21
1596
is($dbi->models->{'book'}, $dbi->model('book'));
1597
is($dbi->models->{'company'}, $dbi->model('company'));
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1598

            
1599
{
1600
    package MyDBI4;
1601

            
1602
    use strict;
1603
    use warnings;
1604

            
1605
    use base 'DBIx::Custom';
1606

            
1607
    sub connect {
1608
        my $self = shift->SUPER::connect(@_);
1609
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1610
        $self->include_model(
1611
            MyModel2 => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1612
                'book',
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1613
                {class => 'Company', name => 'company'}
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1614
            ]
1615
        );
1616
    }
1617

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

            
1620
    use strict;
1621
    use warnings;
1622

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

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

            
1627
    use strict;
1628
    use warnings;
1629

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

            
1632
    sub insert {
1633
        my ($self, $param) = @_;
1634
        
1635
        return $self->SUPER::insert(param => $param);
1636
    }
1637

            
1638
    sub list { shift->select; }
1639

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

            
1642
    use strict;
1643
    use warnings;
1644

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

            
1647
    sub insert {
1648
        my ($self, $param) = @_;
1649
        
1650
        return $self->SUPER::insert(param => $param);
1651
    }
1652

            
1653
    sub list { shift->select; }
1654
}
1655
$dbi = MyDBI4->connect($NEW_ARGS->{0});
1656
$dbi->execute("create table book (title, author)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1657
$model = $dbi->model('book');
1658
$model->insert({title => 'a', author => 'b'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1659
is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1660
$dbi->execute("create table company (name)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1661
$model = $dbi->model('company');
1662
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1663
is_deeply($model->list->all, [{name => 'a'}], 'basic');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1664

            
1665
{
1666
     package MyDBI5;
1667

            
1668
    use strict;
1669
    use warnings;
1670

            
1671
    use base 'DBIx::Custom';
1672

            
1673
    sub connect {
1674
        my $self = shift->SUPER::connect(@_);
1675
        
1676
        $self->include_model('MyModel4');
1677
    }
1678
}
1679
$dbi = MyDBI5->connect($NEW_ARGS->{0});
1680
$dbi->execute("create table company (name)");
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1681
$dbi->execute("create table table1 (key1)");
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1682
$model = $dbi->model('company');
1683
$model->insert({name => 'a'});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1684
is_deeply($model->list->all, [{name => 'a'}], 'include all model');
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1685
$dbi->insert(table => 'table1', param => {key1 => 1});
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1686
$model = $dbi->model('book');
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1687
is_deeply($model->list->all, [{key1 => 1}], 'include all model');
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1688

            
add DBIx::Custom::Model fore...
Yuki Kimoto authored on 2011-02-21
1689
test 'primary_key';
1690
use MyDBI1;
1691
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1692
$model = $dbi->model('book');
1693
$model->primary_key(['id', 'number']);
1694
is_deeply($model->primary_key, ['id', 'number']);
1695

            
add DBIx::Custom::Model colu...
Yuki Kimoto authored on 2011-02-21
1696
test 'columns';
1697
use MyDBI1;
1698
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1699
$model = $dbi->model('book');
1700
$model->columns(['id', 'number']);
1701
is_deeply($model->columns, ['id', 'number']);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1702

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1703
test 'setup_model';
1704
use MyDBI1;
1705
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1706
$dbi->execute('create table book (id)');
1707
$dbi->execute('create table company (id, name);');
1708
$dbi->execute('create table test (id, name, primary key (id, name));');
1709
$dbi->setup_model;
1710
is_deeply($dbi->model('book')->columns, ['id']);
1711
is_deeply($dbi->model('company')->columns, ['id', 'name']);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1712

            
1713
test 'delete_at';
1714
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1715
$dbi->execute($CREATE_TABLE->{1});
1716
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1717
$dbi->delete_at(
1718
    table => 'table1',
1719
    primary_key => ['key1', 'key2'],
1720
    where => [1, 2],
1721
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1722
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1723

            
1724
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1725
$dbi->delete_at(
1726
    table => 'table1',
1727
    primary_key => 'key1',
1728
    where => 1,
1729
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1730
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1731

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

            
1745
$dbi->delete_all(table => 'table1');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1746
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1747
$dbi->insert_at(
1748
    primary_key => 'key1', 
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1749
    table => 'table1',
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1750
    where => 1,
1751
    param => {key2 => 2, key3 => 3}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1752
);
1753

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

            
1758
eval {
1759
    $dbi->insert_at(
1760
        table => 'table1',
1761
        primary_key => ['key1', 'key2'],
1762
        where => {},
1763
        param => {key1 => 1, key2 => 2, key3 => 3},
1764
    );
1765
};
1766
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1767

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

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

            
1794
$dbi->delete_all(table => 'table1');
1795
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1796
$dbi->update_at(
1797
    table => 'table1',
1798
    primary_key => 'key1',
1799
    where => 1,
1800
    param => {key3 => 4}
1801
);
added tests
Yuki Kimoto authored on 2011-06-08
1802
is($dbi->select(table => 'table1')->one->{key1}, 1);
1803
is($dbi->select(table => 'table1')->one->{key2}, 2);
1804
is($dbi->select(table => 'table1')->one->{key3}, 4);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1805

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1806
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1807
$dbi->execute($CREATE_TABLE->{1});
1808
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1809
$dbi->update_at(
1810
    {key3 => 4},
1811
    table => 'table1',
1812
    primary_key => ['key1', 'key2'],
1813
    where => [1, 2]
1814
);
added tests
Yuki Kimoto authored on 2011-06-08
1815
is($dbi->select(table => 'table1')->one->{key1}, 1);
1816
is($dbi->select(table => 'table1')->one->{key2}, 2);
1817
is($dbi->select(table => 'table1')->one->{key3}, 4);
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1818

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

            
1833
$dbi->delete_all(table => 'table1');
1834
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1835
$result = $dbi->select_at(
1836
    table => 'table1',
1837
    primary_key => 'key1',
1838
    where => 1,
1839
);
added tests
Yuki Kimoto authored on 2011-06-08
1840
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1841
is($row->{key1}, 1);
1842
is($row->{key2}, 2);
1843
is($row->{key3}, 3);
1844

            
1845
$dbi->delete_all(table => 'table1');
1846
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1847
$result = $dbi->select_at(
1848
    table => 'table1',
1849
    primary_key => ['key1', 'key2'],
cleanup
Yuki Kimoto authored on 2011-03-21
1850
    where => [1, 2]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1851
);
added tests
Yuki Kimoto authored on 2011-06-08
1852
$row = $result->one;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1853
is($row->{key1}, 1);
1854
is($row->{key2}, 2);
1855
is($row->{key3}, 3);
1856

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1857
eval {
1858
    $result = $dbi->select_at(
1859
        table => 'table1',
1860
        primary_key => ['key1', 'key2'],
1861
        where => {},
1862
    );
1863
};
1864
like($@, qr/must be/);
1865

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1866
eval {
1867
    $result = $dbi->select_at(
1868
        table => 'table1',
1869
        primary_key => ['key1', 'key2'],
1870
        where => [1],
1871
    );
1872
};
1873
like($@, qr/same/);
1874

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1875
eval {
1876
    $result = $dbi->update_at(
1877
        table => 'table1',
1878
        primary_key => ['key1', 'key2'],
1879
        where => {},
1880
        param => {key1 => 1, key2 => 2},
1881
    );
1882
};
1883
like($@, qr/must be/);
1884

            
1885
eval {
1886
    $result = $dbi->delete_at(
1887
        table => 'table1',
1888
        primary_key => ['key1', 'key2'],
1889
        where => {},
1890
    );
1891
};
1892
like($@, qr/must be/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1893

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1894
test 'columns';
1895
use MyDBI1;
1896
$dbi = MyDBI1->connect($NEW_ARGS->{0});
1897
$model = $dbi->model('book');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1898

            
1899

            
1900
test 'model delete_at';
1901
{
1902
    package MyDBI6;
1903
    
1904
    use base 'DBIx::Custom';
1905
    
1906
    sub connect {
1907
        my $self = shift->SUPER::connect(@_);
1908
        
1909
        $self->include_model('MyModel5');
1910
        
1911
        return $self;
1912
    }
1913
}
1914
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1915
$dbi->execute($CREATE_TABLE->{1});
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1916
$dbi->execute("create table table2 (key1, key2, key3)");
1917
$dbi->execute("create table table3 (key1, key2, key3)");
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1918
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1919
$dbi->model('table1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1920
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1921
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1922
$dbi->model('table1_1')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1923
is_deeply($dbi->select(table => 'table1')->all, []);
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1924
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
1925
$dbi->model('table1_3')->delete_at(where => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
1926
is_deeply($dbi->select(table => 'table1')->all, []);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1927

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

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1941
test 'model update_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1942
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1943
$dbi->execute($CREATE_TABLE->{1});
1944
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1945
$dbi->model('table1')->update_at(
1946
    where => [1, 2],
1947
    param => {key3 => 4}
1948
);
1949
$result = $dbi->model('table1')->select;
added tests
Yuki Kimoto authored on 2011-06-08
1950
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1951
is($row->{key1}, 1);
1952
is($row->{key2}, 2);
1953
is($row->{key3}, 4);
1954

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1955
test 'model select_at';
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1956
$dbi = MyDBI6->connect($NEW_ARGS->{0});
1957
$dbi->execute($CREATE_TABLE->{1});
1958
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
1959
$result = $dbi->model('table1')->select_at(where => [1, 2]);
added tests
Yuki Kimoto authored on 2011-06-08
1960
$row = $result->one;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
1961
is($row->{key1}, 1);
1962
is($row->{key2}, 2);
1963
is($row->{key3}, 3);
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1964

            
1965

            
cleanup
Yuki Kimoto authored on 2011-03-21
1966
test 'mycolumn and column';
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1967
{
1968
    package MyDBI7;
1969
    
1970
    use base 'DBIx::Custom';
1971
    
1972
    sub connect {
1973
        my $self = shift->SUPER::connect(@_);
1974
        
1975
        $self->include_model('MyModel6');
1976
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1977
        
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
1978
        return $self;
1979
    }
1980
}
1981
$dbi = MyDBI7->connect($NEW_ARGS->{0});
1982
$dbi->execute($CREATE_TABLE->{0});
1983
$dbi->execute($CREATE_TABLE->{2});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
1984
$dbi->separator('__');
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1985
$dbi->setup_model;
1986
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1987
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1988
$model = $dbi->model('table1');
cleanup
Yuki Kimoto authored on 2011-03-21
1989
$result = $model->select(
1990
    column => [$model->mycolumn, $model->column('table2')],
1991
    where => {'table1.key1' => 1}
1992
);
added tests
Yuki Kimoto authored on 2011-06-08
1993
is_deeply($result->one,
cleanup
Yuki Kimoto authored on 2011-03-21
1994
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1995

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

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

            
2015

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

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

            
2034
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2035
$dbi->execute($CREATE_TABLE->{1});
2036
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
2037
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
2038

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

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

            
2056

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

            
2063
$param = {key2 => 11};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2064
$update_param = $dbi->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2065
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2066
update table1 set $update_param
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2067
where key1 = 1
2068
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2069
$dbi->execute($sql, param => $param, table => 'table1');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2070
$result = $dbi->execute($SELECT_SOURCES->{0});
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2071
$rows   = $result->all;
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2072
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2073
                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
2074
                  "basic");
2075

            
2076

            
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2077
test 'insert_param';
2078
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2079
$dbi->execute($CREATE_TABLE->{1});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2080
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2081
$insert_param = $dbi->insert_param($param);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2082
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2083
insert into table1 $insert_param
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2084
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2085
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2086
is($dbi->select(table => 'table1')->one->{key1}, 1);
2087
is($dbi->select(table => 'table1')->one->{key2}, 2);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2088

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2089
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2090
$dbi->quote('"');
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2091
$dbi->execute($CREATE_TABLE->{1});
2092
$param = {key1 => 1, key2 => 2};
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2093
$insert_param = $dbi->insert_param($param);
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2094
$sql = <<"EOS";
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2095
insert into table1 $insert_param
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2096
EOS
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2097
$dbi->execute($sql, param => $param, table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2098
is($dbi->select(table => 'table1')->one->{key1}, 1);
2099
is($dbi->select(table => 'table1')->one->{key2}, 2);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
2100

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

            
2104

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2105
test 'join';
cleanup
Yuki Kimoto authored on 2011-03-08
2106
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2107
$dbi->execute($CREATE_TABLE->{0});
2108
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2109
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
2110
$dbi->execute($CREATE_TABLE->{2});
2111
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2112
$dbi->execute($CREATE_TABLE->{4});
2113
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
cleanup
Yuki Kimoto authored on 2011-03-08
2114
$rows = $dbi->select(
2115
    table => 'table1',
2116
    column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2117
    where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2118
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2119
)->all;
cleanup
Yuki Kimoto authored on 2011-03-08
2120
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
2121

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2122
$rows = $dbi->select(
2123
    table => 'table1',
2124
    where   => {'key1' => 1},
2125
    join  => ['left outer join table2 on table1.key1 = table2.key1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2126
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2127
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2128

            
cleanup
Yuki Kimoto authored on 2011-03-08
2129
eval {
2130
    $rows = $dbi->select(
2131
        table => 'table1',
2132
        column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
2133
        where   => {'table1.key2' => 2},
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2134
        join  => {'table1.key1' => 'table2.key1'}
cleanup
Yuki Kimoto authored on 2011-03-08
2135
    );
2136
};
2137
like ($@, qr/array/);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2138

            
2139
$rows = $dbi->select(
2140
    table => 'table1',
2141
    where   => {'key1' => 1},
2142
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2143
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2144
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2145
is_deeply($rows, [{key1 => 1, key2 => 2}]);
2146

            
2147
$rows = $dbi->select(
2148
    column => 'table3.key4 as table3__key4',
2149
    table => 'table1',
2150
    where   => {'table1.key1' => 1},
2151
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2152
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2153
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2154
is_deeply($rows, [{table3__key4 => 4}]);
2155

            
2156
$rows = $dbi->select(
2157
    column => 'table1.key1 as table1__key1',
2158
    table => 'table1',
2159
    where   => {'table3.key4' => 4},
2160
    join  => ['left outer join table2 on table1.key1 = table2.key1',
2161
              'left outer join table3 on table2.key3 = table3.key3']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2162
)->all;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
2163
is_deeply($rows, [{table1__key1 => 1}]);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2164

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2165
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2166
$dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2167
$dbi->execute($CREATE_TABLE->{0});
2168
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2169
$dbi->execute($CREATE_TABLE->{2});
2170
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2171
$rows = $dbi->select(
2172
    table => 'table1',
2173
    column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
2174
    where   => {'table1.key2' => 2},
2175
    join  => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2176
)->all;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2177
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
2178
          'quote');
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
2179

            
2180
{
2181
    package MyDBI8;
2182
    
2183
    use base 'DBIx::Custom';
2184
    
2185
    sub connect {
2186
        my $self = shift->SUPER::connect(@_);
2187
        
2188
        $self->include_model('MyModel7');
2189
        
2190
        return $self;
2191
    }
2192
}
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2193

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2194
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2195
$dbi->execute($CREATE_TABLE->{0});
2196
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2197
$sql = <<"EOS";
2198
left outer join (
2199
  select * from table1 as t1
2200
  where t1.key2 = (
2201
    select max(t2.key2) from table1 as t2
2202
    where t1.key1 = t2.key1
2203
  )
2204
) as latest_table1 on table1.key1 = latest_table1.key1
2205
EOS
2206
$join = [$sql];
2207
$rows = $dbi->select(
2208
    table => 'table1',
2209
    column => 'latest_table1.key1 as latest_table1__key1',
2210
    join  => $join
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2211
)->all;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2212
is_deeply($rows, [{latest_table1__key1 => 1}]);
2213

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

            
2244
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2245
$dbi->execute($CREATE_TABLE->{0});
2246
$dbi->execute($CREATE_TABLE->{2});
2247
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2248
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2249
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
2250
$result = $dbi->select(
2251
    table => 'table1',
2252
    column => [{table2 => ['key3']}],
2253
    join => [
2254
        {
2255
            clause => "left outer join table2 on table2.key3 = '4' and table1.key1 = table2.key1",
2256
            table => ['table1', 'table2']
2257
        }
2258
    ]
2259
);
2260
is_deeply($result->all, [{'table2.key3' => 4}]);
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2261

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2262
test 'mycolumn';
2263
$dbi = MyDBI8->connect($NEW_ARGS->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2264
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2265
$dbi->execute($CREATE_TABLE->{2});
2266
$dbi->setup_model;
2267
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2268
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2269
$model = $dbi->model('table1');
2270
$result = $model->select_at(
2271
    column => [
2272
        $model->mycolumn,
2273
        $model->column('table2')
2274
    ]
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2275
);
added tests
Yuki Kimoto authored on 2011-06-08
2276
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2277
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2278

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2279
$result = $model->select_at(
2280
    column => [
2281
        $model->mycolumn(['key1']),
2282
        $model->column(table2 => ['key1'])
2283
    ]
2284
);
added tests
Yuki Kimoto authored on 2011-06-08
2285
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2286
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2287
$result = $model->select_at(
2288
    column => [
2289
        $model->mycolumn(['key1']),
2290
        {table2 => ['key1']}
2291
    ]
2292
);
added tests
Yuki Kimoto authored on 2011-06-08
2293
is_deeply($result->one,
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2294
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-07
2295

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2296
$result = $model->select_at(
2297
    column => [
2298
        $model->mycolumn(['key1']),
2299
        ['table2.key1', as => 'table2.key1']
2300
    ]
2301
);
2302
is_deeply($result->one,
2303
          {key1 => 1, 'table2.key1' => 1});
2304

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2305
$result = $model->select_at(
2306
    column => [
2307
        $model->mycolumn(['key1']),
2308
        ['table2.key1' => 'table2.key1']
2309
    ]
2310
);
2311
is_deeply($result->one,
2312
          {key1 => 1, 'table2.key1' => 1});
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2313

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2314
test 'dbi method from model';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
2315
{
2316
    package MyDBI9;
2317
    
2318
    use base 'DBIx::Custom';
2319
    
2320
    sub connect {
2321
        my $self = shift->SUPER::connect(@_);
2322
        
2323
        $self->include_model('MyModel8')->setup_model;
2324
        
2325
        return $self;
2326
    }
2327
}
2328
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2329
$dbi->execute($CREATE_TABLE->{0});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2330
$model = $dbi->model('table1');
2331
eval{$model->execute('select * from table1')};
2332
ok(!$@);
2333

            
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2334
test 'column table option';
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2335
$dbi = MyDBI9->connect($NEW_ARGS->{0});
2336
$dbi->execute($CREATE_TABLE->{0});
2337
$dbi->execute($CREATE_TABLE->{2});
2338
$dbi->setup_model;
2339
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
2340
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
2341
$model = $dbi->model('table1');
2342
$result = $model->select(
2343
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2344
        $model->column('table2', {alias => 'table2_alias'})
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2345
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2346
    where => {'table2_alias.key3' => 4}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2347
);
added tests
Yuki Kimoto authored on 2011-06-08
2348
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2349
          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
2350

            
cleanup
Yuki Kimoto authored on 2011-06-13
2351
$dbi->separator('__');
2352
$result = $model->select(
2353
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2354
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2355
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2356
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2357
);
2358
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2359
          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2360

            
2361
$dbi->separator('-');
2362
$result = $model->select(
2363
    column => [
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2364
        $model->column('table2', {alias => 'table2_alias'})
cleanup
Yuki Kimoto authored on 2011-06-13
2365
    ],
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2366
    where => {'table2_alias.key3' => 4}
cleanup
Yuki Kimoto authored on 2011-06-13
2367
);
2368
is_deeply($result->one, 
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
2369
          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
cleanup
Yuki Kimoto authored on 2011-06-13
2370

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2371
test 'type option'; # DEPRECATED!
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2372
$dbi = DBIx::Custom->connect(
2373
    data_source => 'dbi:SQLite:dbname=:memory:',
2374
    dbi_option => {
2375
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2376
    }
2377
);
2378
my $binary = pack("I3", 1, 2, 3);
2379
$dbi->execute('create table table1(key1, key2)');
2380
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [key1 => DBI::SQL_BLOB]);
2381
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2382
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2383
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2384
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2385
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2386
is($row->{key1_length}, length $binary);
2387

            
2388
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, type => [['key1'] => DBI::SQL_BLOB]);
2389
$result = $dbi->select(table => 'table1');
added tests
Yuki Kimoto authored on 2011-06-08
2390
$row   = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2391
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2392
$result = $dbi->execute('select length(key1) as key1_length from table1');
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2393
$row = $result->one;
2394
is($row->{key1_length}, length $binary);
2395

            
2396

            
2397
test 'bind_type option';
2398
$dbi = DBIx::Custom->connect(
2399
    data_source => 'dbi:SQLite:dbname=:memory:',
2400
    dbi_option => {
2401
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2402
    }
2403
);
2404
$binary = pack("I3", 1, 2, 3);
2405
$dbi->execute('create table table1(key1, key2)');
2406
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [key1 => DBI::SQL_BLOB]);
2407
$result = $dbi->select(table => 'table1');
2408
$row   = $result->one;
2409
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2410
$result = $dbi->execute('select length(key1) as key1_length from table1');
2411
$row = $result->one;
2412
is($row->{key1_length}, length $binary);
2413

            
2414
$dbi->insert(table => 'table1', param => {key1 => $binary, key2 => 'あ'}, bind_type => [['key1'] => DBI::SQL_BLOB]);
2415
$result = $dbi->select(table => 'table1');
2416
$row   = $result->one;
2417
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2418
$result = $dbi->execute('select length(key1) as key1_length from table1');
2419
$row = $result->one;
2420
is($row->{key1_length}, length $binary);
2421

            
2422
test 'model type attribute';
2423
$dbi = DBIx::Custom->connect(
2424
    data_source => 'dbi:SQLite:dbname=:memory:',
2425
    dbi_option => {
2426
        $DBD::SQLite::VERSION > 1.26 ? (sqlite_unicode => 1) : (unicode => 1)
2427
    }
2428
);
2429
$binary = pack("I3", 1, 2, 3);
2430
$dbi->execute('create table table1(key1, key2)');
2431
$model = $dbi->create_model(table => 'table1', bind_type => [key1 => DBI::SQL_BLOB]);
2432
$model->insert(param => {key1 => $binary, key2 => 'あ'});
2433
$result = $dbi->select(table => 'table1');
2434
$row   = $result->one;
2435
is_deeply($row, {key1 => $binary, key2 => 'あ'}, "basic");
2436
$result = $dbi->execute('select length(key1) as key1_length from table1');
added tests
Yuki Kimoto authored on 2011-06-08
2437
$row = $result->one;
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2438
is($row->{key1_length}, length $binary);
2439

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2440
test 'create_model';
2441
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2442
$dbi->execute($CREATE_TABLE->{0});
2443
$dbi->execute($CREATE_TABLE->{2});
2444

            
2445
$dbi->create_model(
2446
    table => 'table1',
2447
    join => [
2448
       'left outer join table2 on table1.key1 = table2.key1'
2449
    ],
2450
    primary_key => ['key1']
2451
);
create_model() return model
Yuki Kimoto authored on 2011-03-29
2452
$model2 = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2453
    table => 'table2'
2454
);
2455
$dbi->create_model(
2456
    table => 'table3',
2457
    filter => [
2458
        key1 => {in => sub { uc $_[0] }}
2459
    ]
2460
);
2461
$dbi->setup_model;
2462
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2463
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2464
$model = $dbi->model('table1');
2465
$result = $model->select(
2466
    column => [$model->mycolumn, $model->column('table2')],
2467
    where => {'table1.key1' => 1}
2468
);
added tests
Yuki Kimoto authored on 2011-06-08
2469
is_deeply($result->one,
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2470
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
added tests
Yuki Kimoto authored on 2011-06-08
2471
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2472

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2473
test 'model method';
2474
test 'create_model';
2475
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2476
$dbi->execute($CREATE_TABLE->{2});
2477
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2478
$model = $dbi->create_model(
2479
    table => 'table2'
2480
);
2481
$model->method(foo => sub { shift->select(@_) });
added tests
Yuki Kimoto authored on 2011-06-08
2482
is_deeply($model->foo->one, {key1 => 1, key3 => 3});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2483

            
2484
test 'merge_param';
2485
{
2486
    my $dbi = DBIx::Custom->new;
2487
    my $param1 = {key1 => 1, key2 => 2, key3 => 3};
2488
    my $param2 = {key1 => 1, key2 => 2};
2489
    my $param3 = {key1 => 1};
2490
    my $param = $dbi->merge_param($param1, $param2, $param3);
2491
    is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3});
cleanup
Yuki Kimoto authored on 2011-04-01
2492
}
2493

            
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
2494
{
2495
    my $dbi = DBIx::Custom->new;
2496
    my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]};
2497
    my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3};
2498
    my $param = $dbi->merge_param($param1, $param2);
2499
    is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]});
2500
}
2501

            
cleanup
Yuki Kimoto authored on 2011-04-01
2502
test 'select() param option';
2503
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2504
$dbi->execute($CREATE_TABLE->{0});
2505
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2506
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2507
$dbi->execute($CREATE_TABLE->{2});
2508
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
2509
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
2510
$rows = $dbi->select(
2511
    table => 'table1',
2512
    column => 'table1.key1 as table1_key1, key2, key3',
2513
    where   => {'table1.key2' => 3},
2514
    join  => ['inner join (select * from table2 where {= table2.key3})' . 
2515
              ' as table2 on table1.key1 = table2.key1'],
2516
    param => {'table2.key3' => 5}
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2517
)->all;
cleanup
Yuki Kimoto authored on 2011-04-01
2518
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
2519

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

            
2521
test 'select() wrap option';
2522
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2523
$dbi->execute($CREATE_TABLE->{0});
2524
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2525
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2526
$rows = $dbi->select(
2527
    table => 'table1',
2528
    column => 'key1',
2529
    wrap => ['select * from (', ') as t where key1 = 1']
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2530
)->all;
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
2531
is_deeply($rows, [{key1 => 1}]);
2532

            
2533
eval {
2534
$dbi->select(
2535
    table => 'table1',
2536
    column => 'key1',
2537
    wrap => 'select * from ('
2538
)
2539
};
cleanup
Yuki Kimoto authored on 2011-04-25
2540
like($@, qr/array/);
2541

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2580
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2581
$dbi->execute($CREATE_TABLE->{0});
2582
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2583
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2584
$dbi->delete(
2585
    table => 'table1',
2586
    where => [
2587
        'key1 = :key1 and key2 = :key2',
2588
         {key1 => 1, key2 => 2}
2589
    ]
2590
);
2591
$rows = $dbi->select(table => 'table1')->all;
2592
is_deeply($rows, [{key1 => 2, key2 => 3}]);
2593

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

            
2595
test 'update() string where';
2596
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2597
$dbi->execute($CREATE_TABLE->{0});
2598
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2599
$dbi->update(
2600
    table => 'table1',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2601
    param => {key1 => 5},
updated pod
Yuki Kimoto authored on 2011-06-21
2602
    where => 'key1 = :key1 and key2 = :key2',
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2603
    where_param => {key1 => 1, key2 => 2}
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2604
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2605
$rows = $dbi->select(table => 'table1')->all;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
2606
is_deeply($rows, [{key1 => 5, key2 => 2}]);
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2607

            
updated pod
Yuki Kimoto authored on 2011-06-21
2608
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2609
$dbi->execute($CREATE_TABLE->{0});
2610
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2611
$dbi->update(
2612
    table => 'table1',
2613
    param => {key1 => 5},
2614
    where => [
2615
        'key1 = :key1 and key2 = :key2',
2616
        {key1 => 1, key2 => 2}
2617
    ]
2618
);
2619
$rows = $dbi->select(table => 'table1')->all;
2620
is_deeply($rows, [{key1 => 5, key2 => 2}]);
cleanup
Yuki Kimoto authored on 2011-06-08
2621

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2622
test 'insert id and primary_key option';
2623
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2624
$dbi->execute($CREATE_TABLE->{1});
2625
$dbi->insert(
2626
    primary_key => ['key1', 'key2'], 
2627
    table => 'table1',
2628
    id => [1, 2],
2629
    param => {key3 => 3}
2630
);
2631
is($dbi->select(table => 'table1')->one->{key1}, 1);
2632
is($dbi->select(table => 'table1')->one->{key2}, 2);
2633
is($dbi->select(table => 'table1')->one->{key3}, 3);
2634

            
2635
$dbi->delete_all(table => 'table1');
2636
$dbi->insert(
2637
    primary_key => 'key1', 
2638
    table => 'table1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2639
    id => 0,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2640
    param => {key2 => 2, key3 => 3}
2641
);
2642

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

            
2647
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2648
$dbi->execute($CREATE_TABLE->{1});
2649
$dbi->insert(
2650
    {key3 => 3},
2651
    primary_key => ['key1', 'key2'], 
2652
    table => 'table1',
2653
    id => [1, 2],
2654
);
2655
is($dbi->select(table => 'table1')->one->{key1}, 1);
2656
is($dbi->select(table => 'table1')->one->{key2}, 2);
2657
is($dbi->select(table => 'table1')->one->{key3}, 3);
2658

            
cleanup
Yuki Kimoto authored on 2011-06-08
2659

            
added tests
Yuki Kimoto authored on 2011-06-08
2660
test 'model insert id and primary_key option';
2661
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2662
$dbi->execute($CREATE_TABLE->{1});
2663
$dbi->model('table1')->insert(
2664
    id => [1, 2],
2665
    param => {key3 => 3}
2666
);
2667
$result = $dbi->model('table1')->select;
2668
$row = $result->one;
2669
is($row->{key1}, 1);
2670
is($row->{key2}, 2);
2671
is($row->{key3}, 3);
2672

            
- fixed bug that model inser...
Yuki Kimoto authored on 2011-06-10
2673
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2674
$dbi->execute($CREATE_TABLE->{1});
2675
$dbi->model('table1')->insert(
2676
    {key3 => 3},
2677
    id => [1, 2]
2678
);
2679
$result = $dbi->model('table1')->select;
2680
$row = $result->one;
2681
is($row->{key1}, 1);
2682
is($row->{key2}, 2);
2683
is($row->{key3}, 3);
2684

            
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2685
test 'update and id option';
2686
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2687
$dbi->execute($CREATE_TABLE->{1});
2688
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2689
$dbi->update(
2690
    table => 'table1',
2691
    primary_key => ['key1', 'key2'],
2692
    id => [1, 2],
2693
    param => {key3 => 4}
2694
);
2695
is($dbi->select(table => 'table1')->one->{key1}, 1);
2696
is($dbi->select(table => 'table1')->one->{key2}, 2);
2697
is($dbi->select(table => 'table1')->one->{key3}, 4);
2698

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

            
2711
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2712
$dbi->execute($CREATE_TABLE->{1});
2713
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2714
$dbi->update(
2715
    {key3 => 4},
2716
    table => 'table1',
2717
    primary_key => ['key1', 'key2'],
2718
    id => [1, 2]
2719
);
2720
is($dbi->select(table => 'table1')->one->{key1}, 1);
2721
is($dbi->select(table => 'table1')->one->{key2}, 2);
2722
is($dbi->select(table => 'table1')->one->{key3}, 4);
2723

            
2724

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2725
test 'model update and id option';
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2726
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2727
$dbi->execute($CREATE_TABLE->{1});
2728
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2729
$dbi->model('table1')->update(
2730
    id => [1, 2],
2731
    param => {key3 => 4}
2732
);
2733
$result = $dbi->model('table1')->select;
2734
$row = $result->one;
2735
is($row->{key1}, 1);
2736
is($row->{key2}, 2);
2737
is($row->{key3}, 4);
added tests
Yuki Kimoto authored on 2011-06-08
2738

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

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

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2751
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2752
$dbi->delete(
2753
    table => 'table1',
2754
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2755
    id => 0,
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2756
);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2757
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2758

            
2759

            
2760
test 'model delete and id option';
2761
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2762
$dbi->execute($CREATE_TABLE->{1});
2763
$dbi->execute("create table table2 (key1, key2, key3)");
2764
$dbi->execute("create table table3 (key1, key2, key3)");
2765
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2766
$dbi->model('table1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2767
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2768
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2769
$dbi->model('table1_1')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2770
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2771
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2772
$dbi->model('table1_3')->delete(id => [1, 2]);
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2773
is_deeply($dbi->select(table => 'table1')->all, []);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2774

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

            
2776
test 'select and id option';
2777
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2778
$dbi->execute($CREATE_TABLE->{1});
2779
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2780
$result = $dbi->select(
2781
    table => 'table1',
2782
    primary_key => ['key1', 'key2'],
2783
    id => [1, 2]
2784
);
2785
$row = $result->one;
2786
is($row->{key1}, 1);
2787
is($row->{key2}, 2);
2788
is($row->{key3}, 3);
2789

            
2790
$dbi->delete_all(table => 'table1');
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2791
$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2792
$result = $dbi->select(
2793
    table => 'table1',
2794
    primary_key => 'key1',
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2795
    id => 0,
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2796
);
2797
$row = $result->one;
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
2798
is($row->{key1}, 0);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
2799
is($row->{key2}, 2);
2800
is($row->{key3}, 3);
2801

            
2802
$dbi->delete_all(table => 'table1');
2803
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2804
$result = $dbi->select(
2805
    table => 'table1',
2806
    primary_key => ['key1', 'key2'],
2807
    id => [1, 2]
2808
);
2809
$row = $result->one;
2810
is($row->{key1}, 1);
2811
is($row->{key2}, 2);
2812
is($row->{key3}, 3);
2813

            
2814

            
2815
test 'model select_at';
2816
$dbi = MyDBI6->connect($NEW_ARGS->{0});
2817
$dbi->execute($CREATE_TABLE->{1});
2818
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2819
$result = $dbi->model('table1')->select(id => [1, 2]);
2820
$row = $result->one;
2821
is($row->{key1}, 1);
2822
is($row->{key2}, 2);
2823
is($row->{key3}, 3);
2824

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2825
test 'column separator is default .';
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2826
$dbi = MyDBI7->connect($NEW_ARGS->{0});
2827
$dbi->execute($CREATE_TABLE->{0});
2828
$dbi->execute($CREATE_TABLE->{2});
2829
$dbi->setup_model;
2830
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2831
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2832
$model = $dbi->model('table1');
2833
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2834
    column => [$model->column('table2')],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2835
    where => {'table1.key1' => 1}
2836
);
2837
is_deeply($result->one,
2838
          {'table2.key1' => 1, 'table2.key3' => 3});
2839

            
2840
$result = $model->select(
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
2841
    column => [$model->column('table2' => [qw/key1 key3/])],
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
2842
    where => {'table1.key1' => 1}
2843
);
2844
is_deeply($result->one,
2845
          {'table2.key1' => 1, 'table2.key3' => 3});
2846

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

            
2848
test 'type_rule from';
2849
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2850
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2851
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2852
        date => sub { uc $_[0] }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
2853
    }
2854
);
2855
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2856
$dbi->insert({key1 => 'a'}, table => 'table1');
2857
$result = $dbi->select(table => 'table1');
2858
is($result->fetch_first->[0], 'A');
2859

            
2860
$result = $dbi->select(table => 'table1');
2861
is($result->one->{key1}, 'A');
2862

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

            
2864
test 'type_rule into';
2865
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2866
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2867
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2868
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2869
        date => sub { uc $_[0] }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2870
    }
2871
);
2872
$dbi->insert({key1 => 'a'}, table => 'table1');
2873
$result = $dbi->select(table => 'table1');
2874
is($result->one->{key1}, 'A');
2875

            
2876
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2877
$dbi->execute("create table table1 (key1 date, key2 datetime)");
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2878
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2879
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2880
         [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2881
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2882
);
2883
$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
2884
$result = $dbi->select(table => 'table1');
2885
$row = $result->one;
2886
is($row->{key1}, 'A');
2887
is($row->{key2}, 'B');
2888

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

            
2905
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2906
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2907
$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1');
2908
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2909
    into1 => [
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2910
        [qw/date datetime/] => sub { uc $_[0] }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2911
    ]
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2912
);
2913
$result = $dbi->execute(
2914
    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
2915
    param => {key1 => 'a', 'table1.key2' => 'b'},
2916
    table => 'table1'
2917
);
2918
$row = $result->one;
2919
is($row->{key1}, 'A');
2920
is($row->{key2}, 'B');
2921

            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2922
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2923
$dbi->execute("create table table1 (key1 date, key2 datetime)");
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2924
$dbi->register_filter(twice => sub { $_[0] * 2 });
2925
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2926
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2927
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2928
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2929
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2930
        date => 'twice',
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
2931
    }
2932
);
2933
$dbi->insert({key1 => 2}, table => 'table1');
2934
$result = $dbi->select(table => 'table1');
2935
is($result->fetch->[0], 8);
2936

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2937
test 'type_rule and filter order';
2938
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2939
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2940
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2941
    into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2942
        date => sub { $_[0] . 'b' }
2943
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2944
    into2 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2945
        date => sub { $_[0] . 'c' }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2946
    },
2947
    from1 => {
2948
        date => sub { $_[0] . 'd' }
2949
    },
2950
    from2 => {
2951
        date => sub { $_[0] . 'e' }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2952
    }
2953
);
2954
$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
2955
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2956
$result->filter(key1 => sub { $_[0] . 'f' });
2957
is($result->fetch_first->[0], '1abcdef');
2958

            
2959
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2960
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2961
$dbi->type_rule(
2962
    from1 => {
2963
        date => sub { $_[0] . 'p' }
2964
    },
2965
    from2 => {
2966
        date => sub { $_[0] . 'q' }
2967
    },
2968
);
2969
$dbi->insert({key1 => '1'}, table => 'table1');
2970
$result = $dbi->select(table => 'table1');
2971
$result->type_rule(
2972
    from1 => {
2973
        date => sub { $_[0] . 'd' }
2974
    },
2975
    from2 => {
2976
        date => sub { $_[0] . 'e' }
2977
    }
2978
);
2979
$result->filter(key1 => sub { $_[0] . 'f' });
2980
is($result->fetch_first->[0], '1def');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2981

            
2982
test 'type_rule_off';
2983
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2984
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
2985
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2986
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2987
        date => sub { $_[0] * 2 },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2988
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2989
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
2990
        date => sub { $_[0] * 2 },
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2991
    }
2992
);
2993
$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
2994
$result = $dbi->select(table => 'table1', type_rule_off => 1);
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
2995
is($result->type_rule_off->fetch->[0], 2);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2996

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

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

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3039
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3040
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3041
$dbi->register_filter(ppp => sub { uc $_[0] });
3042
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3043
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3044
        date => 'ppp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3045
    }
3046
);
3047
$dbi->insert({key1 => 'a'}, table => 'table1');
3048
$result = $dbi->select(table => 'table1');
3049
is($result->one->{key1}, 'A');
3050

            
3051
eval{$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3052
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3053
        date => 'pp'
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3054
    }
3055
)};
3056
like($@, qr/not registered/);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3057

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3058
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3059
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3060
eval {
3061
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3062
        from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3063
            Date => sub { $_[0] * 2 },
3064
        }
3065
    );
3066
};
3067
like($@, qr/lower/);
3068

            
3069
eval {
3070
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3071
        into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3072
            Date => sub { $_[0] * 2 },
3073
        }
3074
    );
3075
};
3076
like($@, qr/lower/);
3077

            
3078
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3079
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3080
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3081
    from1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3082
        date => sub { $_[0] * 2 },
3083
    },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3084
    into1 => {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3085
        date => sub { $_[0] * 3 },
3086
    }
3087
);
3088
$dbi->insert({key1 => 2}, table => 'table1');
3089
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3090
$result->type_rule_off;
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3091
is($result->one->{key1}, 6);
3092

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3112
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3113
$result->type_rule(
3114
    from1 => {
3115
        date => sub { $_[0] * 3 }
3116
    }
3117
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3118
$row = $result->one;
3119
is($row->{key1}, 6);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3120
is($row->{key2}, 2);
3121

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3122
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3123
$result->type_rule(
3124
    from1 => {
3125
        date => sub { $_[0] * 3 }
3126
    }
3127
);
cleanup
Yuki Kimoto authored on 2011-06-15
3128
$row = $result->one;
3129
is($row->{key1}, 6);
3130
is($row->{key2}, 2);
3131
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3132
$result->type_rule(
3133
    from1 => [date => sub { $_[0] * 3 }]
3134
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3135
$row = $result->one;
3136
is($row->{key1}, 6);
cleanup
Yuki Kimoto authored on 2011-06-15
3137
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3138
$dbi->register_filter(fivetimes => sub { $_[0] * 5});
3139
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3140
$result->type_rule(
3141
    from1 => [date => 'fivetimes']
3142
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3143
$row = $result->one;
3144
is($row->{key1}, 10);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3145
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3146
$result = $dbi->select(table => 'table1');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3147
$result->type_rule(
3148
    from1 => [date => undef]
3149
);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3150
$row = $result->one;
3151
is($row->{key1}, 2);
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3152
is($row->{key2}, 2);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3153

            
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3154
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3155
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3156
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3157
    from1 => {
DBIx::Custom::Result filter ...
Yuki Kimoto authored on 2011-06-14
3158
        date => sub { $_[0] * 2 },
3159
    },
3160
);
3161
$dbi->insert({key1 => 2}, table => 'table1');
3162
$result = $dbi->select(table => 'table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3163
$result->filter(key1 => sub { $_[0] * 3 });
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3164
is($result->one->{key1}, 12);
3165

            
3166
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3167
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3168
$dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3169
    from1 => {
separate DBIx::Custom::Resul...
Yuki Kimoto authored on 2011-06-15
3170
        date => sub { $_[0] * 2 },
3171
    },
3172
);
3173
$dbi->insert({key1 => 2}, table => 'table1');
3174
$result = $dbi->select(table => 'table1');
3175
$result->filter(key1 => sub { $_[0] * 3 });
3176
is($result->fetch->[0], 12);
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
3177

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

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

            
3222
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3223
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3224
$dbi->type_rule(
3225
    into1 => {
3226
        date => sub { $_[0] . 'b' }
3227
    },
3228
    into2 => {
3229
        date => sub { $_[0] . 'c' }
3230
    },
3231
    from1 => {
3232
        date => sub { $_[0] . 'd' }
3233
    },
3234
    from2 => {
3235
        date => sub { $_[0] . 'e' }
3236
    }
3237
);
3238
$dbi->insert({key1 => '1'}, table => 'table1', type_rule2_off => 1);
3239
$result = $dbi->select(table => 'table1');
- changed EXPERIMENTAL DBIx:...
Yuki Kimoto authored on 2011-06-20
3240
is($result->type_rule2_off->fetch_first->[0], '1bd');
3241
$result = $dbi->select(table => 'table1');
3242
is($result->type_rule2_on->fetch_first->[0], '1bde');
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3243

            
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3244
test 'separator';
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3245
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3246
$dbi->execute($CREATE_TABLE->{0});
3247
$dbi->execute($CREATE_TABLE->{2});
3248

            
3249
$dbi->create_model(
3250
    table => 'table1',
3251
    join => [
3252
       'left outer join table2 on table1.key1 = table2.key1'
3253
    ],
3254
    primary_key => ['key1'],
3255
);
3256
$model2 = $dbi->create_model(
3257
    table => 'table2',
3258
);
3259
$dbi->setup_model;
3260
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3261
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3262
$model = $dbi->model('table1');
3263
$result = $model->select(
3264
    column => [
3265
        $model->mycolumn,
3266
        {table2 => [qw/key1 key3/]}
3267
    ],
3268
    where => {'table1.key1' => 1}
3269
);
3270
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3271
          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3272
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
3273

            
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3274
$dbi->separator('__');
3275
$model = $dbi->model('table1');
3276
$result = $model->select(
3277
    column => [
3278
        $model->mycolumn,
3279
        {table2 => [qw/key1 key3/]}
3280
    ],
3281
    where => {'table1.key1' => 1}
3282
);
3283
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3284
          {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
3285
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
3286

            
cleanup
Yuki Kimoto authored on 2011-06-13
3287
$dbi->separator('-');
3288
$model = $dbi->model('table1');
3289
$result = $model->select(
3290
    column => [
3291
        $model->mycolumn,
3292
        {table2 => [qw/key1 key3/]}
3293
    ],
3294
    where => {'table1.key1' => 1}
3295
);
3296
is_deeply($result->one,
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3297
          {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
3298
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
cleanup
Yuki Kimoto authored on 2011-06-13
3299

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

            
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
3301
test 'filter_off';
3302
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3303
$dbi->execute($CREATE_TABLE->{0});
3304
$dbi->execute($CREATE_TABLE->{2});
3305

            
3306
$dbi->create_model(
3307
    table => 'table1',
3308
    join => [
3309
       'left outer join table2 on table1.key1 = table2.key1'
3310
    ],
3311
    primary_key => ['key1'],
3312
);
3313
$dbi->setup_model;
3314
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3315
$model = $dbi->model('table1');
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
3316
$result = $model->select(column => 'key1');
3317
$result->filter(key1 => sub { $_[0] * 2 });
3318
is_deeply($result->one, {key1 => 2});
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
3319

            
3320
test 'available_date_type';
3321
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3322
ok($dbi->can('available_data_type'));
3323

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

            
3325
test 'select prefix option';
3326
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3327
$dbi->execute($CREATE_TABLE->{0});
3328
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3329
$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
3330
is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
3331

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

            
3333
test 'separator';
3334
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3335
is($dbi->separator, '.');
3336
$dbi->separator('-');
3337
is($dbi->separator, '-');
3338
$dbi->separator('__');
3339
is($dbi->separator, '__');
3340
eval { $dbi->separator('?') };
3341
like($@, qr/Separator/);
3342

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

            
3344
test 'map_param';
3345
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
3346
$param = $dbi->map_param(
3347
    {id => 1, author => 'Ken', price => 1900},
3348
    id => 'book.id',
3349
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3350
    price => ['book.price', {if => sub { $_[0] eq 1900 }}]
3351
);
3352
is_deeply($param, {'book.id' => 1, 'book.author' => '%Ken%',
3353
  'book.price' => 1900});
3354

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

            
3364
$param = $dbi->map_param(
3365
    {id => '', author => '', price => ''},
3366
    id => 'book.id',
3367
    author => ['book.author', sub { '%' . $_[0] . '%' }],
3368
    price => ['book.price', sub { '%' . $_[0] . '%' },
3369
      {if => sub { $_[0] eq 1 }}]
3370
);
3371
is_deeply($param, {});
3372

            
3373
$param = $dbi->map_param(
3374
    {id => undef, author => undef, price => undef},
3375
    id => 'book.id',
3376
    price => ['book.price', {if => 'exists'}]
3377
);
3378
is_deeply($param, {'book.price' => undef});
3379

            
3380
$param = $dbi->map_param(
3381
    {price => 'a'},
3382
    id => ['book.id', {if => 'exists'}],
3383
    price => ['book.price', sub { '%' . $_[0] }, {if => 'exists'}]
3384
);
3385
is_deeply($param, {'book.price' => '%a'});
3386

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

            
3388
test 'table_alias';
3389
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3390
$dbi->execute("create table table1 (key1 Date, key2 datetime)");
3391
$dbi->type_rule(
3392
    into1 => {
3393
        date => sub { uc $_[0] }
3394
    }
3395
);
3396
$dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1' => 'a'},
3397
  table_alias => {table2 => 'table1'});
3398
$result = $dbi->select(table => 'table1');
3399
is($result->one->{key1}, 'A');
3400

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

            
3402
test 'order';
3403
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3404
{
3405
    $dbi->execute("create table table1 (key1, key2)");
3406
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3407
    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3408
    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3409
    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3410
    my $order = $dbi->order;
3411
    $order->prepend('key1', 'key2 desc');
3412
    $result = $dbi->select(table => 'table1', append => "$order");
3413
    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3414
      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3415
    $order->prepend('key1 desc');
3416
    $result = $dbi->select(table => 'table1', append => "$order");
3417
    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3418
      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
added DBIx::Cusotm::Order pr...
Yuki Kimoto authored on 2011-07-11
3419

            
3420
    $order = $dbi->order;
3421
    $order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
3422
    $result = $dbi->select(table => 'table1',
3423
      column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
3424
      append => "$order");
3425
    is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
3426
      {'table1-key1' => 1, 'table1-key2' => 1},
3427
      {'table1-key1' => 2, 'table1-key2' => 4},
3428
      {'table1-key1' => 2, 'table1-key2' => 2}]);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3429
}
3430

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3431
test 'tag_parse';
3432
$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3433
$dbi->tag_parse(0);
3434
{
3435
    $dbi->execute("create table table1 (key1, key2)");
3436
    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3437
    eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
3438
    ok($@);
3439
}
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3440

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
3441
test 'last_sql';
3442
{
3443
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3444
    $dbi->execute("create table table1 (key1, key2)");
3445
    $dbi->execute('select * from table1');
3446
    is($dbi->last_sql, 'select * from table1;');
3447
    
3448
    eval{$dbi->execute("aaa")};
3449
    is($dbi->last_sql, 'aaa;');
3450
    
3451
}
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-07-11
3452

            
3453
test 'DBIx::Custom header';
3454
{
3455
    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3456
    $dbi->execute("create table table1 (key1, key2)");
3457
    my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
3458
    
3459
    is_deeply($result->header, [qw/h1 h2/]);
3460
    
3461
}
3462

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
3463
test 'Named placeholder :name(operater) syntax';
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
3464
$dbi->execute($DROP_TABLE->{0});
3465
$dbi->execute($CREATE_TABLE->{1});
3466
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
3467
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
3468

            
3469
$source = "select * from table1 where :key1{=} and :key2{=}";
3470
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
3471
$rows = $result->all;
3472
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3473

            
3474
$source = "select * from table1 where :key1{ = } and :key2{=}";
3475
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
3476
$rows = $result->all;
3477
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3478

            
3479
$source = "select * from table1 where :key1{<} and :key2{=}";
3480
$result = $dbi->execute($source, param => {key1 => 5, key2 => 2});
3481
$rows = $result->all;
3482
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3483

            
3484
$source = "select * from table1 where :table1.key1{=} and :table1.key2{=}";
3485
$result = $dbi->execute(
3486
    $source,
3487
    param => {'table1.key1' => 1, 'table1.key2' => 1},
3488
    filter => {'table1.key2' => sub { $_[0] * 2 }}
3489
);
3490
$rows = $result->all;
3491
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
3492

            
cleanup
Yuki Kimoto authored on 2011-07-30
3493
test 'high perfomance way';
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
3494
$dbi->execute($DROP_TABLE->{0});
3495
$dbi->execute("create table table1 (ab, bc, ik, hi, ui, pq, dc);");
3496
$rows = [
3497
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3498
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3499
];
3500
{
3501
    my $query;
3502
    foreach my $row (@$rows) {
3503
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
3504
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
3505
    }
3506
    is_deeply($dbi->select(table => 'table1')->all,
3507
      [
3508
          {ab => 2, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3509
          {ab => 2, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3510
      ]
3511
    );
3512
}
3513

            
cleanup
Yuki Kimoto authored on 2011-07-30
3514
$dbi->execute($DROP_TABLE->{0});
3515
$dbi->execute("create table table1 (ab, bc, ik, hi, ui, pq, dc);");
3516
$rows = [
3517
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3518
    {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3519
];
3520
{
3521
    my $query;
3522
    my $sth;
3523
    foreach my $row (@$rows) {
3524
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
3525
      $sth ||= $query->sth;
3526
      $sth->execute(map { $row->{$_} } sort keys %$row);
3527
    }
3528
    is_deeply($dbi->select(table => 'table1')->all,
3529
      [
3530
          {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 7},
3531
          {ab => 1, bc => 2, ik => 3, hi => 4, ui => 5, pq => 6, dc => 8},
3532
      ]
3533
    );
3534
}
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3535
=cut