use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.
the class MySQLChannel method sendCharset.
/**
* 发送字符集设置
*/
private void sendCharset(int ci) throws IOException {
// 发送命令: 直接写入到out中即可
CommandPacket cmd = getCharsetCommand(ci);
cmd.write(out);
out.flush();
BinaryPacket bin = receive();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
this.charsetIndex = ci;
this.charset = CharsetUtil.getCharset(ci);
this.dbCharset = CharsetUtil.getCharset(ci);
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
default:
throw new UnknownPacketException(bin.toString());
}
}
use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.
the class MySQLChannel method getCharsetCommand.
private CommandPacket getCharsetCommand(int ci) {
String charset = CharsetUtil.getDbCharset(ci);
StringBuilder s = new StringBuilder();
s.append("SET names ").append(charset);
CommandPacket cmd = new CommandPacket();
cmd.packetId = 0;
cmd.command = MySQLPacket.COM_QUERY;
cmd.arg = s.toString().getBytes();
return cmd;
}
use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.
the class MySQLChannel method getSqlModeCommand.
private CommandPacket getSqlModeCommand() {
StringBuilder s = new StringBuilder();
s.append("SET sql_mode=\"").append(dsc.getSqlMode()).append('"');
CommandPacket cmd = new CommandPacket();
cmd.packetId = 0;
cmd.command = MySQLPacket.COM_QUERY;
cmd.arg = s.toString().getBytes();
return cmd;
}
use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.
the class MySQLChannel method sendAutocommit.
/**
* 发送事务递交模式设置
*/
private void sendAutocommit(boolean autocommit) throws IOException {
CommandPacket cmd = getAutocommitCommand(autocommit);
cmd.write(out);
out.flush();
BinaryPacket bin = receive();
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
this.autocommit = autocommit;
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
default:
throw new UnknownPacketException(bin.toString());
}
}
use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.
the class KillConnectionHandler method connectionAcquired.
@Override
public void connectionAcquired(MySQLConnection conn) {
conn.setResponseHandler(this);
CommandPacket packet = new CommandPacket();
packet.packetId = 0;
packet.command = MySQLPacket.COM_QUERY;
packet.arg = new StringBuilder("KILL ").append(killee.getThreadId()).toString().getBytes();
packet.write(conn);
}
Aggregations