FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

增加row关键字、解决PUT方法的BUG by 330233789 · Pull Request #126 · APIJSON/APIJSON · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public String getUserIdKey(String database, String schema, String table) {
// return null; // return null 则不生成 id,一般用于数据库自增 id
// }
};

// 自定义where条件拼接
//RAW_MAP.put("commentWhereItem1","`Comment`.`userId` = 38710 and `Comment`.`momentId` = 470");
//RAW_MAP.put("commentWhereItem2","`Comment`.`toId` = 0");
}


Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public JSONObject setUserIdIn(List<Object> list) {
public static final String KEY_HAVING = "@having"; //聚合函数条件,一般和@group一起用
public static final String KEY_ORDER = "@order"; //排序方式
public static final String KEY_JSON = "@json"; //SQL Server 把字段转为 JSON 输出
public static final String KEY_RAW = "@raw"; //自定义where条件拼接

public static final List<String> TABLE_KEY_LIST;
static {
Expand All @@ -171,6 +172,7 @@ public JSONObject setUserIdIn(List<Object> list) {
TABLE_KEY_LIST.add(KEY_HAVING);
TABLE_KEY_LIST.add(KEY_ORDER);
TABLE_KEY_LIST.add(KEY_JSON);
TABLE_KEY_LIST.add(KEY_RAW);
}

//@key关键字都放这个类 >>>>>>>>>>>>>>>>>>>>>>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public abstract class AbstractSQLConfig implements SQLConfig {
*/
public static final Map<String, String> TABLE_KEY_MAP;
public static final List<String> DATABASE_LIST;
// 自定义where条件拼接
public static final Map<String, String> RAW_MAP;
static {
TABLE_KEY_MAP = new HashMap<String, String>();
TABLE_KEY_MAP.put(Table.class.getSimpleName(), Table.TABLE_NAME);
Expand All @@ -101,6 +103,8 @@ public abstract class AbstractSQLConfig implements SQLConfig {
DATABASE_LIST.add(DATABASE_POSTGRESQL);
DATABASE_LIST.add(DATABASE_SQLSERVER);
DATABASE_LIST.add(DATABASE_ORACLE);

RAW_MAP = new HashMap<>();
}

@Override
Expand Down Expand Up @@ -1442,7 +1446,10 @@ private String getWhereItem(String key, Object value
, RequestMethod method, boolean verifyName) throws Exception {
Log.d(TAG, "getWhereItem key = " + key);
//避免筛选到全部 value = key == null ? null : where.get(key);
if (key == null || value == null || key.startsWith("@") || key.endsWith("()")) {//关键字||方法, +或-直接报错
if(key.equals("@raw")){
Log.d(TAG, "getWhereItem key startsWith @ = @raw ");
// 自定义where条件拼接,直接通过,放行
}else if (key == null || value == null || key.startsWith("@") || key.endsWith("()")) {//关键字||方法, +或-直接报错
Log.d(TAG, "getWhereItem key == null || value == null"
+ " || key.startsWith(@) || key.endsWith(()) >> continue;");
return null;
Expand Down Expand Up @@ -1483,7 +1490,9 @@ else if (key.endsWith(">")) {
else if (key.endsWith("<")) {
keyType = 10;
}
else { //else绝对不能省,避免再次踩坑! keyType = 0; 写在for循环外面都没注意!
else if (key.startsWith("@")) {
keyType = 11;
} else { //else绝对不能省,避免再次踩坑! keyType = 0; 写在for循环外面都没注意!
keyType = 0;
}
key = getRealKey(method, key, false, true, verifyName, getQuote());
Expand All @@ -1510,11 +1519,31 @@ else if (key.endsWith("<")) {
return getCompareString(key, value, ">");
case 10:
return getCompareString(key, value, "<");
case 11:
return getRaw(key,value);
default: //TODO MySQL JSON类型的字段对比 key='[]' 会无结果! key LIKE '[1, 2, 3]' //TODO MySQL , 后面有空格!
return getEqualString(key, value);
}
}

@JSONField(serialize = false)
public String getRaw(String key, Object value) throws Exception {
if (JSON.isBooleanOrNumberOrString(value) == false && value instanceof Subquery == false) {
throw new IllegalArgumentException(key + ":value 中value不合法!非PUT请求只支持 [Boolean, Number, String] 内的类型 !");
}

String[] rawList = ((String)value).split(",");
String whereItem = "";
for (int i = 0; i < rawList.length; i++) {
if(rawList.length>1&& i!=0){
whereItem += " and " + RAW_MAP.get(rawList[i]);
}else{
whereItem += RAW_MAP.get(rawList[i]);
}
}

return whereItem;
}

@JSONField(serialize = false)
public String getEqualString(String key, Object value) throws Exception {
Expand Down Expand Up @@ -2041,7 +2070,7 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
String quote = getQuote();

boolean isFirst = true;
int keyType = 0;// 0 - =; 1 - +, 2 - -
int keyType;// 0 - =; 1 - +, 2 - -
Object value;

String idKey = getIdKey();
Expand All @@ -2055,6 +2084,8 @@ public String getSetString(RequestMethod method, Map<String, Object> content, bo
keyType = 1;
} else if (key.endsWith("-")) {
keyType = 2;
} else {
keyType = 0; //注意重置类型,不然不该加减的字段会跟着加减
}
value = content.get(key);
key = getRealKey(method, key, false, true, verifyName, quote);
Expand Down

Back | FazBrowse Home | New Git URL