File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
main/java/net/sf/jsqlparser
test/java/net/sf/jsqlparser/test/update Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 2121 */
2222package net .sf .jsqlparser .statement .update ;
2323
24+ import java .util .Iterator ;
2425import java .util .List ;
2526
2627import net .sf .jsqlparser .expression .Expression ;
@@ -113,13 +114,26 @@ public String toString() {
113114 StringBuilder b = new StringBuilder ("UPDATE " );
114115 b .append (getTable ()).append (" SET " );
115116 for (int i = 0 ; i < getColumns ().size (); i ++) {
116- if (i !=0 ) {
117+ if (i != 0 ) {
117118 b .append (", " );
118119 }
119120 b .append (columns .get (i )).append (" = " );
120121 b .append (expressions .get (i ));
121122 }
122123
124+ if (fromItem != null ) {
125+ b .append (" FROM " ).append (fromItem );
126+ if (joins != null ) {
127+ for (Join join : joins ) {
128+ if (join .isSimple ()) {
129+ b .append (", " ).append (join );
130+ } else {
131+ b .append (" " ).append (join );
132+ }
133+ }
134+ }
135+ }
136+
123137 if (where != null ) {
124138 b .append (" WHERE " );
125139 b .append (where );
Original file line number Diff line number Diff line change 2424import net .sf .jsqlparser .expression .Expression ;
2525import net .sf .jsqlparser .expression .ExpressionVisitor ;
2626import net .sf .jsqlparser .schema .Column ;
27+ import net .sf .jsqlparser .statement .select .Join ;
2728import net .sf .jsqlparser .statement .update .Update ;
2829
2930/**
@@ -68,7 +69,19 @@ public void deParse(Update update) {
6869 if (i < update .getColumns ().size () - 1 ) {
6970 buffer .append (", " );
7071 }
71-
72+ }
73+
74+ if (update .getFromItem () != null ) {
75+ buffer .append (" FROM " ).append (update .getFromItem ());
76+ if (update .getJoins () != null ) {
77+ for (Join join : update .getJoins ()) {
78+ if (join .isSimple ()) {
79+ buffer .append (", " ).append (join );
80+ } else {
81+ buffer .append (" " ).append (join );
82+ }
83+ }
84+ }
7285 }
7386
7487 if (update .getWhere () != null ) {
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ public void testUpdateWithDeparser() throws JSQLParserException {
4747 assertSqlCanBeParsedAndDeparsed ("UPDATE table1 AS A SET A.column = 'XXX' WHERE A.cod_table = 'YYY'" );
4848 }
4949
50+ public void testUpdateWithFrom () throws JSQLParserException {
51+ assertSqlCanBeParsedAndDeparsed ("UPDATE table1 SET column = 5 FROM table1 LEFT JOIN table2 ON col1 = col2" );
52+ }
53+
5054 private void assertSqlCanBeParsedAndDeparsed (String statement ) throws JSQLParserException {
5155 Statement parsed = parserManager .parse (new StringReader (statement ));
5256 assertStatementCanBeDeparsedAs (parsed , statement );
You can’t perform that action at this time.
0 commit comments