Search in sources :

Example 1 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class JDBCConnection method executeSQL.

private void executeSQL(RouteResultsetNode rrn, ServerConnection sc, boolean autocommit) throws IOException {
    String orgin = rrn.getStatement();
    // LOGGER.info("JDBC SQL:"+orgin+"|"+sc.toString());
    if (!modifiedSQLExecuted && rrn.isModifySQL()) {
        modifiedSQLExecuted = true;
    }
    try {
        syncIsolation(sc.getTxIsolation());
        if (!this.schema.equals(this.oldSchema)) {
            con.setCatalog(schema);
            this.oldSchema = schema;
        }
        if (!this.isSpark) {
            con.setAutoCommit(autocommit);
        }
        int sqlType = rrn.getSqlType();
        if (rrn.isCallStatement() && "oracle".equalsIgnoreCase(getDbType())) {
            //存储过程暂时只支持oracle
            ouputCallStatement(rrn, sc, orgin);
        } else if (sqlType == ServerParse.SELECT || sqlType == ServerParse.SHOW) {
            if ((sqlType == ServerParse.SHOW) && (!dbType.equals("MYSQL"))) {
                // showCMD(sc, orgin);
                //ShowVariables.execute(sc, orgin);
                ShowVariables.execute(sc, orgin, this);
            } else if ("SELECT CONNECTION_ID()".equalsIgnoreCase(orgin)) {
                //ShowVariables.justReturnValue(sc,String.valueOf(sc.getId()));
                ShowVariables.justReturnValue(sc, String.valueOf(sc.getId()), this);
            } else {
                ouputResultSet(sc, orgin);
            }
        } else {
            executeddl(sc, orgin);
        }
    } catch (SQLException e) {
        String msg = e.getMessage();
        ErrorPacket error = new ErrorPacket();
        error.packetId = ++packetId;
        error.errno = e.getErrorCode();
        error.message = msg.getBytes();
        this.respHandler.errorResponse(error.writeToBytes(sc), this);
    } catch (Exception e) {
        String msg = e.getMessage();
        ErrorPacket error = new ErrorPacket();
        error.packetId = ++packetId;
        error.errno = ErrorCode.ER_UNKNOWN_ERROR;
        error.message = ((msg == null) ? e.toString().getBytes() : msg.getBytes());
        String err = null;
        if (error.message != null) {
            err = new String(error.message);
        }
        LOGGER.error("sql execute error, " + err, e);
        this.respHandler.errorResponse(error.writeToBytes(sc), this);
    } finally {
        this.running = false;
    }
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class JDBCConnection method justForHeartbeat.

private void justForHeartbeat(String sql) {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        stmt.execute(sql);
        if (!isAutocommit()) {
            //如果在写库上,如果是事务方式的连接,需要进行手动commit
            con.commit();
        }
        this.respHandler.okResponse(OkPacket.OK, this);
    } catch (Exception e) {
        String msg = e.getMessage();
        ErrorPacket error = new ErrorPacket();
        error.packetId = ++packetId;
        error.errno = ErrorCode.ER_UNKNOWN_ERROR;
        error.message = msg.getBytes();
        this.respHandler.errorResponse(error.writeToBytes(), this);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
            }
        }
    }
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class MultiNodeHandler method errorResponse.

public void errorResponse(byte[] data, BackendConnection conn) {
    session.releaseConnectionIfSafe(conn, LOGGER.isDebugEnabled(), false);
    ErrorPacket err = new ErrorPacket();
    err.read(data);
    String errmsg = new String(err.message);
    this.setFail(errmsg);
    LOGGER.warn("error response from " + conn + " err " + errmsg + " code:" + err.errno);
    this.tryErrorFinished(this.decrementCountBy(1));
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Example 4 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class MultiNodeHandler method createErrPkg.

protected ErrorPacket createErrPkg(String errmgs) {
    ErrorPacket err = new ErrorPacket();
    lock.lock();
    try {
        err.packetId = ++packetId;
    } finally {
        lock.unlock();
    }
    err.errno = ErrorCode.ER_UNKNOWN_ERROR;
    err.message = StringUtil.encode(errmgs, session.getSource().getCharset());
    return err;
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Example 5 with ErrorPacket

use of io.mycat.net.mysql.ErrorPacket in project Mycat-Server by MyCATApache.

the class PostgreSQLBackendConnectionHandler method doProcessErrorResponse.

/***
	 * 处理查询出错数据包
	 * 
	 * @param con
	 * @param errorResponse
	 */
private void doProcessErrorResponse(PostgreSQLBackendConnection con, ErrorResponse errorResponse) {
    LOGGER.debug("查询出错了!");
    ErrorPacket err = new ErrorPacket();
    err.packetId = ++packetId;
    err.message = errorResponse.getErrMsg().trim().replaceAll("\0", " ").getBytes();
    err.errno = ErrorCode.ER_UNKNOWN_ERROR;
    con.getResponseHandler().errorResponse(err.writeToBytes(), con);
}
Also used : ErrorPacket(io.mycat.net.mysql.ErrorPacket)

Aggregations

ErrorPacket (io.mycat.net.mysql.ErrorPacket)21 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HandshakePacket (io.mycat.net.mysql.HandshakePacket)2 ConnectionException (io.mycat.net.ConnectionException)1 AuthPacket (io.mycat.net.mysql.AuthPacket)1 BinaryPacket (io.mycat.net.mysql.BinaryPacket)1 HeartbeatPacket (io.mycat.net.mysql.HeartbeatPacket)1 OkPacket (io.mycat.net.mysql.OkPacket)1 Reply323Packet (io.mycat.net.mysql.Reply323Packet)1 ServerConnection (io.mycat.server.ServerConnection)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1