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 / 08txn.t
1 use strict;
2 use DBI;
3 use Test::More;
4
5 if (defined $ENV{DBI_DSN}) {
6   plan tests => 18;
7 } else {
8   plan skip_all => 'cannot test without DB info';
9 }
10
11 my $dbh1 = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
12                         {RaiseError => 1, AutoCommit => 0}
13                        );
14 ok(defined $dbh1,
15    'connect first dbh'
16   );
17
18 my $dbh2 = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
19                         {RaiseError => 1, AutoCommit => 0}
20                        );
21 ok(defined $dbh2,
22    'connect second dbh'
23   );
24
25 $dbh1->do(q{DELETE FROM test});
26 ok($dbh1->commit(),
27    'delete'
28    );
29
30 my $rows = ($dbh1->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
31 ok($rows == 0,
32    'fetch on empty table from dbh1'
33   );
34
35 $rows = ($dbh2->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
36 ok($rows == 0,
37    'fetch on empty table from dbh2'
38   );
39
40 $dbh1->do(q{INSERT INTO test (id, name, val) VALUES (1, 'foo', 'horse')});
41 $dbh1->do(q{INSERT INTO test (id, name, val) VALUES (2, 'bar', 'chicken')});
42 $dbh1->do(q{INSERT INTO test (id, name, val) VALUES (3, 'baz', 'pig')});
43
44 $rows = ($dbh1->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
45 ok($rows == 3,
46    'fetch three rows on dbh1'
47   );
48
49 $rows = ($dbh2->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
50 ok($rows == 0,
51    'fetch on dbh2 before commit'
52   );
53
54 ok($dbh1->commit(),
55    'commit work'
56   );
57
58 $rows = ($dbh1->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
59 ok($rows == 3,
60    'fetch on dbh1 after commit'
61   );
62
63 $rows = ($dbh2->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
64 ok($rows == 3,
65    'fetch on dbh2 after commit'
66   );
67
68 ok($dbh1->do(q{DELETE FROM test}),
69    'delete'
70   );
71
72 $rows = ($dbh1->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
73 ok($rows == 0,
74    'fetch on empty table from dbh1'
75   );
76
77 $rows = ($dbh2->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
78 ok($rows == 3,
79    'fetch on from dbh2 without commit'
80   );
81
82 ok($dbh1->rollback(),
83    'rollback'
84   );
85
86 $rows = ($dbh1->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
87 ok($rows == 3,
88    'fetch on from dbh1 after rollback'
89   );
90
91 $rows = ($dbh2->selectrow_array(q{SELECT COUNT(*) FROM test}))[0];
92 ok($rows == 3,
93    'fetch on from dbh2 after rollback'
94   );
95
96 ok($dbh1->disconnect(),
97    'disconnect on dbh1'
98 );
99
100 ok($dbh2->disconnect(),
101    'disconnect on dbh2'
102 );