Skip to content

Commit 79e2f58

Browse files
committed
fixes #1159
1 parent 0ef4a5c commit 79e2f58

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Also I would like to know about needed examples or documentation stuff.
5757

5858
## Extensions in the latest SNAPSHOT version 4.1
5959

60+
* support for parser modification within **parseExpression** and **parseCondExpression**
6061
' support for table schema for foreign keys
6162
* support for Oracle hints on **insert, update and merge**
6263
* support for **merge insert where** clause

src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public static Statement parse(String sql) throws JSQLParserException {
3838
}
3939

4040
/**
41-
* Parses an sql statement while allowing via consumer to configure the used parser before.
41+
* Parses an sql statement while allowing via consumer to configure the used
42+
* parser before.
4243
*
4344
* For instance to activate SQLServer bracket quotation on could use:
4445
*
@@ -104,7 +105,15 @@ public static Expression parseExpression(String expression) throws JSQLParserExc
104105
}
105106

106107
public static Expression parseExpression(String expression, boolean allowPartialParse) throws JSQLParserException {
108+
return parseExpression(expression, allowPartialParse, p -> {
109+
});
110+
}
111+
112+
public static Expression parseExpression(String expression, boolean allowPartialParse, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
107113
CCJSqlParser parser = newParser(expression);
114+
if (consumer != null) {
115+
consumer.accept(parser);
116+
}
108117
try {
109118
Expression expr = parser.SimpleExpression();
110119
if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
@@ -119,8 +128,8 @@ public static Expression parseExpression(String expression, boolean allowPartial
119128
}
120129

121130
/**
122-
* Parse an conditional expression. This is the expression after a where clause.
123-
* Partial parsing is enabled.
131+
* Parse an conditional expression. This is the expression after a where
132+
* clause. Partial parsing is enabled.
124133
*
125134
* @param condExpr
126135
* @return the expression parsed
@@ -131,15 +140,24 @@ public static Expression parseCondExpression(String condExpr) throws JSQLParserE
131140
}
132141

133142
/**
134-
* Parse an conditional expression. This is the expression after a where clause.
143+
* Parse an conditional expression. This is the expression after a where
144+
* clause.
135145
*
136146
* @param condExpr
137147
* @param allowPartialParse false: needs the whole string to be processed.
138148
* @return the expression parsed
139149
* @see #parseCondExpression(String)
140150
*/
141151
public static Expression parseCondExpression(String condExpr, boolean allowPartialParse) throws JSQLParserException {
152+
return parseCondExpression(condExpr, allowPartialParse, p -> {
153+
});
154+
}
155+
156+
public static Expression parseCondExpression(String condExpr, boolean allowPartialParse, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
142157
CCJSqlParser parser = newParser(condExpr);
158+
if (consumer != null) {
159+
consumer.accept(parser);
160+
}
143161
try {
144162
Expression expr = parser.Expression();
145163
if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,18 @@ public void testParseExpressionIssue982() throws Exception {
216216
Expression result = CCJSqlParserUtil.parseExpression("tab.col");
217217
assertEquals("tab.col", result.toString());
218218
}
219+
220+
@Test
221+
public void testParseExpressionWithBracketsIssue1159() throws Exception {
222+
Expression result = CCJSqlParserUtil.parseExpression("[travel_data].[travel_id]", false,
223+
parser -> parser.withSquareBracketQuotation(true));
224+
assertEquals("[travel_data].[travel_id]", result.toString());
225+
}
226+
227+
@Test
228+
public void testParseExpressionWithBracketsIssue1159_2() throws Exception {
229+
Expression result = CCJSqlParserUtil.parseCondExpression("[travel_data].[travel_id]", false,
230+
parser -> parser.withSquareBracketQuotation(true));
231+
assertEquals("[travel_data].[travel_id]", result.toString());
232+
}
219233
}

0 commit comments

Comments
 (0)