Option to disable the charging of the setup fee while a package is suspended.
[freeside.git] / install / 5.005 / DBD-Pg-1.22-fixvercmp / t / 05fetch.t
1 use strict;
2 use DBI;
3 use Test::More;
4
5 if (defined $ENV{DBI_DSN}) {
6   plan tests => 10;
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 $dbh->do(q{INSERT INTO test (id, name, val) VALUES (1, 'foo', 'horse')});
19 $dbh->do(q{INSERT INTO test (id, name, val) VALUES (2, 'bar', 'chicken')});
20 $dbh->do(q{INSERT INTO test (id, name, val) VALUES (3, 'baz', 'pig')});
21 ok($dbh->commit(),
22    'commit'
23    );
24
25 my $sql = <<SQL;
26   SELECT id
27   , name
28   FROM test
29 SQL
30 my $sth = $dbh->prepare($sql);
31 $sth->execute();
32
33 my $rows = 0;
34 while (my ($id, $name) = $sth->fetchrow_array()) {
35   if (defined($id) && defined($name)) {
36     $rows++;
37   }
38 }
39 $sth->finish();
40 ok($rows == 3,
41    'fetch three rows'
42   );
43
44 $sql = <<SQL;
45        SELECT id
46        , name
47        FROM test
48        WHERE 1 = 0
49 SQL
50 $sth = $dbh->prepare($sql);
51 $sth->execute();
52
53 $rows = 0;
54 while (my ($id, $name) = $sth->fetchrow_array()) {
55   $rows++;
56 }
57 $sth->finish();
58
59 ok($rows == 0,
60    'fetch zero rows'
61    );
62
63 $sql = <<SQL;
64        SELECT id
65        , name
66        FROM test
67        WHERE id = ?
68 SQL
69 $sth = $dbh->prepare($sql);
70 $sth->execute(1);
71
72 $rows = 0;
73 while (my ($id, $name) = $sth->fetchrow_array()) {
74   if (defined($id) && defined($name)) {
75     $rows++;
76   }
77 }
78 $sth->finish();
79
80 ok($rows == 1,
81    'fetch one row on id'
82   );
83
84 # Attempt to test whether or not we can get unicode out of the database
85 # correctly.  Reuse the previous sth.
86 SKIP: {
87   eval "use Encode";
88   skip "need Encode module for unicode tests", 3 if $@;
89   local $dbh->{pg_enable_utf8} = 1;
90   $dbh->do("INSERT INTO test (id, name, val) VALUES (4, '\001\000dam', 'cow')");
91   $sth->execute(4);
92   my ($id, $name) = $sth->fetchrow_array();
93   ok(Encode::is_utf8($name),
94      'returned data has utf8 bit set'
95     );
96   is(length($name), 4,
97      'returned utf8 data is not corrupted'
98     );
99   $sth->finish();
100   $sth->execute(1);
101   my ($id2, $name2) = $sth->fetchrow_array();
102   ok(! Encode::is_utf8($name2),
103      'returned ASCII data has not got utf8 bit set'
104     );
105   $sth->finish();
106 }
107
108 $sql = <<SQL;
109        SELECT id
110        , name
111        FROM test
112        WHERE name = ?
113 SQL
114 $sth = $dbh->prepare($sql);
115 $sth->execute('foo');
116
117 $rows = 0;
118 while (my ($id, $name) = $sth->fetchrow_array()) {
119   if (defined($id) && defined($name)) {
120     $rows++;
121   }
122 }
123 $sth->finish();
124
125 ok($rows == 1,
126    'fetch one row on name'
127    );
128
129 ok($dbh->disconnect(),
130    'disconnect'
131   );