use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SecureSessionTest method assertTlsVersion.
private void assertTlsVersion(Session sess, String expectedTlsVersion) {
SqlResult rs = sess.sql("SHOW SESSION STATUS LIKE 'mysqlx_ssl_version'").execute();
String actual = rs.fetchOne().getString(1);
assertEquals(expectedTlsVersion, actual);
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SecureSessionTest method getHighestCommonTlsVersion.
private String getHighestCommonTlsVersion(Session sess) throws Exception {
// Find out which TLS protocol versions are supported by this JVM.
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
List<String> jvmSupportedProtocols = Arrays.asList(sslContext.createSSLEngine().getSupportedProtocols());
SqlResult rset = sess.sql("SHOW GLOBAL VARIABLES LIKE 'tls_version'").execute();
String value = rset.fetchOne().getString(1);
// this.rs = sslConn.createStatement().executeQuery("SHOW GLOBAL VARIABLES LIKE 'tls_version'");
// assertTrue(this.rs.next());
List<String> serverSupportedProtocols = Arrays.asList(value.trim().split("\\s*,\\s*"));
String highestCommonTlsVersion = "";
for (String p : new String[] { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" }) {
if (jvmSupportedProtocols.contains(p) && serverSupportedProtocols.contains(p)) {
highestCommonTlsVersion = p;
break;
}
}
System.out.println("Server supports TLS protocols: " + serverSupportedProtocols);
System.out.println("Highest common TLS protocol: " + highestCommonTlsVersion);
return highestCommonTlsVersion;
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SecureSessionTest method assertUser.
private void assertUser(String user, Session sess) {
SqlResult rows = sess.sql("SELECT USER(),CURRENT_USER()").execute();
Row row = rows.fetchOne();
assertEquals(user, row.getString(0).split("@")[0]);
assertEquals(user, row.getString(1).split("@")[0]);
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SessionTest method testFetchOneFetchAllAsync.
@Test
public void testFetchOneFetchAllAsync() throws Exception {
Row r = null;
List<Row> rowList = null;
try {
CompletableFuture<SqlResult> asyncSqlRes = this.session.sql("drop table if exists testFetchOneFetchAllAsync").executeAsync();
SqlResult sqlRes = asyncSqlRes.get();
asyncSqlRes = this.session.sql("create table testFetchOneFetchAllAsync(a int,b bigint,c double,d blob)").executeAsync();
sqlRes = asyncSqlRes.get();
asyncSqlRes = this.session.sql("insert into testFetchOneFetchAllAsync values(?,?,?,?)").bind(1, 11).bind(21, "A").executeAsync();
sqlRes = asyncSqlRes.get();
asyncSqlRes = this.session.sql("insert into testFetchOneFetchAllAsync values(?,?,?,?)").bind(2, 12).bind(22, "B").executeAsync();
sqlRes = asyncSqlRes.get();
asyncSqlRes = this.session.sql("insert into testFetchOneFetchAllAsync values(?,?,?,?)").bind(3, 13).bind(23, "C").executeAsync();
sqlRes = asyncSqlRes.get();
asyncSqlRes = this.session.sql("insert into testFetchOneFetchAllAsync values(?,?,?,?)").bind(4, 14).bind(23, "D").executeAsync();
sqlRes = asyncSqlRes.get();
// With FetchOne()
asyncSqlRes = this.session.sql("select * from testFetchOneFetchAllAsync where a<=? order by a asc").bind(5).executeAsync();
SqlResult sqlRes1 = asyncSqlRes.get();
int i = 0;
while (sqlRes1.hasNext()) {
r = sqlRes1.fetchOne();
assertEquals((long) (i + 1), r.getInt(0));
i++;
}
assertThrows(WrongArgumentException.class, "Cannot fetchAll\\(\\) after starting iteration", () -> sqlRes1.fetchAll());
asyncSqlRes = this.session.sql("select * from testFetchOneFetchAllAsync where a<=? order by a asc").bind(3).executeAsync();
sqlRes = asyncSqlRes.get();
rowList = sqlRes.fetchAll();
assertEquals((long) 3, (long) rowList.size());
for (i = 0; i < rowList.size(); i++) {
r = rowList.get(i);
assertEquals((long) (i + 1), r.getInt(0));
i++;
}
} finally {
sqlUpdate("drop table if exists testFetchOneFetchAllAsync");
}
}
use of com.mysql.cj.xdevapi.SqlResult 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"));
}
Aggregations