Skip to content

Commit 5110598

Browse files
committed
introduced deparser and toString correction for insert output clause
1 parent 75489bf commit 5110598

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/main/java/net/sf/jsqlparser/statement/insert/Insert.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public String toString() {
255255
if (columns != null) {
256256
sql.append(PlainSelect.getStringList(columns, true, true)).append(" ");
257257
}
258+
259+
if (outputClause !=null) {
260+
sql.append(outputClause.toString());
261+
}
258262

259263
if (select != null) {
260264
sql.append(select);

src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public void deParse(Insert insert) {
7676
}
7777
buffer.append(")");
7878
}
79+
80+
if (insert.getOutputClause() != null) {
81+
buffer.append(insert.getOutputClause().toString());
82+
}
7983

8084
if (insert.getSelect() != null) {
8185
buffer.append(" ");

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,14 +1821,9 @@ Select SelectWithWithItems( ):
18211821
List<WithItem> with = null;
18221822
}
18231823
{
1824-
// LOOKAHEAD(2) (
1825-
// "(" with=WithList() select = Select( with ) ")" { select.withUsingWithBrackets(true); }
1826-
//)
1827-
//|
1828-
//(
1829-
[ with=WithList() ]
1830-
select = Select( with )
1831-
//)
1824+
(LOOKAHEAD(2) ( "(" with=WithList() select = Select( with ) ")" { select.withUsingWithBrackets(true); } )
1825+
|
1826+
( [with=WithList()] select = Select( with ) ))
18321827
{
18331828
return select;
18341829
}

src/test/java/net/sf/jsqlparser/statement/insert/InsertTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void testInsertSelect() throws JSQLParserException {
254254
@Test
255255
public void testInsertWithSelect() throws JSQLParserException {
256256
assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (mycolumn) WITH a AS (SELECT mycolumn FROM mytable) SELECT mycolumn FROM a", true);
257-
//assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (mycolumn) (WITH a AS (SELECT mycolumn FROM mytable) SELECT mycolumn FROM a)", true);
257+
assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (mycolumn) (WITH a AS (SELECT mycolumn FROM mytable) SELECT mycolumn FROM a)", true);
258258
}
259259

260260
@Test
@@ -446,7 +446,7 @@ public void testInsertUnionSelectIssue1491() throws JSQLParserException {
446446
);
447447
}
448448

449-
//@Test
449+
@Test
450450
public void testInsertOutputClause() throws JSQLParserException {
451451
assertSqlCanBeParsedAndDeparsed(
452452
"INSERT INTO dbo.EmployeeSales (LastName, FirstName, CurrentSales) \n" +

0 commit comments

Comments
 (0)