Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert into ... on duplicate key ... throw exception #191

Closed
packageOk opened this issue Nov 10, 2015 · 3 comments
Closed

insert into ... on duplicate key ... throw exception #191

packageOk opened this issue Nov 10, 2015 · 3 comments

Comments

@packageOk
Copy link
Contributor

Hello, when I parse a mysql which contains "on duplicate key", jsqlparser throw a exception.
There is my code:

String sql = "INSERT INTO TempPropInt0 (UserId, Key, Value) VALUES (51311, 'T_211', 18) ON DUPLICATE KEY UPDATE Value = 18;";

    Insert insert = (Insert)CCJSqlParserUtil.parse(sql);

    StringBuilder builder = new StringBuilder();
    ExpressionDeParser eDeparser = new ExpressionDeParser();
    SelectDeParser sDeparser = new SelectDeParser();
    InsertDeParser iDeParser = new InsertDeParser();

    eDeparser.setBuffer(builder);
    eDeparser.setSelectVisitor(sDeparser);
    sDeparser.setBuffer(builder);
    sDeparser.setExpressionVisitor(eDeparser);
    iDeParser.setBuffer(builder);
    iDeParser.setExpressionVisitor(eDeparser);
    iDeParser.setSelectVisitor(sDeparser);

    iDeParser.deParse(insert);
    System.out.println(builder.toString());

There is the exception:
net.sf.jsqlparser.JSQLParserException
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:51)
at com.baitian.realtime.dc.parse.custom.CustomParserTest.test4(CustomParserTest.java:160)
...
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "ON" "ON "" at line 1, column 81.
Was expecting one of:

"RETURNING" ...

jsqlparser version is 0.9.4

@wumpz
Copy link
Member

wumpz commented Nov 12, 2015

On duplicate key ist not supported by JSqlParser. Pull requests arecwellcome. ☺

@packageOk
Copy link
Contributor Author

I have committed my request. You'd better test it, because I do it after learn javacc examples. I don't have much experience about javacc

@wumpz
Copy link
Member

wumpz commented Nov 14, 2015

After a first look it's OK. I will merge and make some minor improvements. Thx for using JSqlparser. Cheers

@wumpz wumpz closed this as completed in 2fddf8c Nov 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants