Skip to content

Commit

Permalink
simple execute clause support
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Aug 14, 2014
1 parent d6f0101 commit 531d617
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Also I would like to know about needed examples or documentation stuff.

## Extensions in the latest SNAPSHOT version 0.9.1

* Simple suppor for EXECUTE.

```sql
EXECUTE myproc 'a', 2, 'b'
```

* Improved support for select into clause.

```sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.statement.select.PlainSelect;

/**
*
Expand Down Expand Up @@ -54,5 +55,10 @@ public void setExprList(ExpressionList exprList) {
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}


@Override
public String toString() {
return "EXECUTE " + name + " " + PlainSelect.getStringList(exprList.getExpressions(), true, false);
}

}
64 changes: 64 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/deparser/ExecuteDeParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.util.deparser;

import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.statement.execute.Execute;
import net.sf.jsqlparser.statement.select.PlainSelect;

public class ExecuteDeParser {

private StringBuilder buffer;
private ExpressionVisitor expressionVisitor;

/**
* @param expressionVisitor a {@link ExpressionVisitor} to de-parse
* expressions. It has to share the same<br>
* StringBuilder (buffer parameter) as this object in order to work
* @param buffer the buffer that will be filled with the select
*/
public ExecuteDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) {
this.buffer = buffer;
this.expressionVisitor = expressionVisitor;
}

public StringBuilder getBuffer() {
return buffer;
}

public void setBuffer(StringBuilder buffer) {
this.buffer = buffer;
}

public void deParse(Execute execute) {
buffer.append("EXECUTE ").append(execute.getName());
buffer.append(" ").append(PlainSelect.getStringList(execute.getExprList().getExpressions(), true, false));
}

public ExpressionVisitor getExpressionVisitor() {
return expressionVisitor;
}

public void setExpressionVisitor(ExpressionVisitor visitor) {
expressionVisitor = visitor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public void visit(Statements stmts) {

@Override
public void visit(Execute execute) {

SelectDeParser selectDeParser = new SelectDeParser();
selectDeParser.setBuffer(buffer);
ExpressionDeParser expressionDeParser = new ExpressionDeParser(selectDeParser, buffer);
ExecuteDeParser executeDeParser = new ExecuteDeParser(expressionDeParser, buffer);
selectDeParser.setExpressionVisitor(expressionDeParser);
executeDeParser.deParse(execute);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public void tearDown() {

/**
* Test of accept method, of class Execute.
* @throws net.sf.jsqlparser.JSQLParserException
*/
@Test
public void testAccept() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("EXEC myproc 'a', 2, 'b'");
assertSqlCanBeParsedAndDeparsed("EXECUTE myproc 'a', 2, 'b'");
}
}

0 comments on commit 531d617

Please sign in to comment.