Skip to content

Commit

Permalink
fixes #519
Browse files Browse the repository at this point in the history
fixes #520
  • Loading branch information
wumpz committed Oct 6, 2017
1 parent 51fcdea commit 272177a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -908,15 +908,29 @@ MergeInsert MergeInsertClause() : {
Column Column() #Column :
{
String databaseName = null, schemaName = null, tableName = null, columnName = null;
String token = null;
}
{
(
columnName = RelObjectName()
( "." [LOOKAHEAD(2) token = RelObjectName()] { tableName = columnName; columnName = token; token = null;}

This comment has been minimized.

Copy link
@artemsnisarenko

artemsnisarenko Jan 30, 2018

Optional column name results in a Column instance with null columnName being parsed.
A test showing the regression:

    @Test
    public void shouldNotParseMissingColumnAsNull() {
        try {
            CCJSqlParserUtil.parse("SELECT t. FROM t");
            fail();
        } catch (JSQLParserException e) {
            // expect
        }
    }
( "." token = RelObjectName() { schemaName = tableName; tableName = columnName; columnName = token; token = null;}
( "." token = RelObjectName() { databaseName = schemaName; schemaName = tableName; tableName = columnName; columnName = token; }
)?
)?
)?

/*(
LOOKAHEAD(7) databaseName=RelObjectName() "." [schemaName=RelObjectName()] "." tableName=RelObjectName() "." columnName=RelObjectName()
| LOOKAHEAD(5) schemaName=RelObjectName() "." tableName=RelObjectName() "." columnName=RelObjectName()
| LOOKAHEAD(3) tableName=RelObjectName() "." columnName=RelObjectName()
| columnName=RelObjectName()
)
)*/

{
if (tableName==null && (databaseName!=null || schemaName!=null)) {
throw generateParseException();
}

final Database database = new Database(databaseName);
final Table table = new Table(database, schemaName, tableName);
Column col = new Column(table, columnName);
Expand Down Expand Up @@ -2372,7 +2386,7 @@ Expression PrimaryExpression():

| LOOKAHEAD(2) retval=DateTimeLiteralExpression()

| LOOKAHEAD(Column()) retval=Column()
| retval=Column()

| LOOKAHEAD("(" SimpleExpression() ")") "(" retval=SimpleExpression() ")" {retval = new Parenthesis(retval); }

Expand Down

0 comments on commit 272177a

Please sign in to comment.