use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method basicSql.
@Test
public void basicSql() {
SqlStatement stmt = this.session.sql("select 1,2,3 from dual");
SqlResult res = stmt.execute();
assertTrue(res.hasData());
Row r = res.next();
assertEquals("1", r.getString(0));
assertEquals("2", r.getString(1));
assertEquals("3", r.getString(2));
assertEquals("1", r.getString("1"));
assertEquals("2", r.getString("2"));
assertEquals("3", r.getString("3"));
assertFalse(res.hasNext());
assertThrows(XDevAPIError.class, "Method getAutoIncrementValue\\(\\) is allowed only for insert statements.", new Callable<Void>() {
public Void call() throws Exception {
assertEquals(null, res.getAutoIncrementValue());
return null;
}
});
}
use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method sqlInsertAutoIncrementValue.
@Test
public void sqlInsertAutoIncrementValue() {
try {
sqlUpdate("drop table if exists lastInsertId");
sqlUpdate("create table lastInsertId (id int not null primary key auto_increment, name varchar(20) not null)");
SqlStatement stmt = this.session.sql("insert into lastInsertId values (null, 'a')");
SqlResult res = stmt.execute();
assertFalse(res.hasData());
assertEquals(1, res.getAffectedItemsCount());
assertEquals(0, res.getWarningsCount());
assertFalse(res.getWarnings().hasNext());
assertEquals(new Long(1), res.getAutoIncrementValue());
} finally {
sqlUpdate("drop table if exists lastInsertId");
}
}
Aggregations