Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Discussion options

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

You must be logged in to vote

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);
 }

Replies: 4 comments

Comment options

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

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
Comment options

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);
 }
You must be logged in to vote
0 replies
Comment options

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);
 }
You must be logged in to vote
0 replies
Answer selected by licai1210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #1765 on April 18, 2023 04:43.

AltStyle によって変換されたページ (->オリジナル) /