@@ -1512,6 +1512,8 @@ public static JSONObject getJSONObject(JSONObject object, String key) {
15121512
15131513
15141514 public static final String KEY_CONFIG = "config" ;
1515+
1516+ public static final String KEY_SQL = "sql" ;
15151517
15161518 protected Map <String , List <JSONObject >> arrayMainCacheMap = new HashMap <>();
15171519 public void putArrayMainCache (String arrayPath , List <JSONObject > mainTableDataList ) {
@@ -1549,19 +1551,27 @@ public JSONObject executeSQL(SQLConfig config, boolean isSubquery) throws Except
15491551 JSONObject result ;
15501552
15511553 boolean explain = config .isExplain ();
1552- if (explain ) { //如果先执行 explain,则 execute 会死循环,所以只能先执行非 explain
1554+ if (explain ) {
1555+ //如果先执行 explain,则 execute 会死循环,所以只能先执行非 explain
15531556 config .setExplain (false ); //对下面 config.getSQL(false); 生效
15541557 JSONObject res = getSQLExecutor ().execute (config , false );
15551558
1556- config .setExplain (explain );
1557- JSONObject explainResult = config .isMain () && config .getPosition () != 0 ? null : getSQLExecutor ().execute (config , false );
1559+ //如果是查询方法,才能执行explain
1560+ if (RequestMethod .isQueryMethod (config .getMethod ())){
1561+ config .setExplain (explain );
1562+ JSONObject explainResult = config .isMain () && config .getPosition () != 0 ? null : getSQLExecutor ().execute (config , false );
15581563
1559- if (explainResult == null ) {
1560- result = res ;
1561- }
1562- else {
1564+ if (explainResult == null ) {
1565+ result = res ;
1566+ }
1567+ else {
1568+ result = new JSONObject (true );
1569+ result .put (KEY_EXPLAIN , explainResult );
1570+ result .putAll (res );
1571+ }
1572+ }else {//如果是更新请求,不执行explain,但可以返回sql
15631573 result = new JSONObject (true );
1564- result .put (KEY_EXPLAIN , explainResult );
1574+ result .put (KEY_SQL , config . getSQL ( false ) );
15651575 result .putAll (res );
15661576 }
15671577 }
0 commit comments