Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: @explain在更新方法应用的错误 #219

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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