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

📄 mysqlio.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                packet.writeString(database);            }            send(packet);            checkErrorPacket();        }    }    /**     * Checks for errors in the reply packet, and if none, returns the reply     * packet, ready for reading     *     * @return a packet ready for reading.     *     * @throws SQLException is the packet is an error packet     */    protected Buffer checkErrorPacket() throws SQLException {        return checkErrorPacket(-1);    }    /**     * Determines if the database charset is the same as the platform charset     */    protected void checkForCharsetMismatch() {        if (this.connection.getUseUnicode() &&                (this.connection.getEncoding() != null)) {            String encodingToCheck = jvmPlatformCharset;            if (encodingToCheck == null) {                encodingToCheck = System.getProperty("file.encoding"); //$NON-NLS-1$            }            if (encodingToCheck == null) {                this.platformDbCharsetMatches = false;            } else {                this.platformDbCharsetMatches = encodingToCheck.equals(this.connection.getEncoding());            }        }    }    protected void clearInputStream() throws SQLException {        if (!this.useNewIo) {            try {                int len = this.mysqlInput.available();                while (len > 0) {                    this.mysqlInput.skip(len);                    len = this.mysqlInput.available();                }            } catch (IOException ioEx) {                throw new CommunicationsException(this.connection,                    this.lastPacketSentTimeMs, ioEx);            }        } else {            //try {            //if (this.mysqlInput.available() != 0) {            try {                this.socketChannel.configureBlocking(false);                int len = 0;                while (true) {                    len = this.socketChannel.read(this.channelClearBuf);                    if ((len == 0) || (len == -1)) {                        break;                    }                    this.channelClearBuf.clear();                }            } catch (IOException ioEx) {                throw new CommunicationsException(this.connection,                    this.lastPacketSentTimeMs, ioEx);            } finally {                try {                    this.socketChannel.configureBlocking(true);                } catch (IOException ioEx) {                    throw new CommunicationsException(this.connection,                        this.lastPacketSentTimeMs, ioEx);                }            }            //}            //} catch (IOException ioEx) {            //	throw new CommunicationsException(this.connection,            //			this.lastPacketSentTimeMs, ioEx);            //}         }    }    protected void resetReadPacketSequence() {        this.readPacketSequence = 0;    }    protected void dumpPacketRingBuffer() throws SQLException {        if ((this.packetDebugRingBuffer != null) &&                this.connection.getEnablePacketDebug()) {            StringBuffer dumpBuffer = new StringBuffer();            dumpBuffer.append("Last " + this.packetDebugRingBuffer.size() +                " packets received from server, from oldest->newest:\n");            dumpBuffer.append("\n");            for (Iterator ringBufIter = this.packetDebugRingBuffer.iterator();                    ringBufIter.hasNext();) {                dumpBuffer.append((StringBuffer) ringBufIter.next());                dumpBuffer.append("\n");            }            this.connection.getLog().logTrace(dumpBuffer.toString());        }    }    /**     * Runs an 'EXPLAIN' on the given query and dumps the results to  the log     *     * @param querySQL DOCUMENT ME!     * @param truncatedQuery DOCUMENT ME!     *     * @throws SQLException DOCUMENT ME!     */    protected void explainSlowQuery(byte[] querySQL, String truncatedQuery)        throws SQLException {        if (StringUtils.startsWithIgnoreCaseAndWs(truncatedQuery, "SELECT")) { //$NON-NLS-1$            PreparedStatement stmt = null;            java.sql.ResultSet rs = null;            try {                stmt = this.connection.clientPrepareStatement("EXPLAIN ?"); //$NON-NLS-1$                stmt.setBytesNoEscapeNoQuotes(1, querySQL);                rs = stmt.executeQuery();                StringBuffer explainResults = new StringBuffer(Messages.getString(                            "MysqlIO.8") + truncatedQuery //$NON-NLS-1$                         +Messages.getString("MysqlIO.9")); //$NON-NLS-1$                ResultSetUtil.appendResultSetSlashGStyle(explainResults, rs);                this.connection.getLog().logWarn(explainResults.toString());            } catch (SQLException sqlEx) {            } finally {                if (rs != null) {                    rs.close();                }                if (stmt != null) {                    stmt.close();                }            }        } else {        }    }    static int getMaxBuf() {        return maxBufferSize;    }    /**     * Get the major version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerMajorVersion() {        return this.serverMajorVersion;    }    /**     * Get the minor version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerMinorVersion() {        return this.serverMinorVersion;    }    /**     * Get the sub-minor version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerSubMinorVersion() {        return this.serverSubMinorVersion;    }    /**     * Get the version string of the server we are talking to     *     * @return DOCUMENT ME!     */    String getServerVersion() {        return this.serverVersion;    }    /**     * Initialize communications with the MySQL server. Handles logging on, and     * handling initial connection errors.     *     * @param user DOCUMENT ME!     * @param password DOCUMENT ME!     * @param database DOCUMENT ME!     *     * @throws SQLException DOCUMENT ME!     * @throws CommunicationsException DOCUMENT ME!     */    void doHandshake(String user, String password, String database)        throws SQLException {        // Read the first packet        this.checkPacketSequence = false;        this.readPacketSequence = 0;        Buffer buf = readPacket();        // Get the protocol version        this.protocolVersion = buf.readByte();        if (this.protocolVersion == -1) {            try {                this.mysqlConnection.close();            } catch (Exception e) {                ; // ignore            }            int errno = 2000;            errno = buf.readInt();            String serverErrorMessage = buf.readString();            StringBuffer errorBuf = new StringBuffer(Messages.getString(                        "MysqlIO.10")); //$NON-NLS-1$            errorBuf.append(serverErrorMessage);            errorBuf.append("\""); //$NON-NLS-1$            String xOpen = SQLError.mysqlToSqlState(errno,                    this.connection.getUseSqlStateCodes());            throw new SQLException(SQLError.get(xOpen) + ", " //$NON-NLS-1$                 +errorBuf.toString(), xOpen, errno);        }        this.serverVersion = buf.readString();        // Parse the server version into major/minor/subminor        int point = this.serverVersion.indexOf("."); //$NON-NLS-1$        if (point != -1) {            try {                int n = Integer.parseInt(this.serverVersion.substring(0, point));                this.serverMajorVersion = n;            } catch (NumberFormatException NFE1) {                ;            }            String remaining = this.serverVersion.substring(point + 1,                    this.serverVersion.length());            point = remaining.indexOf("."); //$NON-NLS-1$            if (point != -1) {                try {                    int n = Integer.parseInt(remaining.substring(0, point));                    this.serverMinorVersion = n;                } catch (NumberFormatException nfe) {                    ;                }                remaining = remaining.substring(point + 1, remaining.length());                int pos = 0;                while (pos < remaining.length()) {                    if ((remaining.charAt(pos) < '0') ||                            (remaining.charAt(pos) > '9')) {                        break;                    }                    pos++;                }                try {                    int n = Integer.parseInt(remaining.substring(0, pos));                    this.serverSubMinorVersion = n;                } catch (NumberFormatException nfe) {                    ;                }            }        }        if (versionMeetsMinimum(4, 0, 8)) {            this.maxThreeBytes = (256 * 256 * 256) - 1;            this.useNewLargePackets = true;        } else {            this.maxThreeBytes = 255 * 255 * 255;            this.useNewLargePackets = false;        }        this.colDecimalNeedsBump = versionMeetsMinimum(3, 23, 0);        this.colDecimalNeedsBump = !versionMeetsMinimum(3, 23, 15); // guess? Not noted in changelog        this.useNewUpdateCounts = versionMeetsMinimum(3, 22, 5);        buf.readLong(); // thread id -- we don't use it        this.seed = buf.readString();        this.serverCapabilities = 0;        if (buf.getPosition() < buf.getBufLength()) {            this.serverCapabilities = buf.readInt();        }        if (versionMeetsMinimum(4, 1, 1)) {            int position = buf.getPosition();            /* New protocol with 16 bytes to describe server characteristics */            this.serverCharsetIndex = buf.readByte() & 0xff;            this.serverStatus = buf.readInt();            buf.setPosition(position + 16);            String seedPart2 = buf.readString();            StringBuffer newSeed = new StringBuffer(20);            newSeed.append(this.seed);            newSeed.append(seedPart2);            this.seed = newSeed.toString();        }        if (((this.serverCapabilities & CLIENT_COMPRESS) != 0) &&                this.connection.getUseCompression()) {            this.clientParam |= CLIENT_COMPRESS;        }        if ((database != null) && (database.length() > 0)) {            this.clientParam |= CLIENT_CONNECT_WITH_DB;        }        if (((this.serverCapabilities & CLIENT_SSL) == 0) &&                this.connection.getUseSSL()) {            if (this.connection.getRequireSSL()) {                this.connection.close();                forceClose();                throw new SQLException(Messages.getString("MysqlIO.15"), //$NON-NLS-1$                    SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);            }            this.connection.setUseSSL(false);        }        if ((this.serverCapabilities & CLIENT_LONG_FLAG) != 0) {            // We understand other column flags, as well            this.clientParam |= CLIENT_LONG_FLAG;            this.hasLongColumnInfo = true;        }        // return FOUND rows        this.clientParam |= CLIENT_FOUND_ROWS;        if (this.connection.getAllowLoadLocalInfile()) {            this.clientParam |= CLIENT_LOCAL_FILES;        }        if (this.isInteractiveClient) {            this.clientParam |= CLIENT_INTERACTIVE;        }        // Authenticate        if (this.protocolVersion > 9) {            this.clientParam |= CLIENT_LONG_PASSWORD; // for long passwords        } else {

⌨️ 快捷键说明

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