Search in sources :

Example 36 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class TableSelectTest method testBug22038729.

/**
 * Tests fix for Bug#22038729, X DEVAPI: ANY API CALL AFTER A FAILED CALL PROC() RESULTS IN HANG
 * and for duplicate Bug#25575010, X DEVAPI: ANY API CALL AFTER A FAILED SELECT RESULTS IN HANG
 *
 * @throws Exception
 */
@Test
public void testBug22038729() throws Exception {
    final Field pf = CoreSession.class.getDeclaredField("protocol");
    pf.setAccessible(true);
    try {
        sqlUpdate("drop table if exists testBug22038729");
        sqlUpdate("create table testBug22038729 (c1 int, c2 int unsigned, id bigint)");
        sqlUpdate("insert into testBug22038729 values(10, 100, -9223372036854775808)");
        sqlUpdate("insert into testBug22038729 values(11, 11, 9223372036854775806)");
        sqlUpdate("drop procedure if exists testBug22038729p");
        sqlUpdate("create procedure testBug22038729p (in p1 int,IN p2 char(20)) begin select -10;select id+1000 from testBug22038729; end;");
        // XProtocol.readRowOrNull()
        Session sess = new SessionFactory().getSession(this.testProperties);
        Table t1 = sess.getDefaultSchema().getTable("testBug22038729");
        RowResult rows = t1.select("c1-c2").orderBy("c1 DESC").execute();
        assertTrue(rows.hasNext());
        Row r = rows.next();
        assertEquals(0, r.getInt(0));
        assertThrows(XProtocolError.class, "ERROR 1690 \\(22003\\) BIGINT UNSIGNED value is out of range .*", () -> rows.hasNext());
        // It was hanging
        sess.close();
        // XProtocol.readRowOrNull()
        sess = new SessionFactory().getSession(this.testProperties);
        SqlResult rs1 = sess.sql("select c1-c2 from testBug22038729 order by c1 desc").execute();
        assertEquals(0, rs1.fetchOne().getInt(0));
        assertThrows(XProtocolError.class, "ERROR 1690 \\(22003\\) BIGINT UNSIGNED value is out of range .*", () -> rs1.fetchOne());
        // It was hanging
        sess.close();
        // XProtocol.drainRows()
        sess = new SessionFactory().getSession(this.testProperties);
        sess.sql("select c1-c2 from testBug22038729 order by c1 desc").execute();
        XProtocol xp = (XProtocol) pf.get(((SessionImpl) sess).getSession());
        assertThrows(XProtocolError.class, "ERROR 1690 \\(22003\\) BIGINT UNSIGNED value is out of range .*", () -> {
            xp.drainRows();
            return xp;
        });
        // It was hanging
        sess.close();
        sess = new SessionFactory().getSession(this.testProperties);
        SqlResult rs2 = sess.sql("call testBug22038729p(?, ?)").bind(10).bind("X").execute();
        assertTrue(rs2.hasData());
        assertTrue(rs2.hasNext());
        r = rs2.next();
        assertEquals(-10, r.getInt(0));
        assertFalse(rs2.hasNext());
        assertTrue(rs2.nextResult());
        assertTrue(rs2.hasData());
        assertTrue(rs2.hasNext());
        r = rs2.next();
        assertEquals(-9223372036854774808L, r.getLong(0));
        assertThrows(XProtocolError.class, "ERROR 1690 \\(22003\\) BIGINT value is out of range .*", () -> rs2.hasNext());
        // It was hanging
        sess.close();
    } finally {
        sqlUpdate("drop table if exists testBug22038729");
        sqlUpdate("drop procedure if exists testBug22038729p");
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Field(java.lang.reflect.Field) RowResult(com.mysql.cj.xdevapi.RowResult) Table(com.mysql.cj.xdevapi.Table) SqlResult(com.mysql.cj.xdevapi.SqlResult) Row(com.mysql.cj.xdevapi.Row) XProtocol(com.mysql.cj.protocol.x.XProtocol) SessionImpl(com.mysql.cj.xdevapi.SessionImpl) CoreSession(com.mysql.cj.CoreSession) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 37 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class TableTest method testAsyncBind.

@Test
public void testAsyncBind() throws Exception {
    try {
        sqlUpdate("drop table if exists testAsyncBind");
        sqlUpdate("create table testAsyncBind(a int,b bigint,c double,d blob)");
        CompletableFuture<SqlResult> asyncSqlRes = null;
        SqlResult sqlRes = null;
        Row r = null;
        // execute without bind()
        assertThrows(ExecutionException.class, ".*You have an error in your SQL syntax.*", () -> this.session.sql("insert into testAsyncBind values(?,?,?,?)").executeAsync().get());
        // execute with more bind()
        assertThrows(ExecutionException.class, ".*Too many arguments.*", () -> this.session.sql("insert into testAsyncBind values(?,?,?,?)").bind(1, 2, 3, 4, 5).executeAsync().get());
        // execute with less bind()
        assertThrows(ExecutionException.class, ".*You have an error in your SQL syntax.*", () -> this.session.sql("insert into testAsyncBind values(?,?,?,?)").bind(1, 2, 3).executeAsync().get());
        // Success
        asyncSqlRes = this.session.sql("insert into testAsyncBind values(?,?,?,?)").bind(10, 2).bind(3, "S").executeAsync();
        sqlRes = asyncSqlRes.get();
        asyncSqlRes = this.session.sql("select * from testAsyncBind where a=?").bind(10).executeAsync();
        sqlRes = asyncSqlRes.get();
        r = sqlRes.next();
        assertTrue(r.getBoolean(0));
        assertEquals(10, r.getInt(0));
        assertEquals(2, r.getLong(1));
        assertEquals(3.0, r.getDouble(2), 1);
        assertEquals("S", r.getString(3));
        assertFalse(sqlRes.hasNext());
        // bind in where and having
        asyncSqlRes = this.session.sql("select b+? as Temp,a as Temp1 from testAsyncBind where a=?+? having a>?").bind(100, 9, 1, 0).executeAsync();
        sqlRes = asyncSqlRes.get();
        r = sqlRes.next();
        assertTrue(r.getBoolean(0));
        assertEquals(102, r.getInt("Temp"));
        assertFalse(sqlRes.hasNext());
    } finally {
        sqlUpdate("drop table if exists testAsyncBind");
    }
}
Also used : SqlResult(com.mysql.cj.xdevapi.SqlResult) Row(com.mysql.cj.xdevapi.Row) Test(org.junit.jupiter.api.Test)

Example 38 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class InternalXBaseTestCase method assertSessionStatusNotEquals.

protected static void assertSessionStatusNotEquals(Session sess, String statusVariable, String unexpected) {
    SqlResult rs = sess.sql("SHOW SESSION STATUS LIKE '" + statusVariable + "'").execute();
    String actual = rs.fetchOne().getString(1);
    assertNotEquals(unexpected, actual);
}
Also used : SqlResult(com.mysql.cj.xdevapi.SqlResult)

Example 39 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class InternalXBaseTestCase method assertSessionStatusEquals.

protected static void assertSessionStatusEquals(Session sess, String statusVariable, String expected) {
    SqlResult rs = sess.sql("SHOW SESSION STATUS LIKE '" + statusVariable + "'").execute();
    String actual = rs.fetchOne().getString(1);
    assertEquals(expected, actual);
}
Also used : SqlResult(com.mysql.cj.xdevapi.SqlResult)

Aggregations

SqlResult (com.mysql.cj.xdevapi.SqlResult)39 Test (org.junit.jupiter.api.Test)27 Row (com.mysql.cj.xdevapi.Row)17 JsonString (com.mysql.cj.xdevapi.JsonString)11 Session (com.mysql.cj.xdevapi.Session)8 ExecutionException (java.util.concurrent.ExecutionException)7 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)6 SqlStatement (com.mysql.cj.xdevapi.SqlStatement)6 CoreSession (com.mysql.cj.CoreSession)5 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)4 StatementExecuteOkBuilder (com.mysql.cj.protocol.x.StatementExecuteOkBuilder)4 SqlResultBuilder (com.mysql.cj.xdevapi.SqlResultBuilder)4 ArrayList (java.util.ArrayList)4 CJPacketTooBigException (com.mysql.cj.exceptions.CJPacketTooBigException)3 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)3 XProtocolRowInputStream (com.mysql.cj.protocol.x.XProtocolRowInputStream)3 DbDoc (com.mysql.cj.xdevapi.DbDoc)3 DbDocImpl (com.mysql.cj.xdevapi.DbDocImpl)3 DocResult (com.mysql.cj.xdevapi.DocResult)3 SessionFactory (com.mysql.cj.xdevapi.SessionFactory)3