@date 2019年4月30日上午09:58:02 @desc Update语法操作类
| 25 | * @desc Update语法操作类 |
| 26 | */ |
| 27 | public class Update extends com.sql.parse.statement.Update { |
| 28 | private net.sf.jsqlparser.statement.update.Update update; |
| 29 | |
| 30 | public Update(net.sf.jsqlparser.statement.update.Update update) { |
| 31 | this.update = update; |
| 32 | } |
| 33 | |
| 34 | public Update(String tableName) { |
| 35 | net.sf.jsqlparser.statement.update.Update update = new net.sf.jsqlparser.statement.update.Update(); |
| 36 | Table table = new Table(tableName); |
| 37 | update.setTable(table); |
| 38 | this.update = update; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public String getSql(boolean safe) { |
| 43 | Update myUpdate = this.clone(); |
| 44 | /*where条件为空时,添加1=2的条件表达式*/ |
| 45 | if (safe && myUpdate.getUpdate().getWhere() == null) { |
| 46 | myUpdate.where("1 = 2"); |
| 47 | } |
| 48 | return myUpdate.getUpdate().toString(); |
| 49 | } |
| 50 | |
| 51 | public net.sf.jsqlparser.statement.update.Update getUpdate() { |
| 52 | return this.update; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @title: addColumn |
| 57 | * @desc 新增update数据 |
| 58 | */ |
| 59 | public Update addColumn(UpdateItem updateItem) { |
| 60 | if (update.getColumns() == null) { |
| 61 | update.setColumns(new ArrayList<>()); |
| 62 | } |
| 63 | if (update.getExpressions() == null) { |
| 64 | update.setExpressions(new ArrayList<>()); |
| 65 | } |
| 66 | update.getColumns().add(new Column(updateItem.getColumnName())); |
| 67 | try { |
| 68 | Expression expression = ExpressionBuilder.parse(updateItem.getExpression()); |
| 69 | update.getExpressions().add(expression); |
| 70 | } catch (Exception e) { |
| 71 | throw BaseException.errorCode(SqlParseConstant.CODE_002); |
| 72 | } |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | public Update addColumn(String column, String value) { |
| 77 | return addColumn(new UpdateItem(column, value)); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @title: where |
| 82 | * @desc "WHERE"符号 |
| 83 | */ |
| 84 | public Update where(String expr) { |
nothing calls this directly
no outgoing calls
no test coverage detected