Search in sources :

Example 1 with SqlMultiResult

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

the class SessionTest method testBug23721537.

@Test
public void testBug23721537() throws Exception {
    try {
        sqlUpdate("drop table if exists testBug23721537");
        sqlUpdate("create table testBug23721537 (id int, name varchar(20) not null)");
        sqlUpdate("insert into testBug23721537 values (0, 'a')");
        this.session.sql("drop procedure if exists newproc").execute();
        this.session.sql("create procedure newproc (in p1 int,in p2 char(20)) begin select 1; update testBug23721537 set name='b' where id=0; select 2; select 3; end;").execute();
        /* sync execution */
        SqlResult res1 = this.session.sql("call newproc(?,?)").bind(10).bind("X").execute();
        assertTrue(res1 instanceof SqlMultiResult);
        assertTrue(res1.hasData());
        assertTrue(res1.hasNext());
        Row r = res1.next();
        assertEquals(1, r.getInt(0));
        assertFalse(res1.hasNext());
        // res1 should finish streaming here
        SqlResult res2 = this.session.sql("select 10").execute();
        assertTrue(res1.nextResult());
        assertTrue(res1.hasData());
        assertTrue(res1.hasNext());
        r = res1.next();
        assertEquals(2, r.getInt(0));
        assertFalse(res1.hasNext());
        assertTrue(res1.nextResult());
        assertTrue(res1.hasData());
        assertTrue(res1.hasNext());
        r = res1.next();
        assertEquals(3, r.getInt(0));
        assertFalse(res1.hasNext());
        assertFalse(res1.nextResult());
        // 
        assertTrue(res2.hasData());
        assertTrue(res2.hasNext());
        r = res2.next();
        assertEquals(10, r.getInt(0));
        assertFalse(res2.hasNext());
        assertFalse(res2.nextResult());
        /* async execution */
        res1 = this.session.sql("call newproc(?,?)").bind(10).bind("X").executeAsync().get();
        assertTrue(res1.hasData());
        r = res1.next();
        assertEquals(1, r.getInt(0));
        assertFalse(res1.hasNext());
        // res1 should finish streaming here
        res2 = this.session.sql("select 10").executeAsync().get();
        assertTrue(res1.nextResult());
        assertTrue(res1.hasData());
        assertTrue(res1.hasNext());
        r = res1.next();
        assertEquals(2, r.getInt(0));
        assertFalse(res1.hasNext());
        assertTrue(res1.nextResult());
        assertTrue(res1.hasData());
        assertTrue(res1.hasNext());
        r = res1.next();
        assertEquals(3, r.getInt(0));
        assertFalse(res1.hasNext());
        assertFalse(res1.nextResult());
        // 
        assertTrue(res2.hasData());
        assertTrue(res2.hasNext());
        r = res2.next();
        assertEquals(10, r.getInt(0));
        assertFalse(res2.hasNext());
        assertFalse(res2.nextResult());
    } finally {
        sqlUpdate("drop table if exists testBug23721537");
        this.session.sql("drop procedure if exists newproc").execute();
    }
}
Also used : SqlResult(com.mysql.cj.xdevapi.SqlResult) SqlMultiResult(com.mysql.cj.xdevapi.SqlMultiResult) Row(com.mysql.cj.xdevapi.Row) Test(org.junit.jupiter.api.Test)

Aggregations

Row (com.mysql.cj.xdevapi.Row)1 SqlMultiResult (com.mysql.cj.xdevapi.SqlMultiResult)1 SqlResult (com.mysql.cj.xdevapi.SqlResult)1 Test (org.junit.jupiter.api.Test)1