From 72956f4a49480609a3b399c90639f8c0e859d78c Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 12 Jul 2021 09:45:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9oracle=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86=201=E3=80=81=E8=A1=A8=E5=88=AB=E5=90=8DAS?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86=202=E3=80=81JOIN=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2SELECT=E5=90=8E=E7=BC=BA=E5=B0=91=E7=A9=BA=E6=A0=BC?= =?UTF-8?q?=E5=BC=95=E8=B5=B7SQL=E9=9D=9E=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/apijson/orm/AbstractSQLConfig.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index 1b63d9ba..e1884b94 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -589,7 +589,9 @@ public abstract class AbstractSQLConfig implements SQLConfig { String sch = getSQLSchema(); String sqlTable = getSQLTable(); - return (StringUtil.isEmpty(sch, true) ? "" : q + sch + q + ".") + q + sqlTable + q + ( isKeyPrefix() ? " AS " + getAliasWithQuote() : ""); + //兼容Oracle删除表别名AS关键字 by enjoy + //return (StringUtil.isEmpty(sch, true) ? "" : q + sch + q + ".") + q + sqlTable + q + ( isKeyPrefix() ? " AS " + getAliasWithQuote() : ""); + return (StringUtil.isEmpty(sch, true) ? "" : q + sch + q + ".") + q + sqlTable + q + ( isKeyPrefix() ? " " + getAliasWithQuote() : ""); } @Override public AbstractSQLConfig setTable(String table) { //Table已经在Parser中校验,所以这里不用防SQL注入 @@ -882,7 +884,9 @@ public abstract class AbstractSQLConfig implements SQLConfig { // return (hasPrefix ? " ORDER BY " : "") + StringUtil.concat(order, joinOrder, ", "); // } - if (getCount() > 0 && (isOracle() || isSQLServer() || isDb2())) { // Oracle, SQL Server, DB2 的 OFFSET 必须加 ORDER BY + //oracle order by异常,删除isOracle() by enjoy + if (getCount() > 0 && (isSQLServer() || isDb2())) { // Oracle, SQL Server, DB2 的 OFFSET 必须加 ORDER BY + //if (getCount() > 0 && (isOracle() || isSQLServer() || isDb2())) { // Oracle, SQL Server, DB2 的 OFFSET 必须加 ORDER BY // String[] ss = StringUtil.split(order); if (StringUtil.isEmpty(order, true)) { //SQL Server 子查询内必须指定 OFFSET 才能用 ORDER BY @@ -2663,7 +2667,9 @@ public abstract class AbstractSQLConfig implements SQLConfig { String column = config.getColumnString(); if (config.isOracle()) { //When config's database is oracle,Using subquery since Oracle12 below does not support OFFSET FETCH paging syntax. - return explain + "SELECT * FROM (SELECT"+ (config.getCache() == JSONRequest.CACHE_RAM ? "SQL_NO_CACHE " : "") + column + " FROM " + getConditionString(column, tablePath, config) + ") " + config.getLimitString(); + //oracle SELECT缺少空格引起sql非法,by enjoy + return explain + "SELECT * FROM (SELECT "+ (config.getCache() == JSONRequest.CACHE_RAM ? "SQL_NO_CACHE " : "") + column + " FROM " + getConditionString(column, tablePath, config) + ") " + config.getLimitString(); + //return explain + "SELECT * FROM (SELECT"+ (config.getCache() == JSONRequest.CACHE_RAM ? "SQL_NO_CACHE " : "") + column + " FROM " + getConditionString(column, tablePath, config) + ") " + config.getLimitString(); } return explain + "SELECT " + (config.getCache() == JSONRequest.CACHE_RAM ? "SQL_NO_CACHE " : "") + column + " FROM " + getConditionString(column, tablePath, config) + config.getLimitString(); @@ -2784,7 +2790,9 @@ public abstract class AbstractSQLConfig implements SQLConfig { case ">": // RIGHT JOIN jc.setMain(true).setKeyPrefix(false); sql = ( "<".equals(type) ? " LEFT" : (">".equals(type) ? " RIGHT" : " CROSS") ) - + " JOIN ( " + jc.getSQL(isPrepared()) + " ) AS " + //oracle 表别名AS引起非法sql处理,by enjoy + //+ " JOIN ( " + jc.getSQL(isPrepared()) + " ) AS " + + " JOIN ( " + jc.getSQL(isPrepared()) + " ) " + quote + jt + quote + " ON " + quote + jt + quote + "." + quote + j.getKey() + quote + " = " + quote + tt + quote + "." + quote + j.getTargetKey() + quote; jc.setMain(false).setKeyPrefix(true); -- Gitee