comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 650:849f99124e32

Correcting implementation of Statement.setQueryTimeout(int seconds). According to the webdocumentation the procedures sys.settimeout(query bigint) and sys.setquerytimeout(query int) expect a timeout in milliseconds but the JDBC method Statement.setQueryTimeout(int) gets a timeout in seconds. See https://www.monetdb.org/documentation-Jan2022/admin-guide/monitoring/session-procedures/ and https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#setQueryTimeout-int- So we need to multiply the int value by 1000 before calling the procedure.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 30 Jun 2022 18:40:52 +0200 (2022-06-30)
parents 06d69b82d409
children c6fe5dfecafc
comparison
equal deleted inserted replaced
649:060347aa81ea 650:849f99124e32
1728 1728
1729 /** 1729 /**
1730 * Utility method to call sys.setquerytimeout(int); procedure on the connected server. 1730 * Utility method to call sys.setquerytimeout(int); procedure on the connected server.
1731 * It is called from: MonetConnection.isValid() and MonetStatement.internalExecute() 1731 * It is called from: MonetConnection.isValid() and MonetStatement.internalExecute()
1732 */ 1732 */
1733 void setQueryTimeout(final int millis) throws SQLException { 1733 void setQueryTimeout(final int seconds) throws SQLException {
1734 if (millis < 0) 1734 if (seconds < 0)
1735 throw new SQLException("query timeout milliseconds is less than zero", "M1M05"); 1735 throw new SQLException("query timeout seconds is less than zero", "M1M05");
1736 1736
1737 checkNotClosed(); 1737 checkNotClosed();
1738 Statement st = null; 1738 Statement st = null;
1739 try { 1739 try {
1740 final String callstmt; 1740 final String callstmt;
1741 // as of release Jun2020 (11.37.7) the function sys.settimeout(bigint) is deprecated and replaced by new sys.setquerytimeout(int) 1741 final int msecs = (seconds <= 2147483) ? seconds * 1000 : seconds; // prevent overflow of int
1742
1743 // as of release Jun2020 (11.37.7) the function sys.settimeout(msecs bigint) is deprecated and replaced by new sys.setquerytimeout(msecs int)
1742 if ((getDatabaseMajorVersion() == 11) && (getDatabaseMinorVersion() < 37)) 1744 if ((getDatabaseMajorVersion() == 11) && (getDatabaseMinorVersion() < 37))
1743 callstmt = "CALL sys.\"settimeout\"(" + millis + ")"; 1745 callstmt = "CALL sys.\"settimeout\"(" + msecs + ")";
1744 else 1746 else
1745 callstmt = "CALL sys.\"setquerytimeout\"(" + millis + ")"; 1747 callstmt = "CALL sys.\"setquerytimeout\"(" + msecs + ")";
1746 // for debug: System.out.println("Before: " + callstmt); 1748 // for debug: System.out.println("Before: " + callstmt);
1747 st = createStatement(); 1749 st = createStatement();
1748 st.execute(callstmt); 1750 st.execute(callstmt);
1749 // for debug: System.out.println("After : " + callstmt); 1751 // for debug: System.out.println("After : " + callstmt);
1750 1752
1751 this.lastSetQueryTimeout = millis; 1753 this.lastSetQueryTimeout = seconds;
1752 } 1754 }
1753 /* do not catch SQLException here, as we want to know it when it fails */ 1755 /* do not catch SQLException here, as we want to know it when it fails */
1754 finally { 1756 finally {
1755 closeResultsetStatement(null, st); 1757 closeResultsetStatement(null, st);
1756 } 1758 }