Search in sources :

Example 1 with ExecutePacket

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

the class ServerPrepareHandler method execute.

@Override
public void execute(byte[] data) {
    long pstmtId = ByteUtil.readUB4(data, 5);
    PreparedStatement pstmt = null;
    if ((pstmt = pstmtForId.get(pstmtId)) == null) {
        source.writeErrMessage(ErrorCode.ER_ERROR_WHEN_EXECUTING_COMMAND, "Unknown pstmtId when executing.");
    } else {
        ExecutePacket packet = new ExecutePacket(pstmt);
        try {
            packet.read(data, source.getCharset());
        } catch (UnsupportedEncodingException e) {
            source.writeErrMessage(ErrorCode.ER_ERROR_WHEN_EXECUTING_COMMAND, e.getMessage());
            return;
        }
        BindValue[] bindValues = packet.values;
        // 还原sql中的动态参数为实际参数值
        String sql = prepareStmtBindValue(pstmt, bindValues);
        // 执行sql
        source.getSession2().setPrepared(true);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("execute prepare sql: " + sql);
        }
        source.query(sql);
    }
}
Also used : ExecutePacket(io.mycat.net.mysql.ExecutePacket) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PreparedStatement(io.mycat.backend.mysql.PreparedStatement) BindValue(io.mycat.backend.mysql.BindValue)

Aggregations

BindValue (io.mycat.backend.mysql.BindValue)1 PreparedStatement (io.mycat.backend.mysql.PreparedStatement)1 ExecutePacket (io.mycat.net.mysql.ExecutePacket)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1