/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { CommandStatement cs = new CommandStatement((Command)this.command.clone()); cs.returnable = this.returnable; return cs; }
/** * rewrite as loop on (query) as X begin newupdate; rows_updated = rows_updated + 1 end; * @param updateType */ private Command asLoopProcedure(GroupSymbol group, QueryCommand query, ProcedureContainer newUpdate, GroupSymbol varGroup, int updateType) throws QueryResolverException, TeiidComponentException, TeiidProcessingException { return asLoopProcedure(group, query, new CommandStatement(newUpdate), varGroup, updateType); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { CommandStatement cs = new CommandStatement((Command)this.command.clone()); cs.returnable = this.returnable; return cs; }
/** * rewrite as loop on (query) as X begin newupdate; rows_updated = rows_updated + 1 end; * @param updateType */ private Command asLoopProcedure(GroupSymbol group, QueryCommand query, ProcedureContainer newUpdate, GroupSymbol varGroup, int updateType) throws QueryResolverException, TeiidComponentException, TeiidProcessingException { return asLoopProcedure(group, query, new CommandStatement(newUpdate), varGroup, updateType); }
/** * rewrite as loop on (query) as X begin newupdate; rows_updated = rows_updated + 1 end; * @param updateType */ private Command asLoopProcedure(GroupSymbol group, QueryCommand query, ProcedureContainer newUpdate, GroupSymbol varGroup, int updateType) throws QueryResolverException, TeiidComponentException, TeiidProcessingException { return asLoopProcedure(group, query, new CommandStatement(newUpdate), varGroup, updateType); }
/** * Deep clone statement to produce a new identical statement. * @return Deep clone */ public Object clone() { CommandStatement cs = new CommandStatement((Command)this.command.clone()); cs.returnable = this.returnable; return cs; }
public static final CommandStatement sample2() { QueryParser parser = new QueryParser(); try { Update update = (Update) parser.parseCommand("UPDATE x SET x = 'y'"); //$NON-NLS-1$ return new CommandStatement(update); } catch(Exception e) { return null;} }
public static final CommandStatement sample1() { QueryParser parser = new QueryParser(); try { Query query = (Query) parser.parseCommand("Select x from y"); //$NON-NLS-1$ return new CommandStatement(query); } catch(Exception e) { return null;} }
@Test public void testCommandStatement() throws Exception { Query query = sampleQuery(); Command sqlCmd = query; CommandStatement cmdStmt = new CommandStatement(sqlCmd); helpStmtTest("SELECT a1 FROM g WHERE a2 = 5;", "SELECT a1 FROM g WHERE a2 = 5;", //$NON-NLS-1$ //$NON-NLS-2$ cmdStmt); }
public void addStatement(Statement statement, boolean exception) { if (statement instanceof AssignmentStatement) { AssignmentStatement stmt = (AssignmentStatement)statement; Command cmd = stmt.getCommand(); if (cmd != null) { internalAddStatement(new CommandStatement(cmd), exception); stmt.setCommand(null); stmt.setExpression(null); if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) { return; } String fullName = ProcedureReservedWords.VARIABLES+Symbol.SEPARATOR+ProcedureReservedWords.ROWCOUNT; stmt.setExpression(new ElementSymbol(fullName)); } } internalAddStatement(statement, exception); }
@Test public void testCommandStatement2() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); helpTest(cmdStmt, "DELETE FROM g;"); //$NON-NLS-1$ }
@Test public void testDynamicCommandStatement() throws Exception { List<ElementSymbol> symbols = new ArrayList<ElementSymbol>(); ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$ a1.setType(DataTypeManager.DefaultDataClasses.STRING); symbols.add(a1); DynamicCommand sqlCmd = new DynamicCommand(); Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5"); //$NON-NLS-1$ sqlCmd.setSql(sql); sqlCmd.setAsColumns(symbols); sqlCmd.setAsClauseSet(true); sqlCmd.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(sqlCmd); helpStmtTest("exec string 'SELECT a1 FROM g WHERE a2 = 5' as a1 string into #g;", "EXECUTE IMMEDIATE 'SELECT a1 FROM g WHERE a2 = 5' AS a1 string INTO #g;", //$NON-NLS-1$ //$NON-NLS-2$ cmdStmt); }
@Test public void testBlock1() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); helpTest(b, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure3() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure1() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testCreateUpdateProcedure2() { Delete d1 = new Delete(); d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$ CommandStatement cmdStmt = new CommandStatement(d1); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt); CreateProcedureCommand cup = new CreateProcedureCommand(b); helpTest(cup, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$ }
@Test public void testDynamicCommandStatementWithUsing() throws Exception { SetClauseList using = new SetClauseList(); ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ using.addClause(a, new ElementSymbol("b")); //$NON-NLS-1$ DynamicCommand sqlCmd = new DynamicCommand(); Expression sql = new ElementSymbol("z"); //$NON-NLS-1$ sqlCmd.setSql(sql); sqlCmd.setUsing(using); CommandStatement cmdStmt = new CommandStatement(sqlCmd); helpStmtTest("execute immediate z using a=b;", "EXECUTE IMMEDIATE z USING a = b;", //$NON-NLS-1$ //$NON-NLS-2$ cmdStmt); }
@Test public void testBlockExceptionHandling() throws ParseException { CommandStatement cmdStmt = new CommandStatement(new Query(new Select(Arrays.asList(new MultipleElementSymbol())), new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("x")))), null, null, null)); AssignmentStatement assigStmt = new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$ RaiseStatement errStmt = new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$ Block b = new Block(); b.setExceptionGroup("e"); b.addStatement(cmdStmt); b.addStatement(assigStmt); b.addStatement(errStmt, true); helpStmtTest("BEGIN\nselect * from x;\na = 1;\nexception e\nERROR 'My Error';\nEND", "BEGIN\nSELECT * FROM x;\na = 1;\nEXCEPTION e\nRAISE SQLEXCEPTION 'My Error';\nEND", b); //$NON-NLS-1$ }
@Test public void testCommandStatement1() { Query q1 = new Query(); Select select = new Select(); select.addSymbol(new ElementSymbol("x")); //$NON-NLS-1$ q1.setSelect(select); From from = new From(); from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$ q1.setFrom(from); CommandStatement cmdStmt = new CommandStatement(q1); helpTest(cmdStmt, "SELECT x FROM g;"); //$NON-NLS-1$ }
@Test public void testCommandStatement1a() { Query q1 = new Query(); Select select = new Select(); select.addSymbol(new ElementSymbol("x")); //$NON-NLS-1$ q1.setSelect(select); From from = new From(); from.addGroup(new GroupSymbol("g")); //$NON-NLS-1$ q1.setFrom(from); CommandStatement cmdStmt = new CommandStatement(q1); cmdStmt.setReturnable(false); helpTest(cmdStmt, "SELECT x FROM g WITHOUT RETURN;"); //$NON-NLS-1$ }