⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlio.java

📁 用于JAVA数据库连接.解压就可用,方便得很
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						remaining -= 2;						if (remaining > 0) {							skipFully(this.mysqlInput, remaining);						}						return null; // last data packet					}					rowData = new byte[columnCount][];					firstTime = false;				}				int len = 0;				switch (sw) {				case 251:					len = NULL_LENGTH;					break;				case 252:					len = (this.mysqlInput.read() & 0xff)							| ((this.mysqlInput.read() & 0xff) << 8);					remaining -= 2;					break;				case 253:					len = (this.mysqlInput.read() & 0xff)							| ((this.mysqlInput.read() & 0xff) << 8)							| ((this.mysqlInput.read() & 0xff) << 16);					remaining -= 3;					break;				case 254:					len = (int) ((this.mysqlInput.read() & 0xff)							| ((long) (this.mysqlInput.read() & 0xff) << 8)							| ((long) (this.mysqlInput.read() & 0xff) << 16)							| ((long) (this.mysqlInput.read() & 0xff) << 24)							| ((long) (this.mysqlInput.read() & 0xff) << 32)							| ((long) (this.mysqlInput.read() & 0xff) << 40)							| ((long) (this.mysqlInput.read() & 0xff) << 48)							| ((long) (this.mysqlInput.read() & 0xff) << 56));					remaining -= 8;					break;				default:					len = sw;				}				if (len == NULL_LENGTH) {					rowData[i] = null;				} else if (len == 0) {					rowData[i] = Constants.EMPTY_BYTE_ARRAY;				} else {					rowData[i] = new byte[len];					int bytesRead = readFully(this.mysqlInput, rowData[i], 0,							len);					if (bytesRead != len) {						throw SQLError.createCommunicationsException(this.connection,			    				this.lastPacketSentTimeMs,			    				new IOException(Messages.getString("MysqlIO.43")));					}					remaining -= bytesRead;				}			}			if (remaining > 0) {				skipFully(this.mysqlInput, remaining);			}			return new ByteArrayRow(rowData);		} catch (IOException ioEx) {			throw SQLError.createCommunicationsException(this.connection,    				this.lastPacketSentTimeMs, ioEx);		}	}    /**     * Log-off of the MySQL server and close the socket.     *     * @throws SQLException DOCUMENT ME!     */    final void quit() throws SQLException {        Buffer packet = new Buffer(6);        this.packetSequence = -1;        packet.writeByte((byte) MysqlDefs.QUIT);        send(packet, packet.getPosition());        forceClose();    }    /**     * Returns the packet used for sending data (used by PreparedStatement)     * Guarded by external synchronization on a mutex.     *     * @return A packet to send data with     */    Buffer getSharedSendPacket() {        if (this.sharedSendPacket == null) {        	this.sharedSendPacket = new Buffer(INITIAL_PACKET_SIZE);        }        return this.sharedSendPacket;    }    void closeStreamer(RowData streamer) throws SQLException {        if (this.streamingData == null) {            throw SQLError.createSQLException(Messages.getString("MysqlIO.17") //$NON-NLS-1$                 +streamer + Messages.getString("MysqlIO.18")); //$NON-NLS-1$        }        if (streamer != this.streamingData) {            throw SQLError.createSQLException(Messages.getString("MysqlIO.19") //$NON-NLS-1$                 +streamer + Messages.getString("MysqlIO.20") //$NON-NLS-1$                 +Messages.getString("MysqlIO.21") //$NON-NLS-1$                 +Messages.getString("MysqlIO.22")); //$NON-NLS-1$        }        this.streamingData = null;    }    ResultSetImpl readAllResults(StatementImpl callingStatement, int maxRows,        int resultSetType, int resultSetConcurrency, boolean streamResults,        String catalog, Buffer resultPacket, boolean isBinaryEncoded,        long preSentColumnCount, Field[] metadataFromCache)        throws SQLException {        resultPacket.setPosition(resultPacket.getPosition() - 1);        ResultSetImpl topLevelResultSet = readResultsForQueryOrUpdate(callingStatement,                maxRows, resultSetType, resultSetConcurrency, streamResults,                catalog, resultPacket, isBinaryEncoded, preSentColumnCount,                metadataFromCache);        ResultSetImpl currentResultSet = topLevelResultSet;        boolean checkForMoreResults = ((this.clientParam &            CLIENT_MULTI_RESULTS) != 0);        boolean serverHasMoreResults = (this.serverStatus &            SERVER_MORE_RESULTS_EXISTS) != 0;        //        // TODO: We need to support streaming of multiple result sets        //        if (serverHasMoreResults && streamResults) {            clearInputStream();            throw SQLError.createSQLException(Messages.getString("MysqlIO.23"), //$NON-NLS-1$                SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);        }        boolean moreRowSetsExist = checkForMoreResults & serverHasMoreResults;        while (moreRowSetsExist) {        	Buffer fieldPacket = checkErrorPacket();            fieldPacket.setPosition(0);            ResultSetImpl newResultSet = readResultsForQueryOrUpdate(callingStatement,                    maxRows, resultSetType, resultSetConcurrency,                    streamResults, catalog, fieldPacket, isBinaryEncoded,                    preSentColumnCount, metadataFromCache);            currentResultSet.setNextResultSet(newResultSet);            currentResultSet = newResultSet;            moreRowSetsExist = (this.serverStatus & SERVER_MORE_RESULTS_EXISTS) != 0;        }        if (!streamResults) {            clearInputStream();        }        reclaimLargeReusablePacket();        return topLevelResultSet;    }    /**     * Sets the buffer size to max-buf     */    void resetMaxBuf() {        this.maxAllowedPacket = this.connection.getMaxAllowedPacket();    }    /**     * Send a command to the MySQL server If data is to be sent with command,     * it should be put in extraData.     *     * Raw packets can be sent by setting queryPacket to something other     * than null.     *     * @param command the MySQL protocol 'command' from MysqlDefs     * @param extraData any 'string' data for the command     * @param queryPacket a packet pre-loaded with data for the protocol (i.e.     * from a client-side prepared statement).     * @param skipCheck do not call checkErrorPacket() if true     * @param extraDataCharEncoding the character encoding of the extraData     * parameter.     *     * @return the response packet from the server     *     * @throws SQLException if an I/O error or SQL error occurs     */    final Buffer sendCommand(int command, String extraData, Buffer queryPacket,        boolean skipCheck, String extraDataCharEncoding)        throws SQLException {        //        // We cache these locally, per-command, as the checks        // for them are in very 'hot' sections of the I/O code        // and we save 10-15% in overall performance by doing this...        //        this.enablePacketDebug = this.connection.getEnablePacketDebug();        this.traceProtocol = this.connection.getTraceProtocol();        this.readPacketSequence = 0;        try {            checkForOutstandingStreamingData();            // Clear serverStatus...this value is guarded by an            // external mutex, as you can only ever be processing            // one command at a time            this.serverStatus = 0;            this.hadWarnings = false;            this.warningCount = 0;            this.queryNoIndexUsed = false;            this.queryBadIndexUsed = false;            //            // Compressed input stream needs cleared at beginning            // of each command execution...            //            if (this.useCompression) {                int bytesLeft = this.mysqlInput.available();                if (bytesLeft > 0) {                    this.mysqlInput.skip(bytesLeft);                }            }            try {                clearInputStream();                //                // PreparedStatements construct their own packets,                // for efficiency's sake.                //                // If this is a generic query, we need to re-use                // the sending packet.                //                if (queryPacket == null) {                    int packLength = HEADER_LENGTH + COMP_HEADER_LENGTH + 1 +                        ((extraData != null) ? extraData.length() : 0) + 2;                    if (this.sendPacket == null) {                        this.sendPacket = new Buffer(packLength);                    }                    this.packetSequence = -1;                    this.readPacketSequence = 0;                    this.checkPacketSequence = true;                    this.sendPacket.clear();                    this.sendPacket.writeByte((byte) command);                    if ((command == MysqlDefs.INIT_DB) ||                            (command == MysqlDefs.CREATE_DB) ||                            (command == MysqlDefs.DROP_DB) ||                            (command == MysqlDefs.QUERY) ||                            (command == MysqlDefs.COM_PREPARE)) {                        if (extraDataCharEncoding == null) {                            this.sendPacket.writeStringNoNull(extraData);                        } else {                            this.sendPacket.writeStringNoNull(extraData,                                extraDataCharEncoding,                                this.connection.getServerCharacterEncoding(),                                this.connection.parserKnowsUnicode(), this.connection);                        }                    } else if (command == MysqlDefs.PROCESS_KILL) {                        long id = Long.parseLong(extraData);                        this.sendPacket.writeLong(id);                    }                    send(this.sendPacket, this.sendPacket.getPosition());                } else {                    this.packetSequence = -1;                    send(queryPacket, queryPacket.getPosition()); // packet passed by PreparedStatement                }            } catch (SQLException sqlEx) {                // don't wrap SQLExceptions                throw sqlEx;            } catch (Exception ex) {                throw SQLError.createCommunicationsException(this.connection,                    this.lastPacketSentTimeMs, ex);            }            Buffer returnPacket = null;            if (!skipCheck) {                if ((command == MysqlDefs.COM_EXECUTE) ||                        (command == MysqlDefs.COM_RESET_STMT)) {                    this.readPacketSequence = 0;                    this.packetSequenceReset = true;                }                returnPacket = checkErrorPacket(command);            }            return returnPacket;        } catch (IOException ioEx) {            throw SQLError.createCommunicationsException(this.connection,                this.lastPacketSentTimeMs, ioEx);        }    }    private int statementExecutionDepth = 0;	private boolean useAutoSlowLog;    /**     * Send a query stored in a packet directly to the server.     *     * @param callingStatement DOCUMENT ME!     * @param resultSetConcurrency DOCUMENT ME!     * @param characterEncoding DOCUMENT ME!     * @param queryPacket DOCUMENT ME!     * @param maxRows DOCUMENT ME!     * @param conn DOCUMENT ME!     * @param resultSetType DOCUMENT ME!     * @param resultSetConcurrency DOCUMENT ME!     * @param streamResults DOCUMENT ME!     * @param catalog DOCUMENT ME!     * @param unpackFieldInfo should we read MYSQL_FIELD info (if available)?     *     * @return DOCUMENT ME!     *     * @throws Exception DOCUMENT ME!     */    final ResultSetInternalMethods sqlQueryDirect(StatementImpl callingStatement, String query,    		String characterEncoding, Buffer queryPacket, int maxRows,    		int resultSetType, int resultSetConcurrency,    		boolean streamResults, String catalog, Field[] cachedMetadata)    throws Exception {    	this.statementExecutionDepth++;    	try {	    	if (this.statementInterceptors != null) {	    		ResultSetInternalMethods interceptedResults =	    			invokeStatementInterceptorsPre(query, callingStatement);	    		if (interceptedResults != null) {	    			return interceptedResults;	    		}	    	}	    	long queryStartTime = 0;	    	long queryEndTime = 0;	    	if (query != null) {	    		// We don't know exactly how many bytes we're going to get	    		// from the query. Since we're dealing with Unicode, the	    		// max is 2, so pad it (2 * query) + space for headers	    		int packLength = HEADER_LENGTH + 1 + (query.length() * 2) + 2;	    		String statementComment = this.connection.getStatementComment();	    		byte[] commentAsBytes = null;	    		if (statementComment != null) {	    			commentAsBytes = StringUtils.getBytes(statementC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -