~ubuntu-branches/ubuntu/maverick/libdbd-pg-perl/maverick-updates

« back to all changes in this revision

Viewing changes to t/09arrays.t

  • Committer: Bazaar Package Importer
  • Author(s): Gunnar Wolf, Gunnar Wolf, Jonathan Yu
  • Date: 2009-08-07 23:57:04 UTC
  • mfrom: (1.1.20 upstream) (4.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090807235704-gwhfvbf4l1cs0oyj
Tags: 2.15.1-1
[ Gunnar Wolf ]
* New (very minor) upstream release. Merging changelog entry with
  Jonathan's, as previous version (2.15.0) has not been uploaded

[ Jonathan Yu ]
* New upstream release
  + Use PQexecPrepared even with no placeholders (RT#48155)
  + Allow execute_array and bind_param_array to take an odd number of items:
    DBI will make the missing ones undef (RT#39829)
  + Single quites around array literals when quoting arrays (RT#48420)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
if (! defined $dbh) {
19
19
        plan skip_all => 'Connection to database failed, cannot continue testing';
20
20
}
21
 
plan tests => 250;
 
21
plan tests => 257;
22
22
 
23
23
isnt ($dbh, undef, 'Connect to database for array testing');
24
24
 
51
51
$SQL = q{SELECT testarray3 FROM dbd_pg_test WHERE pname= 'Array Testing'};
52
52
my $getarray_bool = $dbh->prepare($SQL);
53
53
 
 
54
$t='Array quoting allows direct insertion into statements';
 
55
$SQL = q{INSERT INTO dbd_pg_test (id,testarray2) VALUES };
 
56
my $quoteid = $dbh->quote(123);
 
57
my $quotearr = $dbh->quote([456]);
 
58
$SQL .= qq{($quoteid, $quotearr)};
 
59
eval {
 
60
        $dbh->do($SQL);
 
61
};
 
62
is ($@, q{}, $t);
 
63
$dbh->rollback();
 
64
 
 
65
## Input
 
66
## Expected
 
67
## Name of test
 
68
 
54
69
my $array_tests =
55
70
q!['']
56
71
{""}
160
175
{{"O\"RLY?"},{"'Ya' - \"really\""},{123}} quote: {{"O\"RLY?"},{"'Ya' - \"really\""},{"123"}}
161
176
Many quotes
162
177
 
163
 
["Test\\\\nRun"]
164
 
{"Test\\\\nRun"} quote: {"Test\\\\\\nRun"}
165
 
Simple backslash
166
 
 
167
 
[["Test\\\\nRun","Quite \"so\""],["back\\\\\\\\slashes are a \"pa\\\\in\"",123] ]
168
 
{{"Test\\\\nRun","Quite \"so\""},{"back\\\\\\\\\\\\slashes are a \"pa\\\\in\"",123}} quote: {{"Test\\\\\\nRun","Quite \"so\""},{"back\\\\\\\\\\\\slashes are a \"pa\\\\\\in\"","123"}}
169
 
Escape party
 
178
["Single\\\\Backslash"]
 
179
{"Single\\\\\\\\Backslash"} quote: {"Single\\\\\\\\Backslash"}
 
180
Single backslash testing
 
181
 
 
182
["Double\\\\\\\\Backslash"]
 
183
{"Double\\\\\\\\\\\\\\\\Backslash"} quote: {"Double\\\\\\\\\\\\\\\\Backslash"}
 
184
Double backslash testing
 
185
 
 
186
[["Test\\\nRun","Quite \"so\""],["back\\\\\\\\slashes are a \"pa\\\\in\"",123] ]
 
187
{{"Test\\\\\\\\nRun","Quite \"so\""},{"back\\\\\\\\\\\\\\\\slashes are a \"pa\\\\\\\\in\"",123}} quote: {{"Test\\\\\\\nRun","Quite \"so\""},{"back\\\\\\\\\\\\\\\\slashes are a \"pa\\\\\\\\in\"","123"}}
 
188
Escape party - backslash+newline, two + one
170
189
 
171
190
[undef]
172
191
{NULL}
193
212
        if ($expected =~ s/\s*quote:\s*(.+)//) {
194
213
                $qexpected = $1;
195
214
        }
 
215
        if ($qexpected !~ /^ERROR/) {
 
216
                $qexpected = qq{'$qexpected'};
 
217
        }
196
218
 
197
219
        if ($msg =~ s/NEED (\d+):\s*//) {
198
220
                my $ver = $1;
279
301
                $qexpected =~ s/{}/{''}/;
280
302
                $qexpected =~ y/{}/[]/;
281
303
                $qexpected =~ s/NULL/undef/g;
282
 
                $qexpected =~ s/\\\\n/\\n/g;
283
 
                $qexpected =~ s/\\\\"/\\"/g;
284
 
                $qexpected =~ s/\\\\i/\\i/g;
285
304
                if ($msg =~ /closing brace/) {
286
305
                        $qexpected =~ s/]"/}"/;
287
306
                }
546
565
        skip ('Encode module is needed for unicode tests', 14) if $@;
547
566
 
548
567
        my $server_encoding = $dbh->selectall_arrayref('SHOW server_encoding')->[0][0];
549
 
        skip ('Cannot test unicode with a LATIN1 database', 14)
550
 
                if $server_encoding eq 'LATIN1';
 
568
        skip ('Cannot reliably test unicode without a UTF8 database', 14)
 
569
                if $server_encoding ne 'UTF8';
551
570
 
552
571
        $t='String should be UTF-8';
553
572
        local $dbh->{pg_enable_utf8} = 1;
563
582
 
564
583
        $t='quote() handles utf8 inside array';
565
584
        $quoted = $dbh->quote([$utf8_str, $utf8_str]);
566
 
        is ($quoted, qq!{"$utf8_str","$utf8_str"}!, $t);
 
585
        is ($quoted, qq!'{"$utf8_str","$utf8_str"}'!, $t);
567
586
 
568
587
        $t='Quoted array of strings should be UTF-8';
569
588
    ok (Encode::is_utf8( $quoted ), $t);
576
595
 
577
596
        $t='Inserting utf-8 into an array via quoted do() works';
578
597
        $dbh->do('DELETE FROM dbd_pg_test');
579
 
        $SQL = qq{INSERT INTO dbd_pg_test (id, testarray, val) VALUES (1, '$quoted', 'one')};
 
598
        $SQL = qq{INSERT INTO dbd_pg_test (id, testarray, val) VALUES (1, $quoted, 'one')};
580
599
        eval {
581
600
                $dbh->do($SQL);
582
601
        };