use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method sqlArguments.
@Test
public void sqlArguments() {
SqlStatement stmt = this.session.sql("select ? as a, 40 + ? as b, ? as c");
SqlResult res = stmt.bind(1).bind(2).bind(3).execute();
Row r = res.next();
assertEquals("1", r.getString("a"));
assertEquals("42", r.getString("b"));
assertEquals("3", r.getString("c"));
}
use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method smartBufferMultipleResults.
@Test
public void smartBufferMultipleResults() {
try {
sqlUpdate("drop procedure if exists basicMultipleResults");
sqlUpdate("create procedure basicMultipleResults() begin explain select 1; explain select 2; end");
SqlStatement stmt = this.session.sql("call basicMultipleResults()");
/* SqlResult res = */
stmt.execute();
// execute another statement, should work fine
this.session.sql("call basicMultipleResults()");
this.session.sql("call basicMultipleResults()");
this.session.sql("call basicMultipleResults()");
} finally {
sqlUpdate("drop procedure if exists basicMultipleResults");
}
}
use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method basicMultipleResults.
@Test
public void basicMultipleResults() {
try {
sqlUpdate("drop procedure if exists basicMultipleResults");
sqlUpdate("create procedure basicMultipleResults() begin explain select 1; explain select 2; end");
SqlStatement stmt = this.session.sql("call basicMultipleResults()");
SqlResult res = stmt.execute();
assertTrue(res.hasData());
/* Row r = */
res.next();
assertFalse(res.hasNext());
assertTrue(res.nextResult());
assertTrue(res.hasData());
assertFalse(res.nextResult());
assertFalse(res.nextResult());
assertFalse(res.nextResult());
} finally {
sqlUpdate("drop procedure if exists basicMultipleResults");
}
}
use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method sqlUpdate.
@Test
public void sqlUpdate() {
SqlStatement stmt = this.session.sql("set @cjTestVar = 1");
SqlResult res = stmt.execute();
assertFalse(res.hasData());
assertEquals(0, res.getAffectedItemsCount());
assertEquals(null, res.getAutoIncrementValue());
assertEquals(0, res.getWarningsCount());
assertFalse(res.getWarnings().hasNext());
// TODO SqlUpdateResult throws FeatureNotAvailableException("Not a multi-result");
// res.nextResult();
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.fetchAll();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.next();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.hasNext();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.getColumnCount();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.getColumns();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.getColumnNames();
return null;
}
});
assertThrows(FeatureNotAvailableException.class, "No data", new Callable<Void>() {
public Void call() throws Exception {
res.count();
return null;
}
});
}
use of com.mysql.cj.xdevapi.SqlStatement in project aws-mysql-jdbc by awslabs.
the class SessionTest method errorOnPacketTooBig.
/**
* Test the client-side enforcing of server `mysqlx_max_allowed_packet'.
*/
@Test
public void errorOnPacketTooBig() {
// to free the memory from previous tests artifacts
System.gc();
SqlStatement stmt = this.session.sql("select @@mysqlx_max_allowed_packet");
SqlResult res = stmt.execute();
Row r = res.next();
long mysqlxMaxAllowedPacket = r.getLong(0);
long size = 100 + mysqlxMaxAllowedPacket;
StringBuilder b = new StringBuilder();
for (int i = 0; i < size; ++i) {
b.append('a');
}
String s = b.append("\"}").toString();
assertThrows("Large packet should cause an exception", CJPacketTooBigException.class, () -> {
this.session.dropSchema(s);
return null;
});
}
Aggregations