@@ -94,15 +94,15 @@ public abstract class AbstractSQLConfig implements SQLConfig {
9494 TABLE_KEY_MAP .put (SysTable .class .getSimpleName (), SysTable .TABLE_NAME );
9595 TABLE_KEY_MAP .put (SysColumn .class .getSimpleName (), SysColumn .TABLE_NAME );
9696 TABLE_KEY_MAP .put (ExtendedProperty .class .getSimpleName (), ExtendedProperty .TABLE_NAME );
97-
97+
9898 DATABASE_LIST = new ArrayList <>();
9999 DATABASE_LIST .add (DATABASE_MYSQL );
100100 DATABASE_LIST .add (DATABASE_POSTGRESQL );
101101 DATABASE_LIST .add (DATABASE_SQLSERVER );
102102 DATABASE_LIST .add (DATABASE_ORACLE );
103103 }
104-
105-
104+
105+
106106 @ NotNull
107107 @ Override
108108 public String getIdKey () {
@@ -259,7 +259,7 @@ public String getSQLDatabase() {
259259 String db = getDatabase ();
260260 return db == null ? DEFAULT_DATABASE : db ; // "" 表示已设置,不需要用全局默认的 StringUtil.isEmpty(db, false)) {
261261 }
262-
262+
263263 @ Override
264264 public boolean isMySQL () {
265265 return isMySQL (getSQLDatabase ());
@@ -288,7 +288,7 @@ public boolean isOracle() {
288288 public static boolean isOracle (String db ) {
289289 return DATABASE_ORACLE .equals (db );
290290 }
291-
291+
292292 @ Override
293293 public String getQuote () {
294294 return isMySQL () ? "`" : "\" " ;
@@ -303,24 +303,21 @@ public String getSchema() {
303303 * @return
304304 */
305305 @ NotNull
306- public String getSQLSchema (String table ) {
307- String sch = getSchema ();
308- if (sch == null ) { //PostgreSQL 的 pg_class 和 pg_attribute 表好像不属于任何 Schema StringUtil.isEmpty(sch, true)) {
309- //不能强制,SQL Server 在 information_schema 和 sys 中都有 tables 和 columns //强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值
310- if (Table .TAG .equals (table ) || Column .TAG .equals (table )) {
311- return SCHEMA_INFORMATION ; //MySQL, PostgreSQL, SQL Server 都有的
312- }
313- if (SysTable .TAG .equals (table ) || SysColumn .TAG .equals (table )) {
314- return SCHEMA_SYS ; //SQL Server 在 sys 中的属性比 information_schema 中的要全,能拿到注释
315- }
316- if ((PgAttribute .TAG .equals (table ) || PgClass .TAG .equals (table )) ) {
317- return "" ; //PostgreSQL 的 pg_class 和 pg_attribute 表好像不属于任何 Schema
318- }
319-
320- return DEFAULT_SCHEMA ;
306+ public String getSQLSchema () {
307+ String table = getTable ();
308+ //强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值
309+ if (Table .TAG .equals (table ) || Column .TAG .equals (table )) {
310+ return SCHEMA_INFORMATION ; //MySQL, PostgreSQL, SQL Server 都有的
311+ }
312+ if (PgClass .TAG .equals (table ) || PgAttribute .TAG .equals (table )) {
313+ return "" ; //PostgreSQL 的 pg_class 和 pg_attribute 表好像不属于任何 Schema
314+ }
315+ if (SysTable .TAG .equals (table ) || SysColumn .TAG .equals (table ) || ExtendedProperty .TAG .equals (table )) {
316+ return SCHEMA_SYS ; //SQL Server 在 sys 中的属性比 information_schema 中的要全,能拿到注释
321317 }
322-
323- return sch ;
318+
319+ String sch = getSchema ();
320+ return sch == null ? DEFAULT_SCHEMA : sch ;
324321 }
325322 @ Override
326323 public AbstractSQLConfig setSchema (String schema ) {
@@ -358,8 +355,8 @@ public String getSQLTable() {
358355 public String getTablePath () {
359356 String q = getQuote ();
360357
358+ String sch = getSQLSchema ();
361359 String sqlTable = getSQLTable ();
362- String sch = getSQLSchema (sqlTable );
363360
364361 return (StringUtil .isEmpty (sch , true ) ? "" : q + sch + q + "." ) + q + sqlTable + q + ( isKeyPrefix () ? " AS " + getAliasWithQuote () : "" );
365362 }
@@ -2079,7 +2076,7 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
20792076 // for (...) { Call procedure1();\n SQL \n; Call procedure2(); ... }
20802077 // 貌似不需要,因为 ObjecParser 里就已经处理的顺序等,只是这里要解决下 Schema 问题。
20812078
2082- String sch = config .getSQLSchema (config . getSQLTable () );
2079+ String sch = config .getSQLSchema ();
20832080 if (StringUtil .isNotEmpty (config .getProcedure (), true )) {
20842081 String q = config .getQuote ();
20852082 return "CALL " + q + sch + q + "." + config .getProcedure ();
@@ -2275,7 +2272,7 @@ public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table,
22752272 if (StringUtil .isEmpty (database , false ) == false && DATABASE_LIST .contains (database ) == false ) {
22762273 throw new UnsupportedDataTypeException ("@database:value 中 value 错误,只能是 [" + StringUtil .getString (DATABASE_LIST .toArray ()) + "] 中的一种!" );
22772274 }
2278-
2275+
22792276 String schema = request .getString (KEY_SCHEMA );
22802277
22812278 AbstractSQLConfig config = callback .getSQLConfig (method , database , schema , table );
0 commit comments