Skip to content

Commit

Permalink
named exec procedure parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Feb 1, 2019
1 parent 479ee39 commit 82b287d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Also I would like to know about needed examples or documentation stuff.

## Extensions in the latest SNAPSHOT version 2.0

* support of named parameters for execute: **EXEC procedure @param = 'foo'**
* support multivalue set statement
* support of **describe**
* support of **explain**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2014 JSQLParser
* Copyright (C) 2004 - 2019 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
Expand Down
21 changes: 20 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2014 JSQLParser
* Copyright (C) 2004 - 2019 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
Expand Down Expand Up @@ -3039,10 +3039,25 @@ RowConstructor RowConstructor(): {
}
}

EqualsTo VariableExpression(): {
Expression left;
Expression right;
} {
left = UserVariable() "=" right = SimpleExpression()
{
EqualsTo equals = new EqualsTo();
equals.setLeftExpression(left);
equals.setRightExpression(right);
return equals;
}
}

Execute Execute(): {
List<String> funcName;
ExpressionList expressionList = null;
Execute execute = new Execute();
List<Expression> namedExprList;
Expression expr;
}
{
(<K_EXEC> { execute.setExecType(Execute.EXEC_TYPE.EXEC); }
Expand All @@ -3052,6 +3067,10 @@ Execute Execute(): {
funcName=RelObjectNameList() { execute.setName(funcName); }

(
LOOKAHEAD(3) ( expr = VariableExpression() { namedExprList = new ArrayList<Expression>(); namedExprList.add( expr ); }
( "," expr = VariableExpression() { namedExprList.add(expr); })*
{ expressionList = new ExpressionList(namedExprList); } )
|
LOOKAHEAD(3) expressionList=SimpleExpressionList()
|
("(" expressionList=SimpleExpressionList() ")" { execute.setParenthesis(true); })
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/execute/ExecuteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,24 @@ public void testCallWithMultiname() throws JSQLParserException {
public void testAcceptCallWithParenthesis() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CALL myproc ('a', 2, 'b')");
}

@Test
public void testAcceptExecNamesParameters() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("EXEC procedure @param");
}

@Test
public void testAcceptExecNamesParameters2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 1");
}

@Test
public void testAcceptExecNamesParameters3() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 'foo'");
}

@Test
public void testAcceptExecNamesParameters4() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 'foo', @param2 = 'foo2'");
}
}

0 comments on commit 82b287d

Please sign in to comment.