use of org.teiid.language.Command in project teiid by teiid.
the class TestSqlServerConversionVisitor method testLocate.
@Test
public void testLocate() throws Exception {
// $NON-NLS-1$
String input = "select locate('a', stringkey, 2) from bqt1.smalla";
// $NON-NLS-1$
String output = "SELECT CHARINDEX('a', g_0.StringKey, 2) FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, trans, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testParseFormat.
@Test
public void testParseFormat() throws Exception {
// $NON-NLS-1$
String input = "select parsetimestamp(smalla.timestampvalue, 'yyyy.MM.dd'), formattimestamp(smalla.timestampvalue, 'yy.MM.dd') from bqt1.smalla";
// $NON-NLS-1$
String output = "SELECT TO_TIMESTAMP(to_char(cast(g_0.TimestampValue AS timestamp), 'YYYY-MM-DD HH24:MI:SS.FF'), 'YYYY.MM.DD'), TO_CHAR(g_0.TimestampValue, 'YY.MM.DD') FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testCharType.
@Test
public void testCharType() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("select id from smalla where description = 'a' and ndescription in ('b', 'c')");
for (Literal l : CollectorVisitor.collectObjects(Literal.class, command)) {
l.setBindEligible(true);
}
Connection connection = Mockito.mock(Connection.class);
PreparedStatement ps = Mockito.mock(PreparedStatement.class);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("SELECT SmallishA.ID FROM SmallishA WHERE SmallishA.description = ? AND SmallishA.ndescription IN (?, ?)")).toReturn(ps);
OracleExecutionFactory ef = new OracleExecutionFactory();
ef.start();
JDBCQueryExecution e = new JDBCQueryExecution(command, connection, new FakeExecutionContextImpl(), ef);
e.execute();
Mockito.verify(ps, Mockito.times(1)).setObject(1, "a", OracleExecutionFactory.FIXED_CHAR_TYPE);
Mockito.verify(ps, Mockito.times(1)).setObject(2, "b", OracleExecutionFactory.FIXED_CHAR_TYPE);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testProcedureExecution.
@Test
public void testProcedureExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call spTest8(1)");
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
ResultSet rs = Mockito.mock(ResultSet.class);
Mockito.stub(cs.getObject(1)).toReturn(rs);
Mockito.stub(cs.getInt(3)).toReturn(4);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall("{?= call spTest8(?,?)}")).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
assertEquals(Arrays.asList(4), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
Mockito.verify(cs, Mockito.times(1)).getObject(1);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method helpTestVisitor.
private void helpTestVisitor(String vdb, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws TranslatorException {
// Convert from sql to objects
TranslationUtility util = new TranslationUtility(vdb);
Command obj = util.parseCommand(input, correctNaming, true);
this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
}
Aggregations