@@ -2075,6 +2075,11 @@ public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table,
20752075 }
20762076 AbstractSQLConfig config = callback .getSQLConfig (method , table );
20772077
2078+ String database = request .getString (KEY_DATABASE );
2079+ String schema = request .getString (KEY_SCHEMA );
2080+ config .setDatabase (database ); //不删,后面表对象还要用的,必须放在 parseJoin 前
2081+ config .setSchema (schema ); //不删,后面表对象还要用的
2082+
20782083 //放后面会导致主表是空对象时 joinList 未解析
20792084 if (isProcedure == false ) {
20802085 config = parseJoin (method , config , joinList , callback );
@@ -2084,11 +2089,6 @@ public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table,
20842089 return config ; //request.remove(key); 前都可以直接return,之后必须保证 put 回去
20852090 }
20862091
2087- String database = request .getString (KEY_DATABASE );
2088- String schema = request .getString (KEY_SCHEMA );
2089- config .setDatabase (database ); //不删,后面表对象还要用的
2090- config .setSchema (schema ); //不删,后面表对象还要用的
2091-
20922092 if (isProcedure ) {
20932093 return config ;
20942094 }
@@ -2388,6 +2388,18 @@ public static AbstractSQLConfig parseJoin(RequestMethod method, AbstractSQLConfi
23882388 SQLConfig cacheConfig = newSQLConfig (method , name , j .getTable (), null , false , callback ).setCount (1 );
23892389
23902390 if (j .isAppJoin () == false ) { //除了 @ APP JOIN,其它都是 SQL JOIN,则副表要这样配置
2391+ if (joinConfig .getDatabase () == null ) {
2392+ joinConfig .setDatabase (config .getDatabase ()); //解决主表 JOIN 副表,引号不一致
2393+ }
2394+ else if (joinConfig .getDatabase ().equals (config .getDatabase ()) == false ) {
2395+ throw new IllegalArgumentException ("主表 " + config .getTable () + " 的 @database:" + config .getDatabase () + " 和它 SQL JOIN 的副表 " + name + " 的 @database:" + joinConfig .getDatabase () + " 不一致!" );
2396+ }
2397+ if (joinConfig .getSchema () == null ) {
2398+ joinConfig .setSchema (config .getSchema ()); //主表 JOIN 副表,默认 schema 一致
2399+ }
2400+ cacheConfig .setDatabase (joinConfig .getDatabase ()).setSchema (joinConfig .getSchema ()); //解决主表 JOIN 副表,引号不一致
2401+
2402+
23912403 if (isQuery ) {
23922404 config .setKeyPrefix (true );
23932405 }
@@ -2396,7 +2408,7 @@ public static AbstractSQLConfig parseJoin(RequestMethod method, AbstractSQLConfi
23962408
23972409 if (j .isLeftOrRightJoin ()) {
23982410 SQLConfig outterConfig = newSQLConfig (method , name , j .getOutter (), null , false , callback );
2399- outterConfig .setMain (false ).setKeyPrefix (true );
2411+ outterConfig .setMain (false ).setKeyPrefix (true ). setDatabase ( joinConfig . getDatabase ()). setSchema ( joinConfig . getSchema ()); //解决主表 JOIN 副表,引号不一致
24002412 j .setOutterConfig (outterConfig );
24012413 }
24022414 }
0 commit comments