File: 05arrays.t

package info (click to toggle)
libdbd-pg-perl 1.49-2%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 680 kB
  • ctags: 381
  • sloc: perl: 3,921; ansic: 3,183; makefile: 99; sh: 22
file content (75 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!perl -w

# Test array stuff - currently not working!

use Test::More;
use DBI;
use strict;
$|=1;

if (defined $ENV{DBI_DSN}) {
	plan tests => 18;
} else {
	plan skip_all => 'Cannot run test unless DBI_DSN is defined. See the README file';
}

my $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
                       {RaiseError => 1, PrintError => 0, AutoCommit => 0});
ok( defined $dbh, "Connect to database for array testing");

if (DBD::Pg::_pg_use_catalog($dbh)) {
	$dbh->do("SET search_path TO " . $dbh->quote_identifier
					 (exists $ENV{DBD_SCHEMA} ? $ENV{DBD_SCHEMA} : 'public'));
}

my $SQL = "UPDATE dbd_pg_test SET testarray2 = '{99}'";
my $count = $dbh->do($SQL);
$SQL = "SELECT testarray2 FROM dbd_pg_test";
my $sth = $dbh->prepare($SQL);
my $count2 = $sth->execute();
my $info = $sth->fetchall_arrayref();
ok ($count==$count2, "Select from an array works");

SKIP: {
    # XXX Until all the array stuff is working, skip all tests.
    # Should really be a TODO, but these tests will die.
    skip 'Array support not implemented', 15;

    # Insert into array
    my $values = [["a,b", 'c","d', "e'", '\\"'], ['f', 'g', 'h']];

    ok($dbh->do(q{INSERT INTO dbd_pg_test (id, name, testarray) VALUES (?, ?, ?)},
                {}, 1, 'array1', $values),
       'insert statement with references');

    my $sql = <<"    SQL";
     SELECT testarray[1][1],testarray[1][2],testarray[1][3],
            testarray[2][1],testarray[2][2],testarray[2][3]
     FROM   dbd_pg_test
     WHERE  id = ?
     AND    name = ?
    SQL

    my $sth = $dbh->prepare($sql);
    ok(defined $sth, "prepare: $sql" );

    ok($sth->bind_param(1, '1'), 'bind parameter 1', );
    ok($sth->bind_param(2, 'array1'), 'bind parameter 2' );
    ok($sth->execute, 'execute statement with references' );

    my @result = $sth->fetchrow_array;

    ok(scalar(@result) == 6, 'fetch 6 columns' );
    ok($result[0] eq 'a,b', 'values are equal' );
    ok($result[1] eq 'c","d', 'values are equal' );
    ok($result[2] eq "e'", 'values are equal' );
    ok($result[2] eq q{\\\\\"}, 'values are equal' );
    ok($result[3] eq 'f', 'values are equal' );
    ok($result[4] eq 'g', 'values are equal' );
    ok($result[5] eq 'h', 'values are equal' );

    ok($sth->finish, 'finish' );

}; # XXX End SKIP.

ok ($dbh->disconnect, "Disconnect from database");