use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testSelect.
@Test
public void testSelect() throws SQLException {
String[] queries = new String[] { "SELECT * FROM FOO", "/* SELECT STATEMENT FOR TABLE FOO*/\nSELECT * FROM FOO", "--SINGLE LINE COMMENT \nSELECT * FROM FOO" };
for (String sql : queries) {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
boolean isResultSet = statement.execute(sql);
Assert.assertTrue(isResultSet);
ResultSet rs = statement.getResultSet();
Assert.assertNotNull(rs);
boolean moreResults = statement.getMoreResults();
Assert.assertFalse(moreResults);
Assert.assertTrue(rs.isClosed());
Assert.assertEquals(-1, statement.getUpdateCount());
ResultSet rs2 = statement.executeQuery(sql);
Assert.assertNotNull(rs2);
Assert.assertFalse(statement.getMoreResults(Statement.KEEP_CURRENT_RESULT));
Assert.assertFalse(rs2.isClosed());
}
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testBatch.
private void testBatch(String sql, BatchMode expectedMode) throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
assertEquals(BatchMode.NONE, statement.getCurrentBatchMode());
assertEquals(0, statement.getBatch().size());
statement.addBatch(sql);
assertEquals(expectedMode, statement.getCurrentBatchMode());
assertEquals(1, statement.getBatch().size());
int[] res = statement.executeBatch();
assertEquals(1, res.length);
assertEquals(0, statement.getBatch().size());
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testBatchDDLThenDML.
@Test
public void testBatchDDLThenDML() throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
thrown.expect(SQLFeatureNotSupportedException.class);
thrown.expectMessage("DML statements may not be batched together with DDL statements");
statement.addBatch(BATCH_DDL);
statement.addBatch(BATCH_DML);
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method createConnection.
private CloudSpannerConnection createConnection() throws SQLException {
CloudSpannerConnection connection = CloudSpannerTestObjects.createConnection();
Mockito.when(connection.createStatement()).thenCallRealMethod();
Mockito.when(connection.prepareStatement(Mockito.anyString())).thenCallRealMethod();
return connection;
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testGetTokens.
@Test
public void testGetTokens() throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens(" CREATE TABLE FOO (ID INT64)"));
Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens("CREATE TABLE FOO (ID INT64)"));
Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens("\t\nCREATE TABLE\n\tFOO (ID INT64) "));
Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true" }, statement.getTokens("SET_CONNECTION_PROPERTY AsyncDdlOperations=true"));
Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true" }, statement.getTokens("\t\tSET_CONNECTION_PROPERTY AsyncDdlOperations\t=\ttrue"));
Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true", "AND AllowExtendedMode=true" }, statement.getTokens("SET_CONNECTION_PROPERTY AsyncDdlOperations=true AND AllowExtendedMode=true"));
}
Aggregations