Search in sources :

Example 16 with CreateProcedureCommand

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

the class TestProcedureResolving method testReturnAndResultSet.

@Test
public void testReturnAndResultSet() throws Exception {
    // $NON-NLS-1$
    String ddl = "CREATE FOREIGN PROCEDURE proc (OUT param STRING RESULT) RETURNS TABLE (a INTEGER, b STRING);";
    TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "y");
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve("exec proc()", tm);
    assertEquals(2, sp.getProjectedSymbols().size());
    assertEquals("y.proc.b", sp.getProjectedSymbols().get(1).toString());
    assertTrue(sp.returnsResultSet());
    sp.setCallableStatement(true);
    assertEquals(3, sp.getProjectedSymbols().size());
    assertEquals("y.proc.param", sp.getProjectedSymbols().get(2).toString());
    CreateProcedureCommand cpc = (CreateProcedureCommand) TestResolver.helpResolve("begin exec proc(); end", tm);
    assertEquals(2, cpc.getProjectedSymbols().size());
    assertEquals(2, ((CommandStatement) cpc.getBlock().getStatements().get(0)).getCommand().getProjectedSymbols().size());
    assertTrue(cpc.returnsResultSet());
    TestValidator.helpValidate("begin declare string var; var = exec proc(); select var; end", new String[] { "SELECT var;" }, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Test(org.junit.Test)

Example 17 with CreateProcedureCommand

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

the class TestSQLStringVisitor method testCreateUpdateProcedure2.

@Test
public void testCreateUpdateProcedure2() {
    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)

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