Search in sources :

Example 51 with Literal

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'})}");
}
Also used : Function(org.teiid.language.Function) Literal(org.teiid.language.Literal)

Example 52 with Literal

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");
}
Also used : Literal(org.teiid.language.Literal)

Example 53 with Literal

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");
}
Also used : Literal(org.teiid.language.Literal)

Example 54 with Literal

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");
}
Also used : Literal(org.teiid.language.Literal)

Example 55 with Literal

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));
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Insert(org.teiid.language.Insert) ResultSetMetaData(java.sql.ResultSetMetaData) Literal(org.teiid.language.Literal) ResultSet(java.sql.ResultSet) ExpressionValueSource(org.teiid.language.ExpressionValueSource) Test(org.junit.Test)

Aggregations

Literal (org.teiid.language.Literal)82 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 Expression (org.teiid.language.Expression)17 TranslatorException (org.teiid.translator.TranslatorException)16 Function (org.teiid.language.Function)15 Argument (org.teiid.language.Argument)12 ColumnReference (org.teiid.language.ColumnReference)10 Column (org.teiid.metadata.Column)10 Comparison (org.teiid.language.Comparison)9 ExpressionValueSource (org.teiid.language.ExpressionValueSource)7 List (java.util.List)5 Call (org.teiid.language.Call)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 Timestamp (java.sql.Timestamp)3 Array (org.teiid.language.Array)3 Command (org.teiid.language.Command)3 Insert (org.teiid.language.Insert)3