Skip to content

Commit

Permalink
fix: Parse Oracle open cursor statement SQL error when parameters con…
Browse files Browse the repository at this point in the history
…tain method expr
  • Loading branch information
yisiliang authored and wenshao committed Oct 28, 2024
1 parent 0902727 commit 2cf72f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SQLOpenStatement extends SQLStatementImpl {
//cursor name
private SQLName cursorName;

private final List<SQLName> columns = new ArrayList<SQLName>();
private final List<SQLExpr> columns = new ArrayList<SQLExpr>();

private SQLExpr forExpr;

Expand Down Expand Up @@ -76,7 +76,7 @@ public void setFor(SQLExpr forExpr) {
this.forExpr = forExpr;
}

public List<SQLName> getColumns() {
public List<SQLExpr> getColumns() {
return columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5341,7 +5341,7 @@ public SQLOpenStatement parseOpen() {

if (lexer.token == Token.LPAREN) {
lexer.nextToken();
this.exprParser.names(stmt.getColumns(), stmt);
this.exprParser.exprList(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7384,7 +7384,7 @@ public boolean visit(SQLOpenStatement x) {
print0(ucase ? "OPEN " : "open ");
printExpr(x.getCursorName(), parameterized);

List<SQLName> columns = x.getColumns();
List<SQLExpr> columns = x.getColumns();
if (columns.size() > 0) {
print('(');
printAndAccept(columns, ", ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.alibaba.druid.sql.parser;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import junit.framework.TestCase;
import org.junit.Assert;

import java.util.List;

public class OracleCursorOpenTest extends TestCase {
public void test_open_cursor_with_method() {
String sql = "create or replace procedure proc_test1 (myArray in self_define_array) is \n" +
"\n" +
"CURSOR c_test (p1 varchar2) is\n" +
"select\n" +
" *\n" +
"from\n" +
" test1\n" +
"where\n" +
" id = p1;\n" +
"\n" +
"BEGIN OPEN c_test (myArray (1));\n" +
"\n" +
"END proc_test1;";
List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, DbType.oracle);
System.out.println(sqlStatements);
Assert.assertFalse(sqlStatements.isEmpty());
}
}

0 comments on commit 2cf72f6

Please sign in to comment.