JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

where table_name = select database() has exception

Open luoguohua opened this issue 3 years ago • 1 comments

Describe the bug paser where table_name = select database() has exception

To Reproduce Example

       public static void main(String[] args) throws JSQLParserException {
        String sql = " select table_name, table_comment, create_time, update_time from information_schema.tables " +
                " where table_schema = (select database()) ";
        Statement statement = CCJSqlParserUtil.parse(sql);
        System.out.println(statement.toString());
    }

Exception out

Exception in thread "main" net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "=" "="
    at line 1, column 112.

Was expecting one of:

    "&"
    "::"
    ";"
    "<<"
    ">>"
    "COLLATE"
    "CONNECT"
    "EMIT"
    "GROUP"
    "HAVING"
    "START"
    "["
    "^"
    "|"
    <EOF>

	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:190)
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:63)
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:38)
	at com.seerbigdata.tourism.common.config.MybatisPlusConfig.main(MybatisPlusConfig.java:158)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "=" "="
    at line 1, column 112.

Was expecting one of:

    "&"
    "::"
    ";"
    "<<"
    ">>"
    "COLLATE"
    "CONNECT"
    "EMIT"
    "GROUP"
    "HAVING"
    "START"
    "["
    "^"
    "|"
    <EOF>

	at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:31468)
	at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:31301)
	at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:163)
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:188)
	... 3 more

System

  • MySQL-v8.0.27
  • java version "1.8.0_31"
  • JSqlParser 4.4

luoguohua avatar Apr 11 '22 08:04 luoguohua

Fixed by PR #1382 which is pending approval. You can pull and compile in the meantime to get a working JAR.

manticore-projects avatar Apr 11 '22 08:04 manticore-projects