1414import org .postgresql .util .*;
1515
1616
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 $
1818 * This class defines methods of the jdbc1 specification. This class is
1919 * extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
2020 * 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
362362
363363String dbEncoding =resultSet .getString (2 );
364364encoding =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+ }
365388
366389// Initialise object handling
367390initObjectTypes ();
@@ -896,10 +919,26 @@ public void setAutoCommit(boolean autoCommit) throws SQLException
896919if (this .autoCommit ==autoCommit )
897920return ;
898921if (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+ }
900935else
901936{
902- if (haveMinimumServerVersion ("7.1" ))
937+ if (haveMinimumServerVersion ("7.3" ))
938+ {
939+ ExecSQL ("set autocommit = off; " +getIsolationLevelSQL ());
940+ }
941+ else if (haveMinimumServerVersion ("7.1" ))
903942{
904943ExecSQL ("begin;" +getIsolationLevelSQL ());
905944}
@@ -938,7 +977,11 @@ public void commit() throws SQLException
938977{
939978if (autoCommit )
940979return ;
941- if (haveMinimumServerVersion ("7.1" ))
980+ if (haveMinimumServerVersion ("7.3" ))
981+ {
982+ ExecSQL ("commit; " +getIsolationLevelSQL ());
983+ }
984+ else if (haveMinimumServerVersion ("7.1" ))
942985{
943986ExecSQL ("commit;begin;" +getIsolationLevelSQL ());
944987}
@@ -962,7 +1005,14 @@ public void rollback() throws SQLException
9621005{
9631006if (autoCommit )
9641007return ;
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" ))
9661016{
9671017ExecSQL ("rollback; begin;" +getIsolationLevelSQL ());
9681018}