Search in sources :

Example 1 with CreateProcedureCommand

use of org.teiid.query.sql.proc.CreateProcedureCommand in project teiid by teiid.

the class TestSQLStringVisitor method testCreateUpdateProcedure1.

@Test
public void testCreateUpdateProcedure1() {
    Delete d1 = new Delete();
    // $NON-NLS-1$
    d1.setGroup(new GroupSymbol("g"));
    CommandStatement cmdStmt = new CommandStatement(d1);
    // $NON-NLS-1$
    AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1)));
    // $NON-NLS-1$
    RaiseStatement errStmt = new RaiseStatement(new Constant("My Error"));
    Block b = new Block();
    b.addStatement(cmdStmt);
    b.addStatement(assigStmt);
    b.addStatement(errStmt);
    CreateProcedureCommand cup = new CreateProcedureCommand(b);
    // $NON-NLS-1$
    helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND");
}
Also used : CommandStatement(org.teiid.query.sql.proc.CommandStatement) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement) Block(org.teiid.query.sql.proc.Block) RaiseStatement(org.teiid.query.sql.proc.RaiseStatement) Test(org.junit.Test)

Example 2 with CreateProcedureCommand

use of org.teiid.query.sql.proc.CreateProcedureCommand in project teiid by teiid.

the class TestSQLStringVisitor method testCreateUpdateProcedure3.

@Test
public void testCreateUpdateProcedure3() {
    Delete d1 = new Delete();
    // $NON-NLS-1$
    d1.setGroup(new GroupSymbol("g"));
    CommandStatement cmdStmt = new CommandStatement(d1);
    // $NON-NLS-1$
    AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1)));
    // $NON-NLS-1$
    RaiseStatement errStmt = new RaiseStatement(new Constant("My Error"));
    Block b = new Block();
    b.addStatement(cmdStmt);
    b.addStatement(assigStmt);
    b.addStatement(errStmt);
    CreateProcedureCommand cup = new CreateProcedureCommand(b);
    // $NON-NLS-1$
    helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND");
}
Also used : CommandStatement(org.teiid.query.sql.proc.CommandStatement) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement) Block(org.teiid.query.sql.proc.Block) RaiseStatement(org.teiid.query.sql.proc.RaiseStatement) Test(org.junit.Test)

Example 3 with CreateProcedureCommand

use of org.teiid.query.sql.proc.CreateProcedureCommand in project teiid by teiid.

the class TestResolver method helpResolveUpdateProcedure.

CreateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr) throws QueryParserException, QueryResolverException, TeiidComponentException, QueryMetadataException {
    QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(TriggerEvent.UPDATE, procedure);
    ProcedureContainer userCommand = (ProcedureContainer) QueryParser.getQueryParser().parseCommand(userUpdateStr);
    QueryResolver.resolveCommand(userCommand, metadata);
    return (CreateProcedureCommand) QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord());
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface)

Example 4 with CreateProcedureCommand

use of org.teiid.query.sql.proc.CreateProcedureCommand in project teiid by teiid.

the class TestProcedureResolving method testDefect23257.

/**
 *  Constants will now auto resolve if they are consistently representable in the target type
 */
@Test
public void testDefect23257() throws Exception {
    // $NON-NLS-1$
    CreateProcedureCommand command = (CreateProcedureCommand) helpResolve("EXEC pm6.vsp59()", RealMetadataFactory.example1Cached());
    CommandStatement cs = (CommandStatement) command.getBlock().getStatements().get(1);
    Insert insert = (Insert) cs.getCommand();
    assertEquals(DataTypeManager.DefaultDataClasses.SHORT, ((Expression) insert.getValues().get(1)).getType());
}
Also used : CommandStatement(org.teiid.query.sql.proc.CommandStatement) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Insert(org.teiid.query.sql.lang.Insert) Test(org.junit.Test)

Example 5 with CreateProcedureCommand

use of org.teiid.query.sql.proc.CreateProcedureCommand in project teiid by teiid.

the class TestProcedureResolving method testAnonBlock.

@Test
public void testAnonBlock() throws Exception {
    // $NON-NLS-1$
    String sql = "begin select 1 as something; end";
    CreateProcedureCommand sp = (CreateProcedureCommand) TestResolver.helpResolve(sql, RealMetadataFactory.example1Cached());
    assertEquals(1, sp.getResultSetColumns().size());
    assertEquals("something", Symbol.getName(sp.getResultSetColumns().get(0)));
    assertEquals(1, sp.getProjectedSymbols().size());
    assertTrue(sp.returnsResultSet());
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Test(org.junit.Test)

Aggregations

CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)17 Test (org.junit.Test)8 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)3 ProcedurePlan (org.teiid.query.processor.proc.ProcedurePlan)3 Insert (org.teiid.query.sql.lang.Insert)3 Block (org.teiid.query.sql.proc.Block)3 CommandStatement (org.teiid.query.sql.proc.CommandStatement)3 TriggerAction (org.teiid.query.sql.proc.TriggerAction)3 Expression (org.teiid.query.sql.symbol.Expression)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 Column (org.teiid.metadata.Column)2 Procedure (org.teiid.metadata.Procedure)2