From 6831cb6a6d9b0db24b612628d5dc31243493b7a4 Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Sun, 31 Jan 2021 04:20:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=AE=89=E5=85=A8=EF=BC=9A?= =?UTF-8?q?=E5=AF=B9=20DELETE=20=E5=92=8C=20PUT=20=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=8A=A0=20LIMIT=EF=BC=9B=E7=AE=80=E5=8C=96=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E7=9A=84=E5=86=99=E6=B3=95=EF=BC=9A=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=20"key<>":=20"a"=20=E8=BF=99=E7=A7=8D=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20Data=20truncation:=20Invalid=20JSON=20text?= =?UTF-8?q?=EF=BC=8C=E5=8E=9F=E6=9D=A5=E5=BF=85=E9=A1=BB=E9=87=8C=E9=9D=A2?= =?UTF-8?q?=E5=86=8D=E7=94=A8=20""=20=E5=8C=85=E8=A3=85=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=EF=BC=8CJSON=20=E4=B8=AD=E8=BF=98=E5=BE=97=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=EF=BC=8C=E7=8E=B0=E5=9C=A8=E7=9B=B4=E6=8E=A5=E5=86=99=E5=8D=B3?= =?UTF-8?q?=E5=8F=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apijson/orm/AbstractObjectParser.java | 4 +-- .../java/apijson/orm/AbstractSQLConfig.java | 29 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java b/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java index 2ac9447e6..b40c9ca0b 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java @@ -650,7 +650,7 @@ public SQLConfig newSQLConfig(boolean isProcedure) throws Exception { */ @Override public AbstractObjectParser setSQLConfig() throws Exception { - return setSQLConfig(1, 0, 0); + return setSQLConfig(RequestMethod.isQueryMethod(method) ? 1 : 0, 0, 0); } @Override @@ -668,7 +668,7 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro return this; } } - sqlConfig.setCount(count).setPage(page).setPosition(position); + sqlConfig.setCount(sqlConfig.getCount() <= 0 ? count : sqlConfig.getCount()).setPage(page).setPosition(position); parser.onVerifyRole(sqlConfig); diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 169fe6d4e..e6b08a494 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -1284,11 +1284,11 @@ public String getLimitString() { public static String getLimitString(int page, int count, boolean isTSQL) { int offset = getOffset(page, count); - if (isTSQL) { + if (isTSQL) { // OFFSET FECTH 中所有关键词都不可省略 return " OFFSET " + offset + " ROWS FETCH FIRST " + count + " ROWS ONLY"; } - return " LIMIT " + count + " OFFSET " + offset; + return " LIMIT " + count + (offset <= 0 ? "" : " OFFSET " + offset); // DELETE, UPDATE 不支持 OFFSET } //WHERE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -2179,20 +2179,23 @@ public String getContainString(String key, Object[] childs, int type) throws Ill String condition = ""; if (childs != null) { for (int i = 0; i < childs.length; i++) { - if (childs[i] != null) { - if (childs[i] instanceof JSON) { + Object c = childs[i]; + if (c != null) { + if (c instanceof JSON) { throw new IllegalArgumentException(key + "<>:value 中value类型不能为JSON!"); } condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR)); if (isPostgreSQL()) { - condition += (getKey(key) + " @> " + getValue(newJSONArray(childs[i]))); //operator does not exist: jsonb @> character varying "[" + childs[i] + "]"); + condition += (getKey(key) + " @> " + getValue(newJSONArray(c))); //operator does not exist: jsonb @> character varying "[" + c + "]"); } else if (isOracle()) { - condition += ("json_textcontains(" + getKey(key) + ", '$', " + getValue(childs[i].toString()) + ")"); + condition += ("json_textcontains(" + getKey(key) + ", '$', " + getValue(c.toString()) + ")"); } else { - condition += ("json_contains(" + getKey(key) + ", " + getValue(childs[i].toString()) + ")"); + boolean isNum = c instanceof Number; + String v = (isNum ? "" : "\"") + childs[i] + (isNum ? "" : "\""); + condition += ("json_contains(" + getKey(key) + ", " + getValue(v) + ")"); } } } @@ -2390,9 +2393,9 @@ public static String getSQL(AbstractSQLConfig config) throws Exception { case POST: return "INSERT INTO " + tablePath + config.getColumnString() + " VALUES" + config.getValuesString(); case PUT: - return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true); + return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true) + config.getLimitString(); case DELETE: - return "DELETE FROM " + tablePath + config.getWhereString(true); + return "DELETE FROM " + tablePath + config.getWhereString(true) + config.getLimitString(); default: String explain = (config.isExplain() ? (config.isSQLServer() || config.isOracle() ? "SET STATISTICS PROFILE ON " : "EXPLAIN ") : ""); if (config.isTest() && RequestMethod.isGetMethod(config.getMethod(), true)) { @@ -2635,6 +2638,10 @@ public static SQLConfig newSQLConfig(RequestMethod method, String table, String throw new NotExistException(TAG + ": newSQLConfig idIn instanceof List >> 去掉无效 id 后 newIdIn.isEmpty()"); } idIn = newIdIn; + + if (method == DELETE || method == PUT) { + config.setCount(newIdIn.size()); + } } //对id和id{}处理,这两个一定会作为条件 @@ -2670,6 +2677,10 @@ else if (id instanceof Subquery) {} throw new NotExistException(TAG + ": newSQLConfig idIn != null && (((List) idIn).contains(id) == false"); } } + + if (method == DELETE || method == PUT) { + config.setCount(1); + } }