List:Commits« Previous MessageNext Message »
From:mmatthews Date:October 18 2006 5:04pm
Subject:Connector/J commit: r5889 - in branches/branch_3_1/connector-j: . src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_3_1/connector-j/CHANGES
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java
Log:
Check and store value for continueBatchOnError property in constructor
      of Statements, rather than when executing batches, so that Connections
      closed out from underneath statements don't cause NullPointerExceptions
      when it's required to check this property.

Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES	2006-10-18 15:40:15 UTC (rev 5888)
+++ branches/branch_3_1/connector-j/CHANGES	2006-10-18 17:04:37 UTC (rev 5889)
@@ -1,7 +1,7 @@
 # Changelog
 # $Id$
 
-nn-nn-06 - Version 3.1.14
+10-19-06 - Version 3.1.14
 
     - Fixed BUG#20479 - Updatable result set throws ClassCastException
 	  when there is row data and moveToInsertRow() is called.
@@ -60,7 +60,12 @@
 	- Fixed BUG#18258 - DatabaseMetaData.getTables(), columns() with bad
 	  catalog parameter threw exception rather than return empty result
 	  set (as required by spec).
-	  	  	    
+	
+	- Check and store value for continueBatchOnError property in constructor
+      of Statements, rather than when executing batches, so that Connections
+      closed out from underneath statements don't cause NullPointerExceptions
+      when it's required to check this property.
+      
 05-26-06 - Version 3.1.13
 
     - Fixed BUG#15464 - INOUT parameter does not store IN value.

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-10-18 15:40:15 UTC (rev 5888)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-10-18 17:04:37 UTC (rev 5889)
@@ -421,6 +421,7 @@
 	protected PreparedStatement(Connection conn, String catalog)
 			throws SQLException {
 		super(conn, catalog);
+		
 	}
 
 	/**
@@ -492,6 +493,7 @@
 		this.usingAnsiMode = !this.connection.useAnsiQuotedIdentifiers();
 
 		initializeFromParseInfo();
+		
 	}
 
 	/**
@@ -1081,7 +1083,7 @@
 					} catch (SQLException ex) {
 						updateCounts[commandIndex] = EXECUTE_FAILED;
 
-						if (this.connection.getContinueBatchOnError()) {
+						if (this.continueBatchOnError) {
 							sqlEx = ex;
 						} else {
 							int[] newUpdateCounts = new int[commandIndex];
@@ -2041,6 +2043,9 @@
 		if (x == null) {
 			setNull(parameterIndex, java.sql.Types.BINARY);
 		} else {
+			
+			int parameterIndexOffset = getParameterIndexOffset();
+			
 			if ((parameterIndex < 1)
 					|| (parameterIndex > this.staticSqlStrings.length)) {
 				throw new SQLException(
@@ -2048,12 +2053,15 @@
 								+ parameterIndex
 								+ Messages.getString("PreparedStatement.3") + this.staticSqlStrings.length + Messages.getString("PreparedStatement.4"), //$NON-NLS-1$ //$NON-NLS-2$
 						SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+			} else if (parameterIndexOffset == -1 && parameterIndex == 1) {
+				throw new SQLException("Can't set IN parameter for return value of stored function call.", 
+					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
 			}
 
-			this.parameterStreams[parameterIndex - 1] = x;
-			this.isStream[parameterIndex - 1] = true;
-			this.streamLengths[parameterIndex - 1] = length;
-			this.isNull[parameterIndex - 1] = false;
+			this.parameterStreams[parameterIndex - 1 + parameterIndexOffset] = x;
+			this.isStream[parameterIndex - 1 + parameterIndexOffset] = true;
+			this.streamLengths[parameterIndex - 1 + parameterIndexOffset] = length;
+			this.isNull[parameterIndex - 1 + parameterIndexOffset] = false;
 		}
 	}
 
@@ -2474,6 +2482,8 @@
 					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
 		}
 
+		int parameterIndexOffset = getParameterIndexOffset();
+		
 		if ((paramIndex < 1)) {
 			throw new SQLException(
 					Messages.getString("PreparedStatement.49") //$NON-NLS-1$
@@ -2485,12 +2495,15 @@
 							+ paramIndex
 							+ Messages.getString("PreparedStatement.52") + (this.parameterValues.length) + Messages.getString("PreparedStatement.53"), //$NON-NLS-1$ //$NON-NLS-2$
 					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+		} else if (parameterIndexOffset == -1 && paramIndex == 1) {
+			throw new SQLException("Can't set IN parameter for return value of stored function call.", 
+					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
 		}
 
-		this.isStream[paramIndex - 1] = false;
-		this.isNull[paramIndex - 1] = false;
-		this.parameterStreams[paramIndex - 1] = null;
-		this.parameterValues[paramIndex - 1] = val;
+		this.isStream[paramIndex - 1 + parameterIndexOffset] = false;
+		this.isNull[paramIndex - 1 + parameterIndexOffset] = false;
+		this.parameterStreams[paramIndex - 1 + parameterIndexOffset] = null;
+		this.parameterValues[paramIndex - 1 + parameterIndexOffset] = val;
 	}
 
 	private final void setInternal(int paramIndex, String val)
@@ -3543,4 +3556,16 @@
 	
 		return buf.toString();
 	}
+	
+	
+	/** 
+	 * For calling stored functions, this will be -1 as we don't really count
+	 * the first '?' parameter marker, it's only syntax, but JDBC counts it
+	 * as #1, otherwise it will return 0 
+	 *
+	 */
+	
+	protected int getParameterIndexOffset() {
+		return 0;
+	}
 }

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-10-18 15:40:15 UTC (rev 5888)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-10-18 17:04:37 UTC (rev 5889)
@@ -633,7 +633,7 @@
 							} catch (SQLException ex) {
 								updateCounts[commandIndex] = EXECUTE_FAILED;
 
-								if (this.connection.getContinueBatchOnError()) {
+								if (this.continueBatchOnError) {
 									sqlEx = ex;
 								} else {
 									int[] newUpdateCounts = new int[commandIndex];

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java	2006-10-18 15:40:15 UTC (rev 5888)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/Statement.java	2006-10-18 17:04:37 UTC (rev 5889)
@@ -169,6 +169,8 @@
 
 	protected boolean retrieveGeneratedKeys = false;
 
+	protected boolean continueBatchOnError = false;
+
 	/**
 	 * Constructor for a Statement.
 	 * 
@@ -189,7 +191,8 @@
 		this.connection = c;
 		this.currentCatalog = catalog;
 		this.pedantic = this.connection.getPedantic();
-
+		this.continueBatchOnError = this.connection.getContinueBatchOnError();
+		
 		if (!this.connection.getDontTrackOpenResources()) {
 			this.connection.registerStatement(this);
 		}

Thread
Connector/J commit: r5889 - in branches/branch_3_1/connector-j: . src/com/mysql/jdbcmmatthews18 Oct