2121 */
2222package net .sf .jsqlparser .statement .select ;
2323
24+ import java .util .Iterator ;
25+ import java .util .List ;
2426import net .sf .jsqlparser .expression .Alias ;
2527import net .sf .jsqlparser .expression .Expression ;
2628import net .sf .jsqlparser .expression .ExpressionVisitor ;
@@ -35,6 +37,7 @@ public class SubSelect implements FromItem, Expression, ItemsList {
3537 private SelectBody selectBody ;
3638 private Alias alias ;
3739 private boolean useBrackets = true ;
40+ private List <WithItem > withItemsList ;
3841
3942 private Pivot pivot ;
4043
@@ -83,6 +86,14 @@ public boolean isUseBrackets() {
8386 public void setUseBrackets (boolean useBrackets ) {
8487 this .useBrackets = useBrackets ;
8588 }
89+
90+ public List <WithItem > getWithItemsList () {
91+ return withItemsList ;
92+ }
93+
94+ public void setWithItemsList (List <WithItem > withItemsList ) {
95+ this .withItemsList = withItemsList ;
96+ }
8697
8798 @ Override
8899 public void accept (ItemsListVisitor itemsListVisitor ) {
@@ -91,8 +102,27 @@ public void accept(ItemsListVisitor itemsListVisitor) {
91102
92103 @ Override
93104 public String toString () {
94- return (useBrackets ?"(" :"" ) + selectBody + (useBrackets ?")" :"" )
95- + ((pivot != null ) ? " " + pivot : "" )
96- + ((alias != null ) ? alias .toString () : "" );
105+ StringBuilder retval = new StringBuilder ();
106+ if (useBrackets )
107+ retval .append ("(" );
108+ if (withItemsList != null && !withItemsList .isEmpty ()) {
109+ retval .append ("WITH " );
110+ for (Iterator <WithItem > iter = withItemsList .iterator (); iter .hasNext ();) {
111+ WithItem withItem = (WithItem ) iter .next ();
112+ retval .append (withItem );
113+ if (iter .hasNext ()) {
114+ retval .append ("," );
115+ }
116+ retval .append (" " );
117+ }
118+ }
119+ retval .append (selectBody );
120+ if (useBrackets )
121+ retval .append (")" );
122+
123+ if (pivot != null ) retval .append (" " ).append (pivot );
124+ if (alias != null ) retval .append (alias .toString ());
125+
126+ return retval .toString ();
97127 }
98128}
0 commit comments