14
14
import org .postgresql .util .*;
15
15
16
16
17
- /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.10 2002/10/01 00:39:01 davec Exp $
17
+ /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.11 2002/10/17 05:33:52 barry Exp $
18
18
* This class defines methods of the jdbc1 specification. This class is
19
19
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
20
20
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -362,6 +362,29 @@ public void openConnection(String host, int port, Properties info, String databa
362
362
363
363
String dbEncoding = resultSet .getString (2 );
364
364
encoding = Encoding .getEncoding (dbEncoding , info .getProperty ("charSet" ));
365
+ //In 7.3 we are forced to do a second roundtrip to handle the case
366
+ //where a database may not be running in autocommit mode
367
+ //jdbc by default assumes autocommit is on until setAutoCommit(false)
368
+ //is called. Therefore we need to ensure a new connection is
369
+ //initialized to autocommit on.
370
+ if (haveMinimumServerVersion ("7.3" ))
371
+ {
372
+ java .sql .ResultSet acRset =
373
+ ExecSQL ("show autocommit" );
374
+
375
+ if (!acRset .next ())
376
+ {
377
+ throw new PSQLException ("postgresql.con.failed" , "failed getting autocommit status" );
378
+ }
379
+ //if autocommit is currently off we need to turn it on
380
+ //note that we will be in a transaction because the select above
381
+ //will have initiated the transaction so we need a commit
382
+ //to make the setting permanent
383
+ if (acRset .getString (1 ).equals ("off" ))
384
+ {
385
+ ExecSQL ("set autocommit = on; commit;" );
386
+ }
387
+ }
365
388
366
389
// Initialise object handling
367
390
initObjectTypes ();
@@ -896,10 +919,26 @@ public void setAutoCommit(boolean autoCommit) throws SQLException
896
919
if (this .autoCommit == autoCommit )
897
920
return ;
898
921
if (autoCommit )
899
- ExecSQL ("end" );
922
+ {
923
+ if (haveMinimumServerVersion ("7.3" ))
924
+ {
925
+ //We do the select to ensure a transaction is in process
926
+ //before we do the commit to avoid warning messages
927
+ //from issuing a commit without a transaction in process
928
+ ExecSQL ("select 1; commit; set autocommit = on;" );
929
+ }
930
+ else
931
+ {
932
+ ExecSQL ("end" );
933
+ }
934
+ }
900
935
else
901
936
{
902
- if (haveMinimumServerVersion ("7.1" ))
937
+ if (haveMinimumServerVersion ("7.3" ))
938
+ {
939
+ ExecSQL ("set autocommit = off; " + getIsolationLevelSQL ());
940
+ }
941
+ else if (haveMinimumServerVersion ("7.1" ))
903
942
{
904
943
ExecSQL ("begin;" + getIsolationLevelSQL ());
905
944
}
@@ -938,7 +977,11 @@ public void commit() throws SQLException
938
977
{
939
978
if (autoCommit )
940
979
return ;
941
- if (haveMinimumServerVersion ("7.1" ))
980
+ if (haveMinimumServerVersion ("7.3" ))
981
+ {
982
+ ExecSQL ("commit; " + getIsolationLevelSQL ());
983
+ }
984
+ else if (haveMinimumServerVersion ("7.1" ))
942
985
{
943
986
ExecSQL ("commit;begin;" + getIsolationLevelSQL ());
944
987
}
@@ -962,7 +1005,14 @@ public void rollback() throws SQLException
962
1005
{
963
1006
if (autoCommit )
964
1007
return ;
965
- if (haveMinimumServerVersion ("7.1" ))
1008
+ if (haveMinimumServerVersion ("7.3" ))
1009
+ {
1010
+ //we don't automatically start a transaction
1011
+ //but let the server functionality automatically start
1012
+ //one when the first statement is executed
1013
+ ExecSQL ("rollback; " + getIsolationLevelSQL ());
1014
+ }
1015
+ else if (haveMinimumServerVersion ("7.1" ))
966
1016
{
967
1017
ExecSQL ("rollback; begin;" + getIsolationLevelSQL ());
968
1018
}
0 commit comments