Skip to content

Commit

Permalink
Merge pull request #219 from gujiachun/master
Browse files Browse the repository at this point in the history
fix: @Explain在更新方法应用的错误
  • Loading branch information
TommyLemon authored Apr 20, 2021
2 parents 4ebc995 + 838b3b0 commit 7843865
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions APIJSONORM/src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,8 @@ public static JSONObject getJSONObject(JSONObject object, String key) {


public static final String KEY_CONFIG = "config";

public static final String KEY_SQL = "sql";

protected Map<String, List<JSONObject>> arrayMainCacheMap = new HashMap<>();
public void putArrayMainCache(String arrayPath, List<JSONObject> mainTableDataList) {
Expand Down Expand Up @@ -1549,19 +1551,27 @@ public JSONObject executeSQL(SQLConfig config, boolean isSubquery) throws Except
JSONObject result;

boolean explain = config.isExplain();
if (explain) { //如果先执行 explain,则 execute 会死循环,所以只能先执行非 explain
if (explain) {
//如果先执行 explain,则 execute 会死循环,所以只能先执行非 explain
config.setExplain(false); //对下面 config.getSQL(false); 生效
JSONObject res = getSQLExecutor().execute(config, false);

config.setExplain(explain);
JSONObject explainResult = config.isMain() && config.getPosition() != 0 ? null : getSQLExecutor().execute(config, false);
//如果是查询方法,才能执行explain
if (RequestMethod.isQueryMethod(config.getMethod())){
config.setExplain(explain);
JSONObject explainResult = config.isMain() && config.getPosition() != 0 ? null : getSQLExecutor().execute(config, false);

if (explainResult == null) {
result = res;
}
else {
if (explainResult == null) {
result = res;
}
else {
result = new JSONObject(true);
result.put(KEY_EXPLAIN, explainResult);
result.putAll(res);
}
}else{//如果是更新请求,不执行explain,但可以返回sql
result = new JSONObject(true);
result.put(KEY_EXPLAIN, explainResult);
result.put(KEY_SQL, config.getSQL(false));
result.putAll(res);
}
}
Expand Down

0 comments on commit 7843865

Please sign in to comment.