List:Commits« Previous MessageNext Message »
From:mmatthews Date:March 9 2006 9:05pm
Subject:Connector/J commit: r5031 - in branches: branch_5_0/connector-j/src/com/mysql/jdbc branch_5_1/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
Log:
Return fetch size in use on result set if cursor-based fetch is being used.

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java	2006-03-09 01:02:14
UTC (rev 5030)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java	2006-03-09 20:05:02
UTC (rev 5031)
@@ -419,11 +419,17 @@
 					prepStmt,
 					((com.mysql.jdbc.ResultSetMetaData) prepStmt.getMetaData()).fields);
 
-				return buildResultSetWithRows(
+				ResultSet rs = buildResultSetWithRows(
 					callingStatement,
 					catalog,
 					((com.mysql.jdbc.ResultSetMetaData) prepStmt.getMetaData()).fields,
 					rows, resultSetType, resultSetConcurrency, isBinaryEncoded);
+				
+				if (usingCursor) {
+		        	rs.setFetchSize(callingStatement.getFetchSize());
+		        }
+				
+				return rs;
 			}
 		}
 		
@@ -441,6 +447,8 @@
         ResultSet rs = buildResultSetWithRows(callingStatement, catalog, fields,
             rowData, resultSetType, resultSetConcurrency, isBinaryEncoded);
  
+        
+        
         return rs;
     }
 
@@ -2520,25 +2528,24 @@
         }
     }
 
-    /**
-    * Send a packet to the MySQL server
-    *
-    * @param packet DOCUMENT ME!
-    *
-    * @throws SQLException DOCUMENT ME!
-    */
-    //final void send(Buffer packet) throws SQLException {
-    //    int l = packet.getPosition();
-    //    send(packet, l);
-
-        // 
-        // Don't hold on to large packets
-        //
-     //   if (packet == this.sharedSendPacket) {
-     //       reclaimLargeSharedSendPacket();
-     //   }
-   // }
-
+    void enableMultiQueries() throws SQLException {
+    	Buffer buf = getSharedSendPacket();
+    	
+    	buf.clear();
+    	buf.writeByte((byte)MysqlDefs.COM_SET_OPTION);
+    	buf.writeInt(0);
+    	sendCommand(MysqlDefs.COM_SET_OPTION, null, buf, false, null);
+    }
+    
+    void disableMultiQueries() throws SQLException {
+    	Buffer buf = getSharedSendPacket();
+    	
+    	buf.clear();
+    	buf.writeByte((byte)MysqlDefs.COM_SET_OPTION);
+    	buf.writeInt(1);
+    	sendCommand(MysqlDefs.COM_SET_OPTION, null, buf, false, null);
+    }
+    
     private final void send(Buffer packet, int packetLen)
         throws SQLException {
         try {

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-03-09
01:02:14 UTC (rev 5030)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-03-09
20:05:02 UTC (rev 5031)
@@ -1011,7 +1011,7 @@
 					if (this.parameterBindings[i].isLongData) {
 						if (firstFound && boundTimeToCheck != 
 							this.parameterBindings[i].boundBeforeExecutionNum) { 					
-							throw new SQLException(Messages
+							throw SQLError.createSQLException(Messages
 									.getString("ServerPreparedStatement.11") //$NON-NLS-1$
 									+ Messages.getString("ServerPreparedStatement.12"), //$NON-NLS-1$
 									SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);
@@ -1028,10 +1028,11 @@
 				serverResetStatement();
 			}
 
+
 			// Check bindings
 			for (int i = 0; i < this.parameterCount; i++) {
 				if (!this.parameterBindings[i].isSet) {
-					throw new SQLException(Messages
+					throw SQLError.createSQLException(Messages
 							.getString("ServerPreparedStatement.13") + (i + 1) //$NON-NLS-1$
 							+ Messages.getString("ServerPreparedStatement.14"),
 							SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
@@ -1062,9 +1063,28 @@
 			packet.writeByte((byte) MysqlDefs.COM_EXECUTE);
 			packet.writeLong(this.serverStatementId);
 
+			boolean usingCursor = false;
+
 			if (this.connection.versionMeetsMinimum(4, 1, 2)) {
-				packet.writeByte((byte) 0); // placeholder for flags
-				packet.writeLong(1); // placeholder for parameter iterations
+				// we only create cursor-backed result sets if
+				// a) The query is a SELECT
+				// b) The server supports it
+				// c) We know it is forward-only (note this doesn't
+				// preclude updatable result sets)
+				// d) The user has set a fetch size
+				if (this.resultFields != null &&
+						this.connection.isCursorFetchEnabled()
+						&& getResultSetType() == ResultSet.TYPE_FORWARD_ONLY
+						&& getResultSetConcurrency() == ResultSet.CONCUR_READ_ONLY
+						&& getFetchSize() > 0) {
+					packet.writeByte(MysqlDefs.OPEN_CURSOR_FLAG);
+					usingCursor = true;
+				} else {
+					packet.writeByte((byte) 0); // placeholder for flags
+				}
+
+				packet.writeLong(1); // placeholder for parameter
+				                     // iterations
 			}
 
 			/* Reserve place for null-marker bytes */
@@ -1124,86 +1144,112 @@
 				begin = System.currentTimeMillis();
 			}
 
-			Buffer resultPacket = mysql.sendCommand(MysqlDefs.COM_EXECUTE,
-					null, packet, false, null);
-
+			this.wasCancelled = false;
 			
+			CancelThread timeoutThread = null;
 
-			this.connection.incrementNumberOfPreparedExecutes();
-
-			if (this.connection.getProfileSql()) {
-				this.eventSink = ProfileEventSink.getInstance(this.connection);
-
-				this.eventSink.consumeEvent(new ProfilerEvent(
-						ProfilerEvent.TYPE_EXECUTE, "", this.currentCatalog, //$NON-NLS-1$
-						this.connection.getId(), this.statementId, -1, System
-								.currentTimeMillis(), (int) (System
-								.currentTimeMillis() - begin), null,
-						new Throwable(), truncateQueryToLog(asSql(true))));
-			}
-
-			com.mysql.jdbc.ResultSet rs = mysql.readAllResults(this,
-					maxRowsToRetrieve, this.resultSetType,
-					this.resultSetConcurrency, createStreamingResultSet,
-					this.currentCatalog, resultPacket, true, this.fieldCount,
-					true);
-
+			try {
+				if (this.timeout != 0
+						&& this.connection.versionMeetsMinimum(5, 0, 0)
+						&& !usingCursor /* FIXME: Not supported currently */) {
+					timeoutThread = new CancelThread(this.timeout);
+					new Thread(timeoutThread).start();
+				}
+				
+				Buffer resultPacket = mysql.sendCommand(MysqlDefs.COM_EXECUTE,
+					null, packet, false, null);
+				
+				if (timeoutThread != null) {
+					timeoutThread.dontCancel();
+					timeoutThread = null;
+				}
+				
+				if (this.wasCancelled) {
+					this.wasCancelled = false;
+					throw new MySQLTimeoutException();
+				}
 			
-			if (!createStreamingResultSet && 
-					this.serverNeedsResetBeforeEachExecution) {
-				serverResetStatement(); // clear any long data...
-			}
-
-			this.sendTypesToServer = false;
-			this.results = rs;
-
-			if (this.connection.getLogSlowQueries()
-					|| this.connection.getGatherPerformanceMetrics()) {
-				long elapsedTime = System.currentTimeMillis() - begin;
-
+				this.connection.incrementNumberOfPreparedExecutes();
+	
+				if (this.connection.getProfileSql()) {
+					this.eventSink = ProfileEventSink.getInstance(this.connection);
+	
+					this.eventSink.consumeEvent(new ProfilerEvent(
+							ProfilerEvent.TYPE_EXECUTE, "", this.currentCatalog, //$NON-NLS-1$
+							this.connectionId, this.statementId, -1, System
+									.currentTimeMillis(), (int) (System
+									.currentTimeMillis() - begin), null,
+							new Throwable(), truncateQueryToLog(asSql(true))));
+				}
+	
+				com.mysql.jdbc.ResultSet rs = mysql.readAllResults(this,
+						maxRowsToRetrieve, this.resultSetType,
+						this.resultSetConcurrency, createStreamingResultSet,
+						this.currentCatalog, resultPacket, true, this.fieldCount,
+						true);
+	
+				
+				if (!createStreamingResultSet && 
+						this.serverNeedsResetBeforeEachExecution) {
+					serverResetStatement(); // clear any long data...
+				}
+	
+				this.sendTypesToServer = false;
+				this.results = rs;
+	
 				if (this.connection.getLogSlowQueries()
-						&& (elapsedTime >= this.connection
-								.getSlowQueryThresholdMillis())) {
-					StringBuffer mesgBuf = new StringBuffer(
-							48 + this.originalSql.length());
-					mesgBuf.append(Messages
-							.getString("ServerPreparedStatement.15")); //$NON-NLS-1$
-					mesgBuf.append(this.connection
-							.getSlowQueryThresholdMillis());
-					mesgBuf.append(Messages
-							.getString("ServerPreparedStatement.15a")); //$NON-NLS-1$
-					mesgBuf.append(elapsedTime);
-					mesgBuf.append(Messages
-							.getString("ServerPreparedStatement.16")); //$NON-NLS-1$
-					
-					mesgBuf.append("as prepared: ");
-					mesgBuf.append(this.originalSql);
-					mesgBuf.append("\n\n with parameters bound:\n\n");
-					mesgBuf.append(asSql(true));
-
-					this.connection.getLog().logWarn(mesgBuf.toString());
-
-					if (this.connection.getExplainSlowQueries()) {
-						String queryAsString = asSql(true);
-
-						mysql.explainSlowQuery(queryAsString.getBytes(),
-								queryAsString);
+						|| this.connection.getGatherPerformanceMetrics()) {
+					long elapsedTime = System.currentTimeMillis() - begin;
+	
+					if (this.connection.getLogSlowQueries()
+							&& (elapsedTime >= this.connection
+									.getSlowQueryThresholdMillis())) {
+						StringBuffer mesgBuf = new StringBuffer(
+								48 + this.originalSql.length());
+						mesgBuf.append(Messages
+								.getString("ServerPreparedStatement.15")); //$NON-NLS-1$
+						mesgBuf.append(this.connection
+								.getSlowQueryThresholdMillis());
+						mesgBuf.append(Messages
+								.getString("ServerPreparedStatement.15a")); //$NON-NLS-1$
+						mesgBuf.append(elapsedTime);
+						mesgBuf.append(Messages
+								.getString("ServerPreparedStatement.16")); //$NON-NLS-1$
+						
+						mesgBuf.append("as prepared: ");
+						mesgBuf.append(this.originalSql);
+						mesgBuf.append("\n\n with parameters bound:\n\n");
+						mesgBuf.append(asSql(true));
+	
+						this.connection.getLog().logWarn(mesgBuf.toString());
+	
+						if (this.connection.getExplainSlowQueries()) {
+							String queryAsString = asSql(true);
+	
+							mysql.explainSlowQuery(queryAsString.getBytes(),
+									queryAsString);
+						}
 					}
+	
+					if (this.connection.getGatherPerformanceMetrics()) {
+						this.connection.registerQueryExecutionTime(elapsedTime);
+					}
 				}
-
-				if (this.connection.getGatherPerformanceMetrics()) {
-					this.connection.registerQueryExecutionTime(elapsedTime);
+				
+				if (mysql.hadWarnings()) {
+		            mysql.scanForAndThrowDataTruncation();
+		        }
+				
+				return rs;
+			} finally {
+				if (timeoutThread != null) {
+					timeoutThread.dontCancel();
 				}
 			}
-			
-			if (mysql.hadWarnings()) {
-	            mysql.scanForAndThrowDataTruncation();
-	        }
-			
-			return rs;
 		}
 	}
 
+
 	/**
 	 * Sends stream-type data parameters to the server.
 	 * 

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java	2006-03-09 01:02:14
UTC (rev 5030)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java	2006-03-09 20:05:02
UTC (rev 5031)
@@ -1492,11 +1492,17 @@
 					prepStmt,
 					((com.mysql.jdbc.ResultSetMetaData) prepStmt.getMetaData()).fields);
 
-				return buildResultSetWithRows(
-					callingStatement,
-					catalog,
-					((com.mysql.jdbc.ResultSetMetaData) prepStmt.getMetaData()).fields,
-					rows, resultSetType, resultSetConcurrency, isBinaryEncoded);
+				ResultSet rs = buildResultSetWithRows(
+						callingStatement,
+						catalog,
+						((com.mysql.jdbc.ResultSetMetaData) prepStmt.getMetaData()).fields,
+						rows, resultSetType, resultSetConcurrency, isBinaryEncoded);
+					
+				if (usingCursor) {
+			        rs.setFetchSize(callingStatement.getFetchSize());
+			    }
+					
+				return rs;
 			}
 		}
 		
@@ -2600,6 +2606,24 @@
         }
     }
 
+    void enableMultiQueries() throws SQLException {
+    	Buffer buf = getSharedSendPacket();
+    	
+    	buf.clear();
+    	buf.writeByte((byte)MysqlDefs.COM_SET_OPTION);
+    	buf.writeInt(0);
+    	sendCommand(MysqlDefs.COM_SET_OPTION, null, buf, false, null);
+    }
+    
+    void disableMultiQueries() throws SQLException {
+    	Buffer buf = getSharedSendPacket();
+    	
+    	buf.clear();
+    	buf.writeByte((byte)MysqlDefs.COM_SET_OPTION);
+    	buf.writeInt(1);
+    	sendCommand(MysqlDefs.COM_SET_OPTION, null, buf, false, null);
+    }
+    
     private final void send(Buffer packet, int packetLen)
         throws SQLException {
         try {

Thread
Connector/J commit: r5031 - in branches: branch_5_0/connector-j/src/com/mysql/jdbc branch_5_1/connector-j/src/com/mysql/jdbcmmatthews9 Mar