use of org.teiid.language.Literal in project teiid by teiid.
the class TestEscapeSyntaxModifier method testTimestampAdd.
public void testTimestampAdd() {
Literal arg1 = CommandBuilder.getLanuageFactory().createLiteral(NonReserved.SQL_TSI_HOUR, String.class);
Literal arg2 = CommandBuilder.getLanuageFactory().createLiteral(Integer.valueOf(1), Integer.class);
Literal arg3 = CommandBuilder.getLanuageFactory().createLiteral(TimestampUtil.createTimestamp(0, 0, 0, 0, 0, 0, 0), Timestamp.class);
// $NON-NLS-1$
Function func = CommandBuilder.getLanuageFactory().createFunction("timestampadd", Arrays.asList(arg1, arg2, arg3), Timestamp.class);
helpTest(func, "{fn timestampadd(SQL_TSI_HOUR, 1, {ts '1899-12-31 00:00:00.0'})}");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestExtractFunctionModifier method test5.
public void test5() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(arg1, "EXTRACT(DAY FROM {d '2004-01-21'})", "dayofmonth");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestExtractFunctionModifier method test4.
public void test4() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(arg1, "EXTRACT(YEAR FROM {ts '2004-01-21 17:05:00.0'})", "year");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestExtractFunctionModifier method test6.
public void test6() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(104, 0, 21, 17, 5, 0, 0), Timestamp.class);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(arg1, "EXTRACT(DAY FROM {ts '2004-01-21 17:05:00.0'})", "dayofmonth");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestJDBCUpdateExecution method testAutoGeneretionKeysPrepared.
@Test
public void testAutoGeneretionKeysPrepared() throws Exception {
// $NON-NLS-1$
Insert command = (Insert) TranslationHelper.helpTranslate("create foreign table SmallA (IntKey integer primary key, IntNum integer)", "insert into SmallA (IntKey, IntNum) values (1, 2)");
((Literal) ((ExpressionValueSource) command.getValueSource()).getValues().get(0)).setBindEligible(true);
Connection connection = Mockito.mock(Connection.class);
PreparedStatement s = Mockito.mock(PreparedStatement.class);
Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey, IntNum) VALUES (?, 2)", new String[] { "IntKey" })).toReturn(s);
JDBCExecutionFactory config = new JDBCExecutionFactory() {
@Override
public boolean supportsGeneratedKeys() {
return true;
}
@Override
public boolean useColumnNamesForGeneratedKeys() {
return true;
}
};
ResultSet r = Mockito.mock(ResultSet.class);
Mockito.stub(r.next()).toReturn(true).toReturn(false);
ResultSetMetaData rs = Mockito.mock(ResultSetMetaData.class);
Mockito.stub(r.getMetaData()).toReturn(rs);
Mockito.stub(s.getGeneratedKeys()).toReturn(r);
FakeExecutionContextImpl context = new FakeExecutionContextImpl();
((org.teiid.query.util.CommandContext) context.getCommandContext()).setReturnAutoGeneratedKeys(Collections.EMPTY_LIST);
JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, context, config);
updateExecution.execute();
Mockito.verify(s, Mockito.times(1)).getGeneratedKeys();
Mockito.verify(s, Mockito.times(1)).executeUpdate();
config = new JDBCExecutionFactory() {
@Override
public boolean supportsGeneratedKeys() {
return true;
}
};
assertEquals(0, context.getCommandContext().getGeneratedKeys().getKeyIterator().next().get(0));
}
Aggregations