use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerParameterMetaDataTest method createStatement.
private CloudSpannerPreparedStatement createStatement(String sql) throws SQLException {
CloudSpannerConnection connection = mock(CloudSpannerConnection.class);
CloudSpannerDatabaseMetaData metadata = mock(CloudSpannerDatabaseMetaData.class);
CloudSpannerResultSet columns = mock(CloudSpannerResultSet.class);
TableKeyMetaData table = mock(TableKeyMetaData.class);
when(table.getKeyColumns()).thenReturn(Arrays.asList("COL1"));
when(connection.getTable("FOO")).thenReturn(table);
when(connection.getMetaData()).thenAnswer(new Returns(metadata));
when(metadata.getColumns(null, null, "FOO", null)).thenReturn(columns);
final ColumnsNextAnswer next = new ColumnsNextAnswer();
when(columns.next()).thenAnswer(next);
when(columns.getString("COLUMN_NAME")).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return Arrays.asList("COL1", "COL2", "COL3").get(next.nextCalled - 1);
}
});
when(columns.getInt("COLUMN_SIZE")).thenAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return Arrays.asList(8, 50, 100).get(next.nextCalled - 1);
}
});
when(columns.getInt("DATA_TYPE")).thenAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return Arrays.asList(Types.BIGINT, Types.NVARCHAR, Types.NVARCHAR).get(next.nextCalled - 1);
}
});
when(columns.getInt("NULLABLE")).thenAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return Arrays.asList(ParameterMetaData.parameterNoNulls, ParameterMetaData.parameterNoNulls, ParameterMetaData.parameterNullable).get(next.nextCalled - 1);
}
});
return new CloudSpannerPreparedStatement(sql, connection, null);
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testGetGeneratedKeys.
@Test
public void testGetGeneratedKeys() throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
try (ResultSet rs = statement.getGeneratedKeys()) {
assertFalse(rs.next());
}
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testInsertWithGetTimestamp.
@Test
public void testInsertWithGetTimestamp() throws SQLException {
thrown.expect(CloudSpannerSQLException.class);
thrown.expectMessage("Function calls such as for example GET_TIMESTAMP() are not allowed in client side insert/update statements");
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
String sql = "INSERT INTO providers\n" + "(provider_id, created, device_id, document_number, document_type_id, name, notification, phone, updated, last_access, deleted, token_fcm)\n" + "VALUES('000000', CURRENT_DATE(), 'not-device-id', null, null, 'provider-promocion', false, null, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), false, 'not-token')";
statement.execute(sql);
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testExecuteNormalMode.
@Test
public void testExecuteNormalMode() throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
boolean res = statement.execute("SELECT * FROM FOO");
assertTrue(res);
ResultSet rs = statement.getResultSet();
assertNotNull(rs);
assertFalse(rs.isClosed());
assertFalse(statement.getMoreResults());
assertNull(statement.getResultSet());
}
use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.
the class CloudSpannerStatementTest method testIsDDLStatement.
@Test
public void testIsDDLStatement() throws SQLException {
CloudSpannerConnection connection = createConnection();
CloudSpannerStatement statement = connection.createStatement();
Assert.assertTrue(statement.isDDLStatement(statement.getTokens("CREATE TABLE FOO (ID INT64 NOT NULL, COL1 STRING(100) NOT NULL) PRIMARY KEY (ID)")));
Assert.assertTrue(statement.isDDLStatement(statement.getTokens("ALTER TABLE FOO ADD COLUMN COL2 STRING(100) NOT NULL")));
Assert.assertTrue(statement.isDDLStatement(statement.getTokens("DROP TABLE FOO")));
Assert.assertTrue(statement.isDDLStatement(statement.getTokens("CREATE INDEX IDX_FOO ON FOO (COL1)")));
Assert.assertTrue(statement.isDDLStatement(statement.getTokens("DROP INDEX IDX_FOO")));
}
Aggregations