Search in sources :

Example 6 with AssignmentStatement

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

the class TestAssignmentStatement method testEquivalence.

public void testEquivalence() {
    AssignmentStatement s1 = sample1();
    AssignmentStatement s1a = sample1();
    int equals = 0;
    UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
}
Also used : AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement)

Example 7 with AssignmentStatement

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

the class TestProcedureResolving method testProcedureScoping.

@Test
public void testProcedureScoping() throws Exception {
    StringBuffer proc = // $NON-NLS-1$
    new StringBuffer("FOR EACH ROW").append(// $NON-NLS-1$
    "\nBEGIN").append(// $NON-NLS-1$
    "\n  declare integer e1 = 1;").append(// $NON-NLS-1$
    "\n  e1 = e1;").append(// $NON-NLS-1$
    "\n  LOOP ON (SELECT pm1.g1.e1 FROM pm1.g1) AS loopCursor").append(// $NON-NLS-1$
    "\n  BEGIN").append(// $NON-NLS-1$
    "\n    variables.e1 = convert(e1, integer);").append(// $NON-NLS-1$
    "\n  END").append(// $NON-NLS-1$
    "\nEND");
    // $NON-NLS-1$
    String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
    TriggerAction command = helpResolveUpdateProcedure(proc.toString(), userUpdateStr, Table.TriggerEvent.UPDATE);
    Block block = command.getBlock();
    AssignmentStatement assStmt = (AssignmentStatement) block.getStatements().get(1);
    assertEquals(ProcedureReservedWords.VARIABLES, assStmt.getVariable().getGroupSymbol().getName());
    assertEquals(ProcedureReservedWords.VARIABLES, ((ElementSymbol) assStmt.getExpression()).getGroupSymbol().getName());
    Block inner = ((LoopStatement) block.getStatements().get(2)).getBlock();
    assStmt = (AssignmentStatement) inner.getStatements().get(0);
    ElementSymbol value = ElementCollectorVisitor.getElements(assStmt.getExpression(), false).iterator().next();
    // $NON-NLS-1$
    assertEquals("loopCursor", value.getGroupSymbol().getName());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TriggerAction(org.teiid.query.sql.proc.TriggerAction) AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement) Block(org.teiid.query.sql.proc.Block) LoopStatement(org.teiid.query.sql.proc.LoopStatement) Test(org.junit.Test)

Example 8 with AssignmentStatement

use of org.teiid.query.sql.proc.AssignmentStatement 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)

Example 9 with AssignmentStatement

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

the class TestSQLStringVisitor method testAssignmentStatement1.

@Test
public void testAssignmentStatement1() {
    // $NON-NLS-1$
    AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1)));
    // $NON-NLS-1$
    helpTest(assigStmt, "a = 1;");
}
Also used : AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement) Test(org.junit.Test)

Example 10 with AssignmentStatement

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

the class TestSQLStringVisitor method testAssignmentStatement2.

@Test
public void testAssignmentStatement2() {
    Query q1 = new Query();
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("x"));
    q1.setSelect(select);
    From from = new From();
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("g"));
    q1.setFrom(from);
    // $NON-NLS-1$
    AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), q1);
    // $NON-NLS-1$
    helpTest(assigStmt, "a = (SELECT x FROM g);");
}
Also used : AssignmentStatement(org.teiid.query.sql.proc.AssignmentStatement) Test(org.junit.Test)

Aggregations

AssignmentStatement (org.teiid.query.sql.proc.AssignmentStatement)14 Test (org.junit.Test)7 Block (org.teiid.query.sql.proc.Block)5 CommandStatement (org.teiid.query.sql.proc.CommandStatement)4 RaiseStatement (org.teiid.query.sql.proc.RaiseStatement)4 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Query (org.teiid.query.sql.lang.Query)2 From (org.teiid.query.sql.lang.From)1 Select (org.teiid.query.sql.lang.Select)1 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)1 LoopStatement (org.teiid.query.sql.proc.LoopStatement)1 TriggerAction (org.teiid.query.sql.proc.TriggerAction)1 Constant (org.teiid.query.sql.symbol.Constant)1 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)1