5959import zuo .biao .apijson .StringUtil ;
6060import zuo .biao .apijson .server .exception .NotExistException ;
6161import zuo .biao .apijson .server .model .Column ;
62+ import zuo .biao .apijson .server .model .PgAttribute ;
63+ import zuo .biao .apijson .server .model .PgClass ;
6264import zuo .biao .apijson .server .model .Table ;
6365
6466/**config sql for JSON Request
@@ -75,8 +77,10 @@ public abstract class AbstractSQLConfig implements SQLConfig {
7577 public static final Map <String , String > TABLE_KEY_MAP ;
7678 static {
7779 TABLE_KEY_MAP = new HashMap <String , String >();
78- TABLE_KEY_MAP .put (Table .class .getSimpleName (), Table .TAG );
79- TABLE_KEY_MAP .put (Column .class .getSimpleName (), Column .TAG );
80+ TABLE_KEY_MAP .put (Table .class .getSimpleName (), Table .TABLE_NAME );
81+ TABLE_KEY_MAP .put (Column .class .getSimpleName (), Column .TABLE_NAME );
82+ TABLE_KEY_MAP .put (PgAttribute .class .getSimpleName (), PgAttribute .TABLE_NAME );
83+ TABLE_KEY_MAP .put (PgClass .class .getSimpleName (), PgClass .TABLE_NAME );
8084 }
8185
8286 @ NotNull
@@ -219,7 +223,7 @@ public AbstractSQLConfig setSchema(String schema) {
219223 if (schema != null ) {
220224 String quote = getQuote ();
221225 String s = schema .startsWith (quote ) && schema .endsWith (quote ) ? schema .substring (1 , schema .length () - 1 ) : schema ;
222- if (StringUtil .isName (s ) == false ) {
226+ if (StringUtil .isEmpty ( s , true ) == false && StringUtil . isName (s ) == false ) {
223227 throw new IllegalArgumentException ("@schema:value 中value必须是1个单词!" );
224228 }
225229 }
@@ -252,15 +256,19 @@ public String getTablePath() {
252256
253257 String sqlTable = getSQLTable ();
254258 String sch = getSchema ();
255- if (StringUtil .isEmpty (sch , true )) {
256- if ((Table .TAG .equals (sqlTable ) || Column .TAG .equals (sqlTable )) ) {
259+ if (sch == null ) { //PostgreSQL 的 pg_class 和 pg_attribute 表好像不属于任何 Schema StringUtil.isEmpty(sch, true)) {
260+ if ((Table .TABLE_NAME .equals (sqlTable ) || Column .TABLE_NAME .equals (sqlTable )) ) {
257261 sch = SCHEMA_INFORMATION ;
258- } else {
262+ }
263+ else if ((PgAttribute .TABLE_NAME .equals (sqlTable ) || PgClass .TABLE_NAME .equals (sqlTable )) ) {
264+ sch = "" ;
265+ }
266+ else {
259267 sch = DEFAULT_SCHEMA ;
260268 }
261269 }
262270
263- return q + sch + q + "." + q + sqlTable + q + ( isKeyPrefix () ? " AS " + getAlias () : "" );
271+ return ( StringUtil . isEmpty ( sch , true ) ? "" : q + sch + q + "." ) + q + sqlTable + q + ( isKeyPrefix () ? " AS " + getAlias () : "" );
264272 }
265273 @ Override
266274 public AbstractSQLConfig setTable (String table ) { //Table已经在Parser中校验,所以这里不用防SQL注入
0 commit comments