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;
}
}
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) {
}
}
}
}
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));
}
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;
}
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);
}
Aggregations