File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 5454 .equalsTo(123456))
5555 .create();
5656
57+ String delete1 = new SQLDelete()
58+ .fromTable("manuscript")
59+ .where(new SQLCondition()
60+ .whereAttribute("author_id")
61+ .equalsTo("123456"))
62+ .create();
63+
5764 stmt.executeQuery(new SQLQuery()
5865 .select('*')
5966 .from("manuscript")
Original file line number Diff line number Diff line change 1+ package com .tpwang .sql ;
2+
3+ public class SQLDelete {
4+
5+ private StringBuilder builder = null ;
6+
7+ /***
8+ * Constructor
9+ */
10+ public SQLDelete () {
11+ builder = new StringBuilder ().append ("DELETE " );
12+ }
13+
14+ /***
15+ * Where to delete from
16+ * @param tableName Delete table name
17+ * @return delete
18+ */
19+ public SQLDelete fromTable (String tableName ) {
20+ builder .append ("FROM " ).append (tableName ).append (' ' );
21+ return this ;
22+ }
23+
24+ /***
25+ * How to delete
26+ * @param condition Delete condition
27+ * @return delete
28+ */
29+ public SQLDelete where (SQLCondition condition ) {
30+ builder .append (condition .toString ());
31+ return this ;
32+ }
33+
34+ /***
35+ * How to delete
36+ * @param condition Delete condition
37+ * @return delete
38+ */
39+ public SQLDelete where (String condition ) {
40+ builder .append (condition );
41+ return this ;
42+ }
43+
44+ /***
45+ * Return the final query
46+ * @return delete string
47+ */
48+ public String create () {
49+ return toString ();
50+ }
51+
52+ /***
53+ * Return the final query
54+ */
55+ @ Override
56+ public String toString () {
57+ return builder .toString ().trim ();
58+ }
59+ }
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ public String create() {
119119 public String toString () {
120120 return builder .append ("SET " ).append (joiner .toString ()).append (' ' )
121121 .append ("WHERE " ).append (condition )
122- .toString ();
122+ .toString (). trim () ;
123123 }
124124
125125}
You can’t perform that action at this time.
0 commit comments