|
25 | 25 | import net.sf.jsqlparser.schema.Table; |
26 | 26 | import net.sf.jsqlparser.statement.Statement; |
27 | 27 | import net.sf.jsqlparser.statement.StatementVisitor; |
| 28 | +import net.sf.jsqlparser.statement.select.FromItem; |
| 29 | +import net.sf.jsqlparser.statement.select.Join; |
28 | 30 | import net.sf.jsqlparser.statement.select.Limit; |
29 | 31 | import net.sf.jsqlparser.statement.select.OrderByElement; |
30 | 32 | import net.sf.jsqlparser.statement.select.PlainSelect; |
|
34 | 36 | public class Delete implements Statement { |
35 | 37 |
|
36 | 38 | private Table table; |
| 39 | + private List<Table> tables; |
| 40 | + private List<Join> joins; |
37 | 41 | private Expression where; |
38 | 42 | private Limit limit; |
39 | 43 | private List<OrderByElement> orderByElements; |
@@ -75,11 +79,58 @@ public void setLimit(Limit limit) { |
75 | 79 | this.limit = limit; |
76 | 80 | } |
77 | 81 |
|
| 82 | + |
| 83 | + public List<Table> getTables() { |
| 84 | + return tables; |
| 85 | + } |
| 86 | + |
| 87 | + public void setTables(List<Table> tables) { |
| 88 | + this.tables = tables; |
| 89 | + } |
| 90 | + |
| 91 | + public List<Join> getJoins() { |
| 92 | + return joins; |
| 93 | + } |
| 94 | + |
| 95 | + public void setJoins(List<Join> joins) { |
| 96 | + this.joins = joins; |
| 97 | + } |
| 98 | + |
78 | 99 | @Override |
79 | 100 | public String toString() { |
80 | | - return "DELETE FROM " + table + |
81 | | - ((where != null) ? " WHERE " + where : "") + |
82 | | - (orderByElements!=null? PlainSelect.orderByToString(orderByElements):"") + |
83 | | - (limit != null ? limit : ""); |
| 101 | + StringBuilder b = new StringBuilder("DELETE"); |
| 102 | + |
| 103 | + if( tables != null && tables.size() > 0){ |
| 104 | + b.append(" "); |
| 105 | + for(Table t : tables){ |
| 106 | + b.append(t.toString()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + b.append(" FROM "); |
| 111 | + b.append(table); |
| 112 | + |
| 113 | + if (joins != null) { |
| 114 | + for (Join join : joins) { |
| 115 | + if (join.isSimple()) { |
| 116 | + b.append(", ").append(join); |
| 117 | + } else { |
| 118 | + b.append(" ").append(join); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + if( where != null ){ |
| 124 | + b.append(" WHERE ").append(where); |
| 125 | + } |
| 126 | + |
| 127 | + if(orderByElements!=null){ |
| 128 | + b.append(PlainSelect.orderByToString(orderByElements)); |
| 129 | + } |
| 130 | + |
| 131 | + if(limit != null){ |
| 132 | + b.append(limit); |
| 133 | + } |
| 134 | + return b.toString(); |
84 | 135 | } |
85 | 136 | } |
0 commit comments