Search in sources :

Example 46 with MySQLMessage

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();
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 47 with MySQLMessage

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();
    }
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 48 with MySQLMessage

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());
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage) Test(org.junit.Test)

Example 49 with MySQLMessage

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);
    }
}
Also used : MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Example 50 with MySQLMessage

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);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) MySQLMessage(io.mycat.backend.mysql.MySQLMessage)

Aggregations

MySQLMessage (io.mycat.backend.mysql.MySQLMessage)56 Test (org.junit.Test)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ByteBuffer (java.nio.ByteBuffer)4 BindValue (io.mycat.backend.mysql.BindValue)2 BufferHolder (io.mycat.memory.unsafe.row.BufferHolder)2 UnsafeRow (io.mycat.memory.unsafe.row.UnsafeRow)2 UnsafeRowWriter (io.mycat.memory.unsafe.row.UnsafeRowWriter)2 EOFPacket (io.mycat.net.mysql.EOFPacket)2 ServerConnection (io.mycat.server.ServerConnection)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2