DBIx-Custom / t / 02-sqlite.t /
Newer Older
368 lines | 15.129kb
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

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

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

            
add tests
yuki-kimoto authored on 2009-10-29
90
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
91
@rows = ();
92
while (my %row = $result->fetch_hash) {
93
    push @rows, {%row};
add test module
yuki-kimoto authored on 2009-10-19
94
}
add tests
yuki-kimoto authored on 2009-10-29
95
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
96

            
add tests
yuki-kimoto authored on 2009-10-29
97
$result = $dbi->execute($query);
cleanup
yuki-kimoto authored on 2009-10-29
98
$rows = $result->fetch_all;
add tests
yuki-kimoto authored on 2009-10-29
99
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context");
cleanup
yuki-kimoto authored on 2009-10-29
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 list context");
cleanup
yuki-kimoto authored on 2009-10-29
104

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

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

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

            
add tests
yuki-kimoto authored on 2009-10-31
114
test 'Insert query return value';
115
$dbi->reconnect;
116
$dbi->do($CREATE_TABLE->{0});
117
$tmpl = "insert into table1 {insert key1 key2}";
118
$query = $dbi->create_query($tmpl);
119
$ret_val = $dbi->execute($query, {key1 => 1, key2 => 2});
120
ok($ret_val, $test);
121

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

            
123
test 'Direct execute';
124
$dbi->reconnect;
125
$dbi->do($CREATE_TABLE->{0});
126
$insert_tmpl = "insert into table1 {insert key1 key2}";
127
$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}, sub {
128
    my $query = shift;
129
    $query->bind_filter(sub {
130
        my ($key, $value) = @_;
131
        if ($key eq 'key2') {
132
            return $value + 1;
133
        }
134
        return $value;
135
    });
136
});
137
$result = $dbi->execute($SELECT_TMPL->{0});
138
$rows = $result->fetch_all_hash;
139
is_deeply($rows, [{key1 => 1, key2 => 3}], $test);
140

            
141

            
add tests
yuki-kimoto authored on 2009-10-31
142
test 'Filter basic';
cleanup#
yuki-kimoto authored on 2009-10-30
143
$dbi->reconnect;
add tests
yuki-kimoto authored on 2009-10-31
144
$dbi->do($CREATE_TABLE->{0});
cleanup#
yuki-kimoto authored on 2009-10-30
145

            
add tests
yuki-kimoto authored on 2009-10-31
146
$insert_tmpl  = "insert into table1 {insert key1 key2};";
add prepare
yuki-kimoto authored on 2009-10-31
147
$insert_query = $dbi->create_query($insert_tmpl);
148
$insert_query->bind_filter(sub {
add tests
yuki-kimoto authored on 2009-10-31
149
    my ($key, $value, $table, $column) = @_;
150
    if ($key eq 'key1' && $table eq '' && $column eq 'key1') {
add prepare
yuki-kimoto authored on 2009-10-31
151
        return $value * 2;
cleanup#
yuki-kimoto authored on 2009-10-30
152
    }
153
    return $value;
154
});
add tests
yuki-kimoto authored on 2009-10-31
155
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
156
$select_query = $dbi->create_query($SELECT_TMPL->{0});
add prepare
yuki-kimoto authored on 2009-10-31
157
$select_query->fetch_filter(sub {
add tests
yuki-kimoto authored on 2009-10-31
158
    my ($key, $value, $type, $sth, $i) = @_;
159
    if ($key eq 'key2' && $type =~ /char/ && $sth->can('execute') && $i == 1) {
add prepare
yuki-kimoto authored on 2009-10-31
160
        return $value * 3;
161
    }
162
    return $value;
163
});
164
$result = $dbi->execute($select_query);
165
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
166
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter");
cleanup#
yuki-kimoto authored on 2009-10-30
167

            
add tests
yuki-kimoto authored on 2009-10-31
168
$dbi->do("delete from table1;");
169
$insert_query->no_bind_filters('key1');
170
$select_query->no_fetch_filters('key2');
171
$dbi->execute($insert_query, {key1 => 1, key2 => 2});
172
$result = $dbi->execute($select_query);
173
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
174
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : no_fetch_filters no_bind_filters");
add tests
yuki-kimoto authored on 2009-10-31
175

            
add tests
yuki-kimoto authored on 2009-10-31
176
$dbi->reconnect;
177
$dbi->do($CREATE_TABLE->{0});
178
$insert_tmpl  = "insert into table1 {insert table1.key1 table1.key2}";
179
$insert_query = $dbi->create_query($insert_tmpl);
180
$insert_query->bind_filter(sub {
181
    my ($key, $value, $table, $column) = @_;
182
    if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1') {
183
        return $value * 3;
184
    }
185
    return $value;
186
});
187
$dbi->execute($insert_query, {table1 => {key1 => 1, key2 => 2}});
188
$select_query = $dbi->create_query($SELECT_TMPL->{0});
189
$result       = $dbi->execute($select_query);
190
$rows = $result->fetch_all_hash;
191
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
192

            
add tests
yuki-kimoto authored on 2009-10-31
193
test 'Filter in';
194
$insert_tmpl  = "insert into table1 {insert key1 key2};";
195
$insert_query = $dbi->create_query($insert_tmpl);
196
$dbi->execute($insert_query, {key1 => 2, key2 => 4});
197
$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
198
$select_query = $dbi->create_query($select_tmpl);
199
$select_query->bind_filter(sub {
200
    my ($key, $value, $table, $column) = @_;
201
    if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1' || $key eq 'table1.key2') {
202
        return $value * 2;
203
    }
204
    return $value;
205
});
206
$result = $dbi->execute($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}});
207
$rows = $result->fetch_all_hash;
208
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : bind_filter");
209

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

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

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

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

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

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

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

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

            
254

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

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

            
268
$tmpl = "select * from table1 where {in table1.key1 2};";
269
$query = $dbi->create_query($tmpl);
270
$result = $dbi->execute($query, {table1 => {key1 => [9, 1]}});
271
$rows = $result->fetch_all_hash;
272
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
273

            
add tests
yuki-kimoto authored on 2009-10-31
274
$tmpl = "select * from table1 where {in table1.key1 2};";
275
$query = $dbi->create_query($tmpl);
276
$result = $dbi->execute($query, {'table1.key1' => [9, 1]});
277
$rows = $result->fetch_all_hash;
278
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
279

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

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

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

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

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

            
add tests
yuki-kimoto authored on 2009-10-31
303
$dbi->do("delete from table1");
304
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
305
$dbi->execute($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5});
306
$result = $dbi->execute($SELECT_TMPL->{0});
307
$rows = $result->fetch_all_hash;
308
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
309

            
310
$dbi->do("delete from table1");
311
$dbi->execute($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
312
$result = $dbi->execute($SELECT_TMPL->{0});
313
$rows = $result->fetch_all_hash;
add tests
yuki-kimoto authored on 2009-10-31
314
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
315

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

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

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

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

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

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

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

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

            
add tests
yuki-kimoto authored on 2009-10-31
357
$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3 => 5, key4 => 5}}, table1 => {key5 => 5}});
358
$result = $dbi->execute($SELECT_TMPL->{0});
359
$rows = $result->fetch_all_hash;
360
is_deeply($rows, [{key1 => 5, key2 => 5, key3 => 5, key4 => 5, key5 => 5},
add tests
yuki-kimoto authored on 2009-10-31
361
                  {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
362

            
add tests
yuki-kimoto authored on 2009-10-31
363
$dbi->execute($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5});
364
$result = $dbi->execute($SELECT_TMPL->{0});
365
$rows = $result->fetch_all_hash;
366
is_deeply($rows, [{key1 => 6, key2 => 6, key3 => 6, key4 => 6, key5 => 5},
add tests
yuki-kimoto authored on 2009-10-31
367
                  {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-31
368