Permalink
Browse files

Fix bugs in setQueryTimeout.

Setting a timeout of zero seconds should disable the timeout.
The timeout should be in seconds, but was implemented as milliseconds.
  • Loading branch information...
1 parent b6d6861 commit cd873456d284aec7870c9c7d83498f426b0db58f @kjurka kjurka committed Feb 10, 2012
Showing with 17 additions and 10 deletions.
  1. +17 −10 org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -706,23 +706,30 @@ public int getQueryTimeout() throws SQLException
public void setQueryTimeout(int seconds) throws SQLException
{
checkClosed();
+
if (seconds < 0)
throw new PSQLException(GT.tr("Query timeout must be a value greater than or equals to 0."),
PSQLState.INVALID_PARAMETER_VALUE);
+ if (seconds == 0) {
+ if ( cancelTimer != null ) {
+ cancelTimer.cancel();
+ cancelTimer = null;
+ }
+ return;
+ }
+
cancelTimer = new TimerTask() {
- public void run()
- {
- try {
- AbstractJdbc2Statement.this.cancel();
- } catch (SQLException e) {
- }
-
- }
-
+ public void run()
+ {
+ try {
+ AbstractJdbc2Statement.this.cancel();
+ } catch (SQLException e) {
+ }
+ }
};
- Driver.addTimerTask( cancelTimer, seconds);
+ Driver.addTimerTask( cancelTimer, seconds * 1000);
timeout = seconds;
}

0 comments on commit cd87345

Please sign in to comment.