MCPcopy Create free account
hub / github.com/Nemo1870/sql-parse / Update

Class Update

src/main/java/com/sql/parse/statement/impl/druid/Update.java:26–281  ·  view source on GitHub ↗

@date 2019年4月30日上午09:58:02 @desc Update语法操作类

Source from the content-addressed store, hash-verified

24 * @desc Update语法操作类
25 */
26public class Update extends com.sql.parse.statement.Update {
27 private SQLUpdateStatement update;
28
29 public Update(SQLUpdateStatement update) {
30 this.update = update;
31 }
32
33 public Update(String tableName) {
34 SQLUpdateStatement update = new SQLUpdateStatement();
35 SQLExprTableSource table = new SQLExprTableSource(tableName);
36 update.setTableSource(table);
37 this.update = update;
38 }
39
40 @Override
41 public String getSql(boolean safe) {
42 Update myUpdate = this.clone();
43 /*where条件为空时,添加1=2的条件表达式*/
44 if (safe && myUpdate.getUpdate().getWhere() == null) {
45 myUpdate.where("1 = 2");
46 }
47 return SQLUtils.toSQLString(myUpdate.getUpdate());
48 }
49
50 public SQLUpdateStatement getUpdate() {
51 return this.update;
52 }
53
54 /**
55 * @title: addColumn
56 * @desc 新增update数据
57 */
58 public Update addColumn(UpdateItem updateItem) {
59 SQLUpdateSetItem setItem = new SQLUpdateSetItem();
60 setItem.setColumn(ExpressionBuilder.parse(updateItem.getColumnName()));
61 setItem.setValue(ExpressionBuilder.parse(updateItem.getExpression()));
62 update.addItem(setItem);
63 return this;
64 }
65
66 public Update addColumn(String column, String value) {
67 return addColumn(new UpdateItem(column, value));
68 }
69
70 /**
71 * @title: where
72 * @desc "WHERE"符号
73 */
74 public Update where(String expr) {
75 SQLExpr expression = ExpressionBuilder.parse(expr);
76 where(expression);
77 return this;
78 }
79
80 public Update where(SQLExpr where) {
81 SQLExpr oldWhere = update.getWhere();
82 if (oldWhere == null) {
83 update.setWhere(where);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected