Skip to content

Commit 2ef18f0

Browse files
committed
Added delete
1 parent 3d579ed commit 2ef18f0

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Usage
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")

src/com/tpwang/sql/SQLDelete.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
}

src/com/tpwang/sql/SQLUpdate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)