Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

[BUG] JSQLParser 4.5/4.6 : RDBMS : extension field exception #1765

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

Closed
licai1210 opened this issue Apr 17, 2023 · 4 comments
Closed

[BUG] JSQLParser 4.5/4.6 : RDBMS : extension field exception #1765

licai1210 opened this issue Apr 17, 2023 · 4 comments

Comments

@licai1210
Copy link

licai1210 commented Apr 17, 2023

image

Hello, this issue is normal in 4.4, and there is an inaccurate issue with dynamically adding fields in the insert statement in 4.5/4.6. May I know how to solve it? Thank you

@manticore-projects
Copy link
Contributor

Greetings.

A lots of API has changed between 4.4 and 4.6 in order to streamline VALUES (..) statements.
The easiest way to figure out the AST is using JSQLFormatter, which can visualize the Tree of Java Objects:

image

You can try it online here

@licai1210
Copy link
Author

Hello, I need to add field values to existing SQL statements. May I know how to proceed? Thank you

@manticore-projects
Copy link
Contributor

Recommendation: Checkout PR #1754 which will allow for

    @Test
    void testIssue1765() {
        String sqlStr = "INSERT INTO mytable (col1)\n"
                        + "VALUES ( 1 )";

        Insert insert = new Insert()
                            .withTable( new Table("mytable") )
                            .withColumns( Arrays.asList(new Column("col1")) )
                            .withSelect( new Values().addExpressions(new LongValue(1)) );

        assertStatementCanBeDeparsedAs(insert, sqlStr,true);
    }

@manticore-projects
Copy link
Contributor

manticore-projects commented Apr 18, 2023

If you use Release 4.6 then your code will look like this:

    @Test
    void testIssue1765() {
        String sqlStr = "INSERT INTO mytable (col1)\n"
                        + "VALUES ( 1 )";

        Select select = new Select()
                                .withSelectBody( new ValuesStatement().addExpressions( new LongValue(1)) );

        Insert insert = new Insert()
                                .withTable( new Table("mytable") )
                                .withColumns( Arrays.asList(new Column("col1")) )
                                .withSelect(  select );

        assertStatementCanBeDeparsedAs(insert, sqlStr,true);
    }

@manticore-projects manticore-projects converted this issue into discussion #1766 Apr 18, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants