1414import java .util .Collections ;
1515import java .util .List ;
1616import java .util .Optional ;
17+
1718import net .sf .jsqlparser .schema .Table ;
1819import net .sf .jsqlparser .statement .Statement ;
1920import net .sf .jsqlparser .statement .StatementVisitor ;
@@ -27,6 +28,7 @@ public class CreateTable implements Statement {
2728 private List <String > createOptionsStrings ;
2829 private List <String > tableOptionsStrings ;
2930 private List <ColumnDefinition > columnDefinitions ;
31+ private List <String > columns ;
3032 private List <Index > indexes ;
3133 private Select select ;
3234 private Table likeTable ;
@@ -66,6 +68,14 @@ public void setColumnDefinitions(List<ColumnDefinition> list) {
6668 columnDefinitions = list ;
6769 }
6870
71+ public List <String > getColumns () {
72+ return this .columns ;
73+ }
74+
75+ public void setColumns (List <String > columns ) {
76+ this .columns =columns ;
77+ }
78+
6979 /**
7080 * @return a list of options (as simple strings) of this table definition, as ("TYPE", "=", "MYISAM")
7181 */
@@ -150,6 +160,10 @@ public String toString() {
150160 + (!"" .equals (createOps ) ? createOps + " " : "" )
151161 + "TABLE " + (ifNotExists ? "IF NOT EXISTS " : "" ) + table ;
152162
163+ if (columns != null && !columns .isEmpty ()) {
164+ sql += " " ;
165+ sql += PlainSelect .getStringList (columns , true , true );
166+ }
153167 if (columnDefinitions != null && !columnDefinitions .isEmpty ()) {
154168 sql += " (" ;
155169
@@ -217,6 +231,11 @@ public CreateTable withColumnDefinitions(List<ColumnDefinition> columnDefinition
217231 return this ;
218232 }
219233
234+ public CreateTable withColumns (List <String > columns ) {
235+ this .setColumns (columns );
236+ return this ;
237+ }
238+
220239 public CreateTable withIndexes (List <Index > indexes ) {
221240 this .setIndexes (indexes );
222241 return this ;
@@ -246,6 +265,18 @@ public CreateTable addColumnDefinitions(Collection<? extends ColumnDefinition> c
246265 return this .withColumnDefinitions (collection );
247266 }
248267
268+ public CreateTable addColumns (String ... columns ) {
269+ List <String > collection = Optional .ofNullable (getColumns ()).orElseGet (ArrayList ::new );
270+ Collections .addAll (collection , columns );
271+ return this .withColumns (collection );
272+ }
273+
274+ public CreateTable addColumns (Collection <String > columns ) {
275+ List <String > collection = Optional .ofNullable (getColumns ()).orElseGet (ArrayList ::new );
276+ collection .addAll (columns );
277+ return this .withColumns (collection );
278+ }
279+
249280 public CreateTable addIndexes (Index ... indexes ) {
250281 List <Index > collection = Optional .ofNullable (getIndexes ()).orElseGet (ArrayList ::new );
251282 Collections .addAll (collection , indexes );
0 commit comments