use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class HeartbeatPacket method read.
public void read(byte[] data) {
MySQLMessage mm = new MySQLMessage(data);
packetLength = mm.readUB3();
packetId = mm.read();
command = mm.read();
id = mm.readLength();
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class ResultSetHeaderPacket method read.
public void read(byte[] data) {
MySQLMessage mm = new MySQLMessage(data);
this.packetLength = mm.readUB3();
this.packetId = mm.read();
this.fieldCount = (int) mm.readLength();
if (mm.hasRemaining()) {
this.extra = mm.readLength();
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class MySQLMessageTest method testReadBytesWithNull2.
@Test
public void testReadBytesWithNull2() {
byte[] bytes = new byte[] { 0, 1, 2, 3, 0, 5 };
MySQLMessage message = new MySQLMessage(bytes);
byte[] ab = message.readBytesWithNull();
Assert.assertEquals(0, ab.length);
Assert.assertEquals(1, message.position());
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class FrontendConnection method initDB.
public void initDB(byte[] data) {
MySQLMessage mm = new MySQLMessage(data);
mm.position(5);
String db = mm.readString();
// 检查schema的有效性
if (db == null || !privileges.schemaExists(db)) {
writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return;
}
if (!privileges.userExists(user, host)) {
writeErrMessage(ErrorCode.ER_ACCESS_DENIED_ERROR, "Access denied for user '" + user + "'");
return;
}
Set<String> schemas = privileges.getUserSchemas(user);
if (schemas == null || schemas.size() == 0 || schemas.contains(db)) {
this.schema = db;
write(writeToBuffer(OkPacket.OK, allocate()));
} else {
String s = "Access denied for user '" + user + "' to database '" + db + "'";
writeErrMessage(ErrorCode.ER_DBACCESS_DENIED_ERROR, s);
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class FrontendConnection method query.
public void query(byte[] data) {
// 取得语句
String sql = null;
try {
MySQLMessage mm = new MySQLMessage(data);
mm.position(5);
sql = mm.readString(charset);
} catch (UnsupportedEncodingException e) {
writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset '" + charset + "'");
return;
}
this.query(sql);
}
Aggregations