DBIx-Custom / t / 02-sqlite.t /
Newer Older
372 lines | 14.399kb
add test
yuki-kimoto authored on 2009-10-18
1
use Test::More;
2
use strict;
3
use warnings;
4

            
5
BEGIN {
6
    eval { require DBD::SQLite; 1 }
7
        or plan skip_all => 'DBD::SQLite required';
8
    eval { DBD::SQLite->VERSION >= 1 }
9
        or plan skip_all => 'DBD::SQLite >= 1.00 required';
10

            
11
    plan 'no_plan';
12
    use_ok('DBI::Custom');
13
}
14

            
cleanup
yuki-kimoto authored on 2009-10-29
15
# Function for test name
16
my $test;
17
sub test {
18
    $test = shift;
19
}
add test
yuki-kimoto authored on 2009-10-18
20

            
cleanup#
yuki-kimoto authored on 2009-10-30
21
# Varialbes for test
add prepare
yuki-kimoto authored on 2009-10-31
22
our $CREATE_TABLE = {
add tests
yuki-kimoto authored on 2009-10-31
23
    0 => 'create table table1 (key1 char(255), key2 char(255));',
24
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));'
add prepare
yuki-kimoto authored on 2009-10-31
25
};
26

            
add tests
yuki-kimoto authored on 2009-10-31
27
our $SELECT_TMPL = {
add tests
yuki-kimoto authored on 2009-10-31
28
    0 => 'select * from table1;'
add tests
yuki-kimoto authored on 2009-10-31
29
};
30

            
cleanup
yuki-kimoto authored on 2009-10-29
31
my $dbi;
32
my $sth;
33
my $tmpl;
cleanup#
yuki-kimoto authored on 2009-10-30
34
my $select_tmpl;
35
my $insert_tmpl;
add tests
yuki-kimoto authored on 2009-10-31
36
my $update_tmpl;
cleanup
yuki-kimoto authored on 2009-10-29
37
my $params;
38
my $sql;
39
my $result;
40
my @rows;
41
my $rows;
add tests
yuki-kimoto authored on 2009-10-29
42
my $query;
cleanup#
yuki-kimoto authored on 2009-10-30
43
my $select_query;
44
my $insert_query;
add tests
yuki-kimoto authored on 2009-10-31
45
my $update_query;
add prepare
yuki-kimoto authored on 2009-10-31
46
my $ret_val;
cleanup#
yuki-kimoto authored on 2009-10-30
47

            
cleanup
yuki-kimoto authored on 2009-10-29
48

            
49

            
add tests
yuki-kimoto authored on 2009-10-31
50
test 'Disconnect';
51
$dbi = DBI::Custom->new(data_source => 'dbi:SQLite:dbname=:memory:');
52
$dbi->connect;
53
$dbi->disconnect;
54
ok(!$dbi->dbh, $test);
add tests
yuki-kimoto authored on 2009-10-31
55

            
cleanup
yuki-kimoto authored on 2009-10-29
56
# Prepare table
57
$dbi = DBI::Custom->new(data_source => 'dbi:SQLite:dbname=:memory:');
58
$dbi->connect;
add prepare
yuki-kimoto authored on 2009-10-31
59
$dbi->do($CREATE_TABLE->{0});
60
$sth = $dbi->prepare("insert into table1 (key1, key2) values (?, ?);");
cleanup
yuki-kimoto authored on 2009-10-29
61
$sth->execute(1, 2);
62
$sth->execute(3, 4);
add test
yuki-kimoto authored on 2009-10-18
63

            
add test module
yuki-kimoto authored on 2009-10-19
64

            
add tests
yuki-kimoto authored on 2009-10-29
65
test 'DBI::Custom::Result test';
66
$tmpl = "select key1, key2 from table1";
67
$query = $dbi->create_query($tmpl);
68
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
69

            
70
@rows = ();
71
while (my $row = $result->fetch) {
72
    push @rows, [@$row];
add test module
yuki-kimoto authored on 2009-10-19
73
}
add tests
yuki-kimoto authored on 2009-10-29
74
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch scalar context");
cleanup
yuki-kimoto authored on 2009-10-29
75

            
76

            
add tests
yuki-kimoto authored on 2009-10-29
77
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
78
@rows = ();
79
while (my @row = $result->fetch) {
80
    push @rows, [@row];
add test module
yuki-kimoto authored on 2009-10-19
81
}
add tests
yuki-kimoto authored on 2009-10-29
82
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch list context");
add test module
yuki-kimoto authored on 2009-10-19
83

            
cleanup
yuki-kimoto authored on 2009-10-29
84

            
add tests
yuki-kimoto authored on 2009-10-29
85
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
86
@rows = ();
87
while (my $row = $result->fetch_hash) {
88
    push @rows, {%$row};
add test module
yuki-kimoto authored on 2009-10-19
89
}
add tests
yuki-kimoto authored on 2009-10-29
90
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash scalar context");
cleanup
yuki-kimoto authored on 2009-10-29
91

            
92

            
add tests
yuki-kimoto authored on 2009-10-29
93
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
94
@rows = ();
95
while (my %row = $result->fetch_hash) {
96
    push @rows, {%row};
add test module
yuki-kimoto authored on 2009-10-19
97
}
add tests
yuki-kimoto authored on 2009-10-29
98
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch hash list context");
add test module
yuki-kimoto authored on 2009-10-19
99

            
100

            
add tests
yuki-kimoto authored on 2009-10-29
101
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
102
$rows = $result->fetch_all;
add tests
yuki-kimoto authored on 2009-10-29
103
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context");
cleanup
yuki-kimoto authored on 2009-10-29
104

            
105

            
add tests
yuki-kimoto authored on 2009-10-29
106
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
107
@rows = $result->fetch_all;
add tests
yuki-kimoto authored on 2009-10-29
108
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all list context");
cleanup
yuki-kimoto authored on 2009-10-29
109

            
110

            
add tests
yuki-kimoto authored on 2009-10-29
111
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
112
@rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-29
113
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all_hash scalar context");
cleanup
yuki-kimoto authored on 2009-10-29
114

            
115

            
add tests
yuki-kimoto authored on 2009-10-29
116
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
117
@rows = $result->fetch_all;
add tests
yuki-kimoto authored on 2009-10-29
118
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all_hash list context");
cleanup
yuki-kimoto authored on 2009-10-29
119

            
add tests
yuki-kimoto authored on 2009-10-31
120

            
add tests
yuki-kimoto authored on 2009-10-31
121
test 'Insert query return value';
122
$dbi->reconnect;
123
$dbi->do($CREATE_TABLE->{0});
124
$tmpl = "insert into table1 {insert key1 key2}";
125
$query = $dbi->create_query($tmpl);
126
$ret_val = $dbi->execute($query, {key1 => 1, key2 => 2});
127
ok($ret_val, $test);
128

            
add tests
yuki-kimoto authored on 2009-10-31
129

            
130
test 'Direct execute';
131
$dbi->reconnect;
132
$dbi->do($CREATE_TABLE->{0});
133
$insert_tmpl = "insert into table1 {insert key1 key2}";
134
$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}, sub {
135
    my $query = shift;
136
    $query->bind_filter(sub {
137
        my ($key, $value) = @_;
138
        if ($key eq 'key2') {
139
            return $value + 1;
140
        }
141
        return $value;
142
    });
143
});
144

            
145
$result = $dbi->execute($SELECT_TMPL->{0});
146

            
147
$rows = $result->fetch_all_hash;
148
is_deeply($rows, [{key1 => 1, key2 => 3}], $test);
149

            
150

            
cleanup#
yuki-kimoto authored on 2009-10-30
151
test 'Filter';
152
$dbi->reconnect;
add tests
yuki-kimoto authored on 2009-10-31
153
$dbi->do($CREATE_TABLE->{0});
cleanup#
yuki-kimoto authored on 2009-10-30
154

            
add tests
yuki-kimoto authored on 2009-10-31
155
$insert_tmpl  = "insert into table1 {insert key1 key2};";
add prepare
yuki-kimoto authored on 2009-10-31
156
$insert_query = $dbi->create_query($insert_tmpl);
157
$insert_query->bind_filter(sub {
add tests
yuki-kimoto authored on 2009-10-31
158
    my ($key, $value, $table, $column) = @_;
159
    if ($key eq 'key1' && $table eq '' && $column eq 'key1') {
add prepare
yuki-kimoto authored on 2009-10-31
160
        return $value * 2;
cleanup#
yuki-kimoto authored on 2009-10-30
161
    }
162
    return $value;
163
});
add tests
yuki-kimoto authored on 2009-10-31
164

            
add tests
yuki-kimoto authored on 2009-10-31
165
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
add prepare
yuki-kimoto authored on 2009-10-31
166

            
add tests
yuki-kimoto authored on 2009-10-31
167
$select_query = $dbi->create_query($SELECT_TMPL->{0});
add prepare
yuki-kimoto authored on 2009-10-31
168
$select_query->fetch_filter(sub {
add tests
yuki-kimoto authored on 2009-10-31
169
    my ($key, $value, $type, $sth, $i) = @_;
170
    if ($key eq 'key2' && $type =~ /char/ && $sth->can('execute') && $i == 1) {
add prepare
yuki-kimoto authored on 2009-10-31
171
        return $value * 3;
172
    }
173
    return $value;
174
});
175
$result = $dbi->execute($select_query);
cleanup#
yuki-kimoto authored on 2009-10-30
176

            
add prepare
yuki-kimoto authored on 2009-10-31
177
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
178
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter");
cleanup#
yuki-kimoto authored on 2009-10-30
179

            
add tests
yuki-kimoto authored on 2009-10-31
180

            
181
$dbi->do("delete from table1;");
182
$insert_query->no_bind_filters('key1');
183
$select_query->no_fetch_filters('key2');
184

            
185
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
186
$result = $dbi->execute($select_query);
187
$rows = $result->fetch_all_hash;
188
is_deeply($rows, [{key1 => 1, key2 => 2}], 'no_fetch_filters no_bind_filters');
189

            
190

            
add tests
yuki-kimoto authored on 2009-10-31
191
$dbi->reconnect;
192
$dbi->do($CREATE_TABLE->{0});
193
$insert_tmpl  = "insert into table1 {insert table1.key1 table1.key2}";
194

            
195
$insert_query = $dbi->create_query($insert_tmpl);
196
$insert_query->bind_filter(sub {
197
    my ($key, $value, $table, $column) = @_;
198
    if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1') {
199
        return $value * 3;
200
    }
201
    return $value;
202
});
203

            
204
$dbi->execute($insert_query, {table1 => {key1 => 1, key2 => 2}});
205

            
206
$select_query = $dbi->create_query($SELECT_TMPL->{0});
207
$result       = $dbi->execute($select_query);
208
$rows = $result->fetch_all_hash;
209
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
210

            
add tests
yuki-kimoto authored on 2009-10-31
211

            
add tests
yuki-kimoto authored on 2009-10-31
212
test 'DBI::Custom::SQL::Template basic tag';
add tests
yuki-kimoto authored on 2009-10-31
213
$dbi->reconnect;
214
$dbi->do($CREATE_TABLE->{1});
215
$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
216
$sth->execute(1, 2, 3, 4, 5);
217
$sth->execute(6, 7, 8, 9, 10);
add tests
yuki-kimoto authored on 2009-10-31
218

            
add tests
yuki-kimoto authored on 2009-10-31
219
$tmpl = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
220
$query = $dbi->create_query($tmpl);
221
$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
cleanup
yuki-kimoto authored on 2009-10-29
222
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
223
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
cleanup
yuki-kimoto authored on 2009-10-29
224

            
add tests
yuki-kimoto authored on 2009-10-31
225
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
226
$query = $dbi->create_query($tmpl);
227
$result = $dbi->execute($query, {table1 => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}});
228
$rows = $result->fetch_all_hash;
229
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table");
230

            
231
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
232
$query = $dbi->create_query($tmpl);
233
$result = $dbi->execute($query, {'table1.key1' => 1, 'table1.key2' => 3, 'table1.key3' => 4, 'table1.key4' => 3, 'table1.key5' => 5});
234
$rows = $result->fetch_all_hash;
235
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table dot");
236

            
add tests
yuki-kimoto authored on 2009-10-31
237
$tmpl = "select * from table1 where {<= key1} and {like key2};";
238
$query = $dbi->create_query($tmpl);
239
$result = $dbi->execute($query, {key1 => 1, key2 => '%2%'});
240
$rows = $result->fetch_all_hash;
241
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
cleanup
yuki-kimoto authored on 2009-10-29
242

            
add tests
yuki-kimoto authored on 2009-10-31
243
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
244
$query = $dbi->create_query($tmpl);
245
$result = $dbi->execute($query, {table1 => {key1 => 1, key2 => '%2%'}});
246
$rows = $result->fetch_all_hash;
247
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table");
248

            
249
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
250
$query = $dbi->create_query($tmpl);
251
$result = $dbi->execute($query, {'table1.key1' => 1, 'table1.key2' => '%2%'});
252
$rows = $result->fetch_all_hash;
253
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table dot");
254

            
255

            
add tests
yuki-kimoto authored on 2009-10-31
256
test 'DIB::Custom::SQL::Template in tag';
257
$dbi->reconnect;
258
$dbi->do($CREATE_TABLE->{1});
259
$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
260
$sth->execute(1, 2, 3, 4, 5);
261
$sth->execute(6, 7, 8, 9, 10);
262

            
263
$tmpl = "select * from table1 where {in key1 2};";
264
$query = $dbi->create_query($tmpl);
265
$result = $dbi->execute($query, {key1 => [9, 1]});
266
$rows = $result->fetch_all_hash;
267
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
268

            
269
$tmpl = "select * from table1 where {in table1.key1 2};";
270
$query = $dbi->create_query($tmpl);
271
$result = $dbi->execute($query, {table1 => {key1 => [9, 1]}});
272
$rows = $result->fetch_all_hash;
273
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table");
add tests
yuki-kimoto authored on 2009-10-31
274

            
add tests
yuki-kimoto authored on 2009-10-31
275
$tmpl = "select * from table1 where {in table1.key1 2};";
276
$query = $dbi->create_query($tmpl);
277
$result = $dbi->execute($query, {'table1.key1' => [9, 1]});
278
$rows = $result->fetch_all_hash;
279
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table dot");
add tests
yuki-kimoto authored on 2009-10-31
280

            
cleanup
yuki-kimoto authored on 2009-10-29
281

            
add tests
yuki-kimoto authored on 2009-10-31
282
test 'DBI::Custom::SQL::Template insert tag';
add tests
yuki-kimoto authored on 2009-10-31
283
$dbi->do("delete from table1");
284
$insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
285
$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
cleanup
yuki-kimoto authored on 2009-10-29
286

            
add tests
yuki-kimoto authored on 2009-10-31
287
$result = $dbi->execute($SELECT_TMPL->{0});
add tests
yuki-kimoto authored on 2009-10-31
288
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
289
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
cleanup
yuki-kimoto authored on 2009-10-29
290

            
add tests
yuki-kimoto authored on 2009-10-31
291
$dbi->do("delete from table1");
292
$dbi->execute($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
293
$result = $dbi->execute($SELECT_TMPL->{0});
294
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
295
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert");
add tests
yuki-kimoto authored on 2009-10-31
296

            
297

            
298
$dbi->do("delete from table1");
299
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
300
$dbi->execute($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
301
$result = $dbi->execute($SELECT_TMPL->{0});
302
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
303
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name");
304

            
add tests
yuki-kimoto authored on 2009-10-31
305
$dbi->do("delete from table1");
306
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
307
$dbi->execute($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5});
308
$result = $dbi->execute($SELECT_TMPL->{0});
309
$rows = $result->fetch_all_hash;
310
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name dot");
add tests
yuki-kimoto authored on 2009-10-31
311

            
312
$dbi->do("delete from table1");
313
$dbi->execute($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
314
$result = $dbi->execute($SELECT_TMPL->{0});
315
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
316
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name");
add tests
yuki-kimoto authored on 2009-10-31
317

            
add tests
yuki-kimoto authored on 2009-10-31
318
$dbi->do("delete from table1");
319
$dbi->execute($insert_tmpl, {'#insert' => {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}});
320
$result = $dbi->execute($SELECT_TMPL->{0});
321
$rows = $result->fetch_all_hash;
322
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name dot");
323

            
add tests
yuki-kimoto authored on 2009-10-31
324

            
add tests
yuki-kimoto authored on 2009-10-31
325
test 'DBI::Custom::SQL::Template update tag';
add tests
yuki-kimoto authored on 2009-10-31
326
$dbi->do("delete from table1");
327
$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
328
$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
329
$dbi->execute($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
330

            
331
$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}';
332
$dbi->execute($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
333

            
334
$result = $dbi->execute($SELECT_TMPL->{0});
335
$rows = $result->fetch_all_hash;
336
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
add tests
yuki-kimoto authored on 2009-10-31
337
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
add tests
yuki-kimoto authored on 2009-10-31
338

            
add tests
yuki-kimoto authored on 2009-10-31
339
$dbi->execute($update_tmpl, {'#update' => {key1 => 2, key2 => 2, key3 => 2, key4 => 2}, key5 => 5});
add tests
yuki-kimoto authored on 2009-10-31
340
$result = $dbi->execute($SELECT_TMPL->{0});
341
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
342
is_deeply($rows, [{key1 => 2, key2 => 2, key3 => 2, key4 => 2, key5 => 5},
343
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : #update");
add tests
yuki-kimoto authored on 2009-10-31
344

            
add tests
yuki-kimoto authored on 2009-10-31
345
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
346
$dbi->execute($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}});
add tests
yuki-kimoto authored on 2009-10-31
347
$result = $dbi->execute($SELECT_TMPL->{0});
348
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
349
is_deeply($rows, [{key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5},
350
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name");
add tests
yuki-kimoto authored on 2009-10-31
351

            
add tests
yuki-kimoto authored on 2009-10-31
352
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
353
$dbi->execute($update_tmpl, {'table1.key1' => 4, 'table1.key2' => 4, 'table1.key3' => 4, 'table1.key4' => 4, 'table1.key5' => 5});
add tests
yuki-kimoto authored on 2009-10-31
354
$result = $dbi->execute($SELECT_TMPL->{0});
355
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
356
is_deeply($rows, [{key1 => 4, key2 => 4, key3 => 4, key4 => 4, key5 => 5},
add tests
yuki-kimoto authored on 2009-10-31
357
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name dot");
cleanup
yuki-kimoto authored on 2009-10-29
358

            
add tests
yuki-kimoto authored on 2009-10-31
359
$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3 => 5, key4 => 5}}, table1 => {key5 => 5}});
360
$result = $dbi->execute($SELECT_TMPL->{0});
361
$rows = $result->fetch_all_hash;
362
is_deeply($rows, [{key1 => 5, key2 => 5, key3 => 5, key4 => 5, key5 => 5},
363
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag #update with table name");
cleanup
yuki-kimoto authored on 2009-10-29
364

            
add tests
yuki-kimoto authored on 2009-10-31
365
$dbi->execute($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5});
366
$result = $dbi->execute($SELECT_TMPL->{0});
367
$rows = $result->fetch_all_hash;
368
is_deeply($rows, [{key1 => 6, key2 => 6, key3 => 6, key4 => 6, key5 => 5},
369
                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag #update with table name dot");
add tests
yuki-kimoto authored on 2009-10-19
370

            
add test module
yuki-kimoto authored on 2009-10-19
371

            
add tests
yuki-kimoto authored on 2009-10-31
372