adding DBD::Pg and DBIx::DBSchema for 5.005. argh freebsd and solaris!
[freeside.git] / install / 5.005 / DBD-Pg-1.22-fixvercmp / t / 12placeholders.t
1 use strict;
2 use DBI;
3 use Test::More;
4
5 if (defined $ENV{DBI_DSN}) {
6   plan tests => 9;
7 } else {
8   plan skip_all => 'cannot test without DB info';
9 }
10
11 my $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
12                        {RaiseError => 1, AutoCommit => 0}
13                       );
14 ok(defined $dbh,
15    'connect with transaction'
16   );
17
18 my $quo = $dbh->quote("\\'?:");
19 my $sth = $dbh->prepare(qq{
20                         INSERT INTO test (name) VALUES ($quo)
21                        });
22 $sth->execute();
23
24 my $sql = <<SQL;
25         SELECT name
26         FROM test
27         WHERE name = $quo;
28 SQL
29 $sth = $dbh->prepare($sql);
30 $sth->execute();
31
32 my ($retr) = $sth->fetchrow_array();
33 ok((defined($retr) && $retr eq "\\'?:"),
34    'fetch'
35   );
36
37 eval {
38   local $dbh->{PrintError} = 0;
39   $sth->execute('foo');
40 };
41 ok($@,
42    'execute with one bind param where none expected'
43   );
44
45 $sql = <<SQL;
46        SELECT name
47        FROM test
48        WHERE name = ?
49 SQL
50 $sth = $dbh->prepare($sql);
51
52 $sth->execute("\\'?:");
53
54 ($retr) = $sth->fetchrow_array();
55 ok((defined($retr) && $retr eq "\\'?:"),
56    'execute with ? placeholder'
57   );
58
59 $sql = <<SQL;
60        SELECT name
61        FROM test
62        WHERE name = :1
63 SQL
64 $sth = $dbh->prepare($sql);
65
66 $sth->execute("\\'?:");
67
68 ($retr) = $sth->fetchrow_array();
69 ok((defined($retr) && $retr eq "\\'?:"),
70    'execute with :1 placeholder'
71   );
72
73 $sql = <<SQL;
74        SELECT name
75        FROM test
76        WHERE name = '?'
77 SQL
78 $sth = $dbh->prepare($sql);
79
80 eval {
81   local $dbh->{PrintError} = 0;
82   $sth->execute('foo');
83 };
84 ok($@,
85    'execute with quoted ?'
86   );
87
88 $sql = <<SQL;
89        SELECT name
90        FROM test
91        WHERE name = ':1'
92 SQL
93 $sth = $dbh->prepare($sql);
94
95 eval {
96   local $dbh->{PrintError} = 0;
97   $sth->execute('foo');
98 };
99 ok($@,
100    'execute with quoted :1'
101   );
102
103 $sql = <<SQL;
104        SELECT name
105        FROM test
106        WHERE name = '\\\\'
107        AND name = '?'
108 SQL
109 $sth = $dbh->prepare($sql);
110
111 eval {
112   local $dbh->{PrintError} = 0;
113   local $sth->{PrintError} = 0;
114   $sth->execute('foo');
115 };
116 ok($@,
117    'execute with quoted ?'
118   );
119
120 $sth->finish();
121 $dbh->rollback();
122
123 ok($dbh->disconnect(),
124    'disconnect'
125   );