Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
747152a
Fixes #1684: Support CREATE MATERIALIZED VIEW with AUTO REFRESH
zaza Dec 11, 2022
9e09005
Merge branch 'master' into 1684-create-mv-auto-refresh
zaza Dec 22, 2022
ea4477b
Reduce cyclomatic complexity in CreateView.toString
zaza Jan 8, 2023
b5321d6
Enhanced Keywords
manticore-projects Oct 18, 2021
5fae2f5
Fix incorrect tests
manticore-projects Oct 18, 2021
f49e828
Define Reserved Keywords explicitly
manticore-projects Oct 24, 2021
86f337d
Fix test resources
manticore-projects Oct 24, 2021
2d51a82
Adjust Gradle to JUnit 5
manticore-projects Nov 22, 2021
232aff6
Do not mark SpeedTest for concurrent execution
manticore-projects Nov 24, 2021
3ba5410
Remove unused imports
manticore-projects Nov 28, 2021
e960a35
Adjust Gradle to JUnit 5
manticore-projects Nov 22, 2021
67f7951
Do not mark SpeedTest for concurrent execution
manticore-projects Nov 24, 2021
a016be0
Remove unused imports
manticore-projects Nov 28, 2021
2ef6637
Sphinx Documentation
manticore-projects Sep 2, 2022
57193b8
doc: request for `Conventional Commit` messages
manticore-projects Sep 6, 2022
b94b2cc
feat: make important Classes Serializable
manticore-projects Sep 15, 2022
02202c5
chore: Make Serializable
manticore-projects Oct 14, 2022
a3ca325
doc: Better integration of the RR diagrams
manticore-projects Jan 7, 2023
fcb5ab1
Merge
manticore-projects Jan 7, 2023
c57c427
feat: Oracle Alternative Quoting
manticore-projects Jan 29, 2023
2aec1f6
style: Appease PMD/Codacy
manticore-projects Jan 29, 2023
1c8d8da
feat: CREATE VIEW ... REFRESH AUTO...
manticore-projects Jan 30, 2023
b707b23
doc: fix the issue template
manticore-projects Feb 1, 2023
46314c4
Update issue templates
manticore-projects Feb 1, 2023
4aeafbc
Update issue templates
manticore-projects Feb 1, 2023
b081484
feat: Support more Statement Separators
manticore-projects Feb 2, 2023
5885e1c
Merge remote-tracking branch 'origin/master'
manticore-projects Feb 13, 2023
581d97a
Merge branch 'master' of https://github.com/JSQLParser/JSqlParser
manticore-projects Feb 24, 2023
0979b2e
feat: FETCH uses EXPRESSION
manticore-projects Mar 7, 2023
ed17f87
style: apply Spotless
manticore-projects Mar 7, 2023
96808d2
test: commit missing test
manticore-projects Mar 7, 2023
21c4550
Merge branch 'master' of https://github.com/JSQLParser/JSqlParser
manticore-projects Mar 12, 2023
029588f
fix: JSon Operator can use Simple Function
manticore-projects Mar 14, 2023
4b312ff
style: Reformat changed files and headers
manticore-projects Mar 14, 2023
91c9503
style: Remove unused variable
manticore-projects Mar 14, 2023
64fe908
feat: Add support for Hangul "\uAC00"-"\uD7A3"
manticore-projects Mar 17, 2023
a6d9e40
style: expose `SetStatement` key-value list
manticore-projects Mar 17, 2023
c5ec0c5
style: Appease PMD/Codacy
manticore-projects Mar 17, 2023
8bfcde6
Merge remote-tracking branch 'manticore/JSonOperatorIssue1571' into J…
manticore-projects Mar 17, 2023
043b71a
feat: `ConflictTarget` allows multiple `IndexColumnNames`
manticore-projects Mar 18, 2023
f75df51
doc: fix reference in the Java Doc
manticore-projects Mar 18, 2023
500046f
build: better Upload Groovy Task
manticore-projects Mar 18, 2023
e460cda
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 23, 2023
ad9e98d
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 23, 2023
31935b3
Merge remote-tracking branch 'origin/master' into ParenthesedSelectBody
manticore-projects Mar 23, 2023
f0f8876
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 23, 2023
d134137
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 23, 2023
616bf23
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 24, 2023
465934c
feat: ParenthesedSelectBody and ParenthesedFromItem
manticore-projects Mar 25, 2023
9b3294c
style: Appease PMD/Codacy
manticore-projects Mar 25, 2023
e470d6e
style: Appease PMD/Codacy
manticore-projects Mar 25, 2023
9f999e3
feat: Refactor SelectBody implementations
manticore-projects Mar 26, 2023
8cddd39
feat: Refactor SelectBody implementations
manticore-projects Mar 27, 2023
d0ea5e0
style: Code cleanup
manticore-projects Mar 27, 2023
4056ca5
feat: Merge `SelectBody` into `Select` Statement
manticore-projects Mar 27, 2023
a6aab00
style: Remove unused import
manticore-projects Mar 27, 2023
a914fe0
test: @Disabled invalid Test
manticore-projects Mar 27, 2023
8b9dd3e
style: Appease PMD/Codacy
manticore-projects Mar 27, 2023
ab127d4
test: Add a SubSelect Parsing Test
manticore-projects Apr 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: ParenthesedSelectBody and ParenthesedFromItem
- extract `OrderByElements` into `SelectBody`
- one more special Oracle Test succeeds
- all tests succeed
  • Loading branch information
manticore-projects committed Mar 25, 2023
commit 465934c4eb12d8a3272e1b8f8a80d1cbe2fe78f0
9 changes: 4 additions & 5 deletions src/main/java/net/sf/jsqlparser/expression/OracleHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
public class OracleHint extends ASTNodeAccessImpl implements Expression {

private static final Pattern SINGLE_LINE = Pattern.compile("--\\+ *([^ ].*[^ ])");
private static final Pattern MULTI_LINE = Pattern.
compile("\\/\\*\\+ *([^ ].*[^ ]) *\\*+\\/", Pattern.MULTILINE | Pattern.DOTALL);
private static final Pattern MULTI_LINE =
Pattern.compile("\\/\\*\\+ *([^ ].*[^ ]) *\\*+\\/", Pattern.MULTILINE | Pattern.DOTALL);

private String value;
private boolean singleLine = false;

public static boolean isHintMatch(String comment) {
return SINGLE_LINE.matcher(comment).find()
|| MULTI_LINE.matcher(comment).find();
return SINGLE_LINE.matcher(comment).find() || MULTI_LINE.matcher(comment).find();
}

public final void setComment(String comment) {
Expand Down Expand Up @@ -94,7 +93,7 @@ public static OracleHint getHintFromSelectBody(SelectBody selectBody) {
if (selectBody instanceof PlainSelect) {
return ((PlainSelect) selectBody).getOracleHint();
} else if (selectBody instanceof ParenthesedSelectBody) {
return getHintFromSelectBody( ((ParenthesedSelectBody) selectBody).getSelectBody() );
return getHintFromSelectBody(((ParenthesedSelectBody) selectBody).getSelectBody());
} else {
return null;
}
Expand Down
122 changes: 69 additions & 53 deletions src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
public final class CCJSqlParserUtil {
public final static int ALLOWED_NESTING_DEPTH = 10;

private CCJSqlParserUtil() {
}
private CCJSqlParserUtil() {}

public static Statement parse(Reader statementReader) throws JSQLParserException {
CCJSqlParser parser = new CCJSqlParser(new StreamProvider(statementReader));
Expand All @@ -48,8 +47,7 @@ public static Statement parse(String sql) throws JSQLParserException {
}

/**
* Parses an sql statement while allowing via consumer to configure the used
* parser before.
* Parses an sql statement while allowing via consumer to configure the used parser before.
*
* For instance to activate SQLServer bracket quotation on could use:
*
Expand All @@ -62,7 +60,8 @@ public static Statement parse(String sql) throws JSQLParserException {
* @return
* @throws JSQLParserException
*/
public static Statement parse(String sql, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
public static Statement parse(String sql, Consumer<CCJSqlParser> consumer)
throws JSQLParserException {
Statement statement = null;

// first, try to parse fast and simple
Expand All @@ -73,7 +72,7 @@ public static Statement parse(String sql, Consumer<CCJSqlParser> consumer) throw
}
statement = parseStatement(parser);
} catch (JSQLParserException ex) {
if (getNestingDepth(sql)<=ALLOWED_NESTING_DEPTH) {
if (getNestingDepth(sql) <= ALLOWED_NESTING_DEPTH) {
CCJSqlParser parser = newParser(sql).withAllowComplexParsing(true);
if (consumer != null) {
consumer.accept(parser);
Expand Down Expand Up @@ -130,13 +129,15 @@ public static Expression parseExpression(String expression) throws JSQLParserExc
return parseExpression(expression, true);
}

public static Expression parseExpression(String expression, boolean allowPartialParse) throws JSQLParserException {
public static Expression parseExpression(String expression, boolean allowPartialParse)
throws JSQLParserException {
return parseExpression(expression, allowPartialParse, p -> {
});
}

@SuppressWarnings("PMD.CyclomaticComplexity")
public static Expression parseExpression(String expressionStr, boolean allowPartialParse, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
public static Expression parseExpression(String expressionStr, boolean allowPartialParse,
Consumer<CCJSqlParser> consumer) throws JSQLParserException {
Expression expression = null;

// first, try to parse fast and simple
Expand All @@ -148,22 +149,26 @@ public static Expression parseExpression(String expressionStr, boolean allowPart
try {
expression = parser.Expression();
if (parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException("could only parse partial expression " + expression.toString());
throw new JSQLParserException(
"could only parse partial expression " + expression.toString());
}
} catch (ParseException ex) {
throw new JSQLParserException(ex);
}
} catch (JSQLParserException ex1) {
// when fast simple parsing fails, try complex parsing but only if it has a chance to succeed
if (getNestingDepth(expressionStr)<=ALLOWED_NESTING_DEPTH) {
// when fast simple parsing fails, try complex parsing but only if it has a chance to
// succeed
if (getNestingDepth(expressionStr) <= ALLOWED_NESTING_DEPTH) {
CCJSqlParser parser = newParser(expressionStr).withAllowComplexParsing(true);
if (consumer != null) {
consumer.accept(parser);
}
try {
expression = parser.Expression();
if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException("could only parse partial expression " + expression.toString());
if (!allowPartialParse
&& parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException(
"could only parse partial expression " + expression.toString());
}
} catch (JSQLParserException ex) {
throw ex;
Expand All @@ -176,8 +181,8 @@ public static Expression parseExpression(String expressionStr, boolean allowPart
}

/**
* Parse an conditional expression. This is the expression after a where
* clause. Partial parsing is enabled.
* Parse an conditional expression. This is the expression after a where clause. Partial parsing
* is enabled.
*
* @param condExpr
* @return the expression parsed
Expand All @@ -188,47 +193,53 @@ public static Expression parseCondExpression(String condExpr) throws JSQLParserE
}

/**
* Parse an conditional expression. This is the expression after a where
* clause.
* Parse an conditional expression. This is the expression after a where clause.
*
* @param condExpr
* @param allowPartialParse false: needs the whole string to be processed.
* @return the expression parsed
* @see #parseCondExpression(String)
*/
public static Expression parseCondExpression(String condExpr, boolean allowPartialParse) throws JSQLParserException {
public static Expression parseCondExpression(String condExpr, boolean allowPartialParse)
throws JSQLParserException {
return parseCondExpression(condExpr, allowPartialParse, p -> {
});
}

@SuppressWarnings("PMD.CyclomaticComplexity")
public static Expression parseCondExpression(String conditionalExpressionStr, boolean allowPartialParse, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
public static Expression parseCondExpression(String conditionalExpressionStr,
boolean allowPartialParse, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
Expression expression = null;

// first, try to parse fast and simple
try {
CCJSqlParser parser = newParser(conditionalExpressionStr).withAllowComplexParsing(false);
CCJSqlParser parser =
newParser(conditionalExpressionStr).withAllowComplexParsing(false);
if (consumer != null) {
consumer.accept(parser);
}
try {
expression = parser.Expression();
if (parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException("could only parse partial expression " + expression.toString());
throw new JSQLParserException(
"could only parse partial expression " + expression.toString());
}
} catch (ParseException ex) {
throw new JSQLParserException(ex);
}
} catch (JSQLParserException ex1) {
if (getNestingDepth(conditionalExpressionStr)<=ALLOWED_NESTING_DEPTH) {
CCJSqlParser parser = newParser(conditionalExpressionStr).withAllowComplexParsing(true);
} catch (JSQLParserException ex1) {
if (getNestingDepth(conditionalExpressionStr) <= ALLOWED_NESTING_DEPTH) {
CCJSqlParser parser =
newParser(conditionalExpressionStr).withAllowComplexParsing(true);
if (consumer != null) {
consumer.accept(parser);
}
try {
expression = parser.Expression();
if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException("could only parse partial expression " + expression.toString());
if (!allowPartialParse
&& parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException(
"could only parse partial expression " + expression.toString());
}
} catch (JSQLParserException ex) {
throw ex;
Expand Down Expand Up @@ -257,7 +268,8 @@ public Statement call() throws Exception {
});
executorService.shutdown();

statement = future.get( parser.getConfiguration().getAsInteger(Feature.timeOut), TimeUnit.MILLISECONDS);
statement = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
parser.interrupted = true;
throw new JSQLParserException("Time out occurred.", ex);
Expand All @@ -281,7 +293,8 @@ public static Statements parseStatements(String sqls) throws JSQLParserException
*
* @return the statements parsed
*/
public static Statements parseStatements(String sqls, Consumer<CCJSqlParser> consumer) throws JSQLParserException {
public static Statements parseStatements(String sqls, Consumer<CCJSqlParser> consumer)
throws JSQLParserException {
Statements statements = null;

// first, try to parse fast and simple
Expand All @@ -292,8 +305,9 @@ public static Statements parseStatements(String sqls, Consumer<CCJSqlParser> con
}
statements = parseStatements(parser);
} catch (JSQLParserException ex) {
// when fast simple parsing fails, try complex parsing but only if it has a chance to succeed
if (getNestingDepth(sqls)<=ALLOWED_NESTING_DEPTH) {
// when fast simple parsing fails, try complex parsing but only if it has a chance to
// succeed
if (getNestingDepth(sqls) <= ALLOWED_NESTING_DEPTH) {
CCJSqlParser parser = newParser(sqls).withAllowComplexParsing(true);
if (consumer != null) {
consumer.accept(parser);
Expand Down Expand Up @@ -321,7 +335,8 @@ public Statements call() throws Exception {
});
executorService.shutdown();

statements = future.get( parser.getConfiguration().getAsInteger(Feature.timeOut) , TimeUnit.MILLISECONDS);
statements = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
parser.interrupted = true;
throw new JSQLParserException("Time out occurred.", ex);
Expand All @@ -331,7 +346,8 @@ public Statements call() throws Exception {
return statements;
}

public static void streamStatements(StatementListener listener, InputStream is, String encoding) throws JSQLParserException {
public static void streamStatements(StatementListener listener, InputStream is, String encoding)
throws JSQLParserException {
try {
CCJSqlParser parser = newParser(is, encoding);
while (true) {
Expand All @@ -349,27 +365,27 @@ public static void streamStatements(StatementListener listener, InputStream is,
throw new JSQLParserException(ex);
}
}

public static int getNestingDepth(String sql) {
int maxlevel=0;
int level=0;
char[] chars = sql.toCharArray();
for (char c:chars) {
switch(c) {
case '(':
level++;
break;
case ')':
if (maxlevel<level) {
maxlevel = level;
}
level--;
break;
default:
// Codazy/PMD insists in a Default statement
}
}
return maxlevel;
int maxlevel = 0;
int level = 0;

char[] chars = sql.toCharArray();
for (char c : chars) {
switch (c) {
case '(':
level++;
break;
case ')':
if (maxlevel < level) {
maxlevel = level;
}
level--;
break;
default:
// Codazy/PMD insists in a Default statement
}
}
return maxlevel;
}
}
Loading