@@ -6,7 +6,7 @@ use Test::More;
6
6
use lib ' t' , ' .' ;
7
7
require ' lib.pl' ;
8
8
9
- use vars qw( $have_transactions $ got_warning $test_dsn $test_user $test_password) ;
9
+ use vars qw( $got_warning $test_dsn $test_user $test_password) ;
10
10
11
11
my $dbh ;
12
12
eval {$dbh = DBI-> connect ($test_dsn , $test_user , $test_password ,
@@ -41,124 +41,60 @@ sub num_rows($$$) {
41
41
return ' ' ;
42
42
}
43
43
44
- $have_transactions = have_transactions($dbh );
45
- my $engine = $have_transactions ? ' InnoDB' : ' MyISAM' ;
44
+ plan tests => 22;
46
45
47
- if ($have_transactions ) {
48
- plan tests => 22;
49
-
50
- ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t50commit" ), " drop table if exists dbd_mysql_t50commit" ;
51
- my $create =<<EOT ;
46
+ ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t50commit" ), " drop table if exists dbd_mysql_t50commit" ;
47
+ my $create =<<EOT ;
52
48
CREATE TABLE dbd_mysql_t50commit (
53
- id INT(4) NOT NULL default 0,
54
- name VARCHAR(64) NOT NULL default ''
55
- ) ENGINE=$engine
56
- EOT
57
-
58
- ok $dbh -> do($create ), ' create dbd_mysql_t50commit' ;
59
-
60
- ok !$dbh -> {AutoCommit }, " \$ dbh->{AutoCommit} not defined |$dbh ->{AutoCommit}|" ;
61
-
62
- $dbh -> {AutoCommit } = 0;
63
- ok !$dbh -> err;
64
- ok !$dbh -> errstr;
65
- ok !$dbh -> {AutoCommit };
66
-
67
- ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (1, 'Jochen')" ),
68
- " insert into dbd_mysql_t50commit (1, 'Jochen')" ;
69
-
70
- my $msg ;
71
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
72
- ok !$msg ;
73
-
74
- ok $dbh -> rollback, ' rollback' ;
75
-
76
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
77
- ok !$msg ;
78
-
79
- ok $dbh -> do(" DELETE FROM dbd_mysql_t50commit WHERE id = 1" ), " delete from dbd_mysql_t50commit where id = 1" ;
80
-
81
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
82
- ok !$msg ;
83
- ok $dbh -> commit, ' commit' ;
84
-
85
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
86
- ok !$msg ;
87
-
88
- # Check auto rollback after disconnect
89
- ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (1, 'Jochen')" );
90
-
91
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
92
- ok !$msg ;
93
-
94
- ok $dbh -> disconnect;
95
-
96
- ok ($dbh = DBI-> connect ($test_dsn , $test_user , $test_password ));
97
-
98
- ok $dbh , " connected" ;
99
-
100
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
101
- ok !$msg ;
102
-
103
- ok $dbh -> {AutoCommit }, " \$ dbh->{AutoCommit} $dbh ->{AutoCommit}" ;
104
- ok $dbh -> do(" DROP TABLE dbd_mysql_t50commit" );
105
-
106
- }
107
- else {
108
- plan tests => 13;
109
-
110
- ok $dbh -> do(" DROP TABLE IF EXISTS dbd_mysql_t50commit" ), " drop table if exists dbd_mysql_t50commit" ;
111
- my $create =<<EOT ;
112
- CREATE TABLE dbd_mysql_t50commit (
113
- id INT(4) NOT NULL default 0,
114
- name VARCHAR(64) NOT NULL default ''
115
- ) ENGINE=$engine
49
+ id INT(4) NOT NULL default 0,
50
+ name VARCHAR(64) NOT NULL default ''
51
+ ) ENGINE=InnoDB
116
52
EOT
117
53
118
- ok $dbh -> do($create ), ' create dbd_mysql_t50commit' ;
54
+ ok $dbh -> do($create ), ' create dbd_mysql_t50commit' ;
119
55
120
- # Tests for databases that don't support transactions
121
- # Check whether AutoCommit mode works.
56
+ ok !$dbh -> {AutoCommit }, " \$ dbh->{AutoCommit} not defined |$dbh ->{AutoCommit}|" ;
122
57
123
- ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (1, 'Jochen')" );
124
- my $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
125
- ok !$msg ;
58
+ $dbh -> {AutoCommit } = 0;
59
+ ok !$dbh -> err;
60
+ ok !$dbh -> errstr;
61
+ ok !$dbh -> {AutoCommit };
126
62
127
- ok $dbh -> disconnect;
63
+ ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (1, 'Jochen')" ),
64
+ " insert into dbd_mysql_t50commit (1, 'Jochen')" ;
128
65
129
- ok ($dbh = DBI-> connect ($test_dsn , $test_user , $test_password ));
66
+ my $msg ;
67
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
68
+ ok !$msg ;
130
69
131
- $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
132
- ok !$msg ;
70
+ ok $dbh -> rollback, ' rollback' ;
133
71
134
- ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (2, 'Tim')" );
72
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
73
+ ok !$msg ;
135
74
136
- my $result ;
137
- $@ = ' ' ;
75
+ ok $dbh -> do(" DELETE FROM dbd_mysql_t50commit WHERE id = 1" ), " delete from dbd_mysql_t50commit where id = 1" ;
138
76
139
- $SIG {__WARN__ } = \&catch_warning;
77
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
78
+ ok !$msg ;
79
+ ok $dbh -> commit, ' commit' ;
140
80
141
- $got_warning = 0;
81
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
82
+ ok !$msg ;
142
83
143
- eval { $result = $dbh -> commit; };
84
+ # Check auto rollback after disconnect
85
+ ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (1, 'Jochen')" );
144
86
145
- $SIG {__WARN__ } = ' DEFAULT' ;
87
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 1);
88
+ ok !$msg ;
146
89
147
- ok $got_warning ;
90
+ ok $dbh -> disconnect ;
148
91
149
- # Check whether rollback issues a warning in AutoCommit mode
150
- # We accept error messages as being legal, because the DBI
151
- # requirement of just issuing a warning seems scary.
152
- ok $dbh -> do(" INSERT INTO dbd_mysql_t50commit VALUES (3, 'Alligator')" );
92
+ ok ($dbh = DBI-> connect ($test_dsn , $test_user , $test_password ));
153
93
154
- $@ = ' ' ;
155
- $SIG {__WARN__ } = \&catch_warning;
156
- $got_warning = 0;
157
- eval { $result = $dbh -> rollback; };
158
- $SIG {__WARN__ } = ' DEFAULT' ;
94
+ ok $dbh , " connected" ;
159
95
160
- ok $got_warning , " Should be warning defined upon rollback of non-trx table" ;
96
+ $msg = num_rows($dbh , ' dbd_mysql_t50commit' , 0);
97
+ ok !$msg ;
161
98
162
- ok $dbh -> do(" DROP TABLE dbd_mysql_t50commit" );
163
- ok $dbh -> disconnect();
164
- }
99
+ ok $dbh -> {AutoCommit }, " \$ dbh->{AutoCommit} $dbh ->{AutoCommit}" ;
100
+ ok $dbh -> do(" DROP TABLE dbd_mysql_t50commit" );
0 commit comments