fix: select filter crash
This commit is contained in:
parent
1ec881177d
commit
cadb1e7a46
@ -184,10 +184,35 @@ public class SelectCatalogWin {
|
||||
sql += " where " + sFilter;
|
||||
}
|
||||
}
|
||||
String sql2 = " and (";
|
||||
if (!sql.contains("where")) {
|
||||
sql2 = " 1=1 and (";
|
||||
}
|
||||
String sqlContext = "";
|
||||
String sqlBy = "";
|
||||
String sqlWhere = "";
|
||||
//
|
||||
String sql2 = "";
|
||||
// if (!sql.toLowerCase().contains("where")) {
|
||||
// sql2 = " 1=1 and (";
|
||||
// sqlWhere = "";
|
||||
// sqlContext = sql;
|
||||
// } else {
|
||||
// sqlWhere = sql.substring(sql.toLowerCase().indexOf("where"), sql.length());
|
||||
// sqlContext = sql.substring(0, sql.toLowerCase().indexOf("where"));
|
||||
// }
|
||||
//
|
||||
// if (sqlWhere.toLowerCase().contains("group by")) {
|
||||
// sqlBy = sqlWhere.substring(sqlWhere.toLowerCase().lastIndexOf("group by"), sqlWhere.length());
|
||||
// sqlWhere = sqlWhere.substring(0, sqlWhere.toLowerCase().lastIndexOf("group by"));
|
||||
// } else {
|
||||
// if (sql.toLowerCase().contains("order by")) {
|
||||
// sqlBy = sqlWhere.substring(sqlWhere.toLowerCase().lastIndexOf("order by"), sqlWhere.length());
|
||||
// sqlWhere = sqlWhere.substring(0, sqlWhere.toLowerCase().lastIndexOf("order by"));
|
||||
// } else {
|
||||
// sqlBy = "";
|
||||
// sqlWhere = "";
|
||||
// }
|
||||
// }
|
||||
// sqlContext = sqlContext.trim();
|
||||
// sqlBy = sqlBy.trim();
|
||||
|
||||
// sGlobalText
|
||||
if (sGlobalText != null && sGlobalText.length() > 0)
|
||||
sGlobalText = sGlobalText.trim();
|
||||
@ -206,29 +231,44 @@ public class SelectCatalogWin {
|
||||
if (i > 0) {
|
||||
sql2 += " or ";
|
||||
}
|
||||
sql2 += sTableName + sSelectFilter + " like '%" + sGlobalText
|
||||
sql2 += "A." + sSelectFilter + " like '%" + sGlobalText
|
||||
+ "%'";
|
||||
i++;
|
||||
}
|
||||
sql2 += ")";
|
||||
String sSql = sql.toLowerCase();
|
||||
String sSql2 = sql2.toLowerCase();
|
||||
if (sSql.contains("where") || sSql2.contains("where")) {
|
||||
sql += sql2;
|
||||
} else {
|
||||
sql += " where " + sql2;
|
||||
}
|
||||
// sql2 += ")";
|
||||
// if (sql2.length() > 0) {
|
||||
// if (sqlWhere.toLowerCase().contains("where")
|
||||
// || sql2.toLowerCase().contains("where")) {
|
||||
// sqlWhere += " " + sql2;
|
||||
// } else {
|
||||
// sqlWhere += " where " + sql2;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
if (!StringX.isSpace(sOtherWhere)) {
|
||||
String[] array = sOtherWhere.split("&");
|
||||
sql = sql.replace(array[0], array[1]);
|
||||
}
|
||||
sql = sql.trim();
|
||||
sql = sql.replace("\r\n", " ");
|
||||
while (sql.contains(" ")) {
|
||||
sql = sql.replace(" ", " ");
|
||||
}
|
||||
ARE.getLog().info("sql > " + sql);
|
||||
// sqlWhere = sqlWhere.trim();
|
||||
// sqlWhere = sqlWhere.replace("\r\n", " ");
|
||||
// sqlWhere = sqlWhere.replace("\n", " ");
|
||||
// sqlBy = sqlBy.trim();
|
||||
// sqlBy = sqlBy.replace("\r\n", " ");
|
||||
// sqlBy = sqlBy.replace("\n", " ");
|
||||
// sqlContext = sqlContext.trim();
|
||||
// sqlContext = sqlContext.replace("\r\n", " ");
|
||||
// sqlContext = sqlContext.replace("\n", " ");
|
||||
// while (sqlWhere.contains(" ")) {
|
||||
// sqlWhere = sqlWhere.replace(" ", " ");
|
||||
// }
|
||||
// while (sqlContext.contains(" ")) {
|
||||
// sqlContext = sqlContext.replace(" ", " ");
|
||||
// }
|
||||
// while (sqlBy.contains(" ")) {
|
||||
// sqlBy = sqlBy.replace(" ", " ");
|
||||
// }
|
||||
// sql = sqlContext + " " + sqlWhere + " " + sqlBy;
|
||||
// ARE.getLog().info("sql > " + sql);
|
||||
String sPageIndex = request.getParameter("pageIndex");
|
||||
String sLimit = request.getParameter("limit");
|
||||
if (sPageIndex == null)
|
||||
@ -241,10 +281,22 @@ public class SelectCatalogWin {
|
||||
iLimit = Integer.valueOf(sLimit);
|
||||
int pageIndexStart = (iPageIndex) * iLimit;
|
||||
int pageIndexEnd = (iPageIndex + 1) * iLimit;
|
||||
// sql = "SELECT * FROM (" + sql + ") A WHERE tenwaROWNUM BETWEEN "
|
||||
// + pageIndexStart + " AND " + pageIndexEnd;
|
||||
// sql = "SELECT * FROM (" + sql + ") A WHERE tenwaROWNUM BETWEEN "
|
||||
// + pageIndexStart + " AND " + pageIndexEnd;
|
||||
|
||||
|
||||
sql = "SELECT * FROM (" + sql + ") A limit " + pageIndexStart + "," + pageIndexEnd;
|
||||
if (sql2.length() > 0) {
|
||||
if (sql2.toLowerCase().contains("where")) {
|
||||
sql = "SELECT * FROM (" + sql + ") A " + sql2 + " limit " + pageIndexStart + "," + pageIndexEnd;
|
||||
} else {
|
||||
sql = "SELECT * FROM (" + sql + ") A WHERE " + sql2 + " limit " + pageIndexStart + "," + pageIndexEnd;
|
||||
}
|
||||
} else {
|
||||
sql = "SELECT * FROM (" + sql + ") A limit " + pageIndexStart + "," + pageIndexEnd;
|
||||
}
|
||||
ARE.getLog().info("sql > " + sql);
|
||||
// sql = "SELECT * FROM (" + sql + ") A " + sql2 + " limit " + pageIndexStart + ","
|
||||
// + pageIndexEnd;
|
||||
String[] aSelReturnValue = sSelReturnValue.split("@");
|
||||
String[] aSelFieldName = sSelFieldName.split(",");
|
||||
String[] aSelHideField = sSelHideField.split(",");
|
||||
@ -252,7 +304,7 @@ public class SelectCatalogWin {
|
||||
|
||||
String sql1 = sql.toLowerCase().replace("{lci,contract}", " ");
|
||||
List<Map<String, Object>> hms = new ArrayList<Map<String, Object>>();
|
||||
if (sql1.startsWith("select")) {
|
||||
if (sql1.toLowerCase().startsWith("select")) {
|
||||
ASResultSet rs = null;
|
||||
SqlObject sqlObject = new SqlObject(sql1);
|
||||
rs = Sqlca.getResultSet(sqlObject);
|
||||
@ -294,7 +346,7 @@ public class SelectCatalogWin {
|
||||
}
|
||||
// ÏÔʾÃû ,
|
||||
try {
|
||||
col.put("display", aSelFieldName[i-1]);
|
||||
col.put("display", aSelFieldName[i - 1]);
|
||||
} catch (Exception e) {
|
||||
ARE.getLog().error(e);
|
||||
col.put("display", "");
|
||||
@ -358,32 +410,33 @@ public class SelectCatalogWin {
|
||||
}
|
||||
String sSqlContext = sSql;
|
||||
sSqlContext = sSqlContext.toLowerCase();
|
||||
if (sSqlContext.contains("group by")) {
|
||||
String sSqlContextGroupAfter = sSqlContext.substring(
|
||||
sSqlContext.lastIndexOf("group by")).trim();
|
||||
String sSqlContextGroupBefore = sSqlContext.substring(0,
|
||||
sSqlContext.lastIndexOf("group by")).trim();
|
||||
//如果此sql 前部分已经包含where条件,且不在select子查询中,则and相接
|
||||
if (sSqlContextGroupBefore.contains(" where ") && !sSqlContextGroupBefore.contains(")")) {
|
||||
sSqlContextGroupBefore += " and 1=2";
|
||||
} else {
|
||||
sSqlContextGroupBefore += " where 1=2";
|
||||
}
|
||||
sSql = sSqlContextGroupBefore + " " + sSqlContextGroupAfter;
|
||||
} else {
|
||||
if (sSqlContext.contains("order by")) {
|
||||
String sSqlContextOrderAfter = sSqlContext.substring(
|
||||
sSqlContext.lastIndexOf("order by")).trim();
|
||||
String sSqlContextOrderBefore = sSqlContext.substring(0,
|
||||
sSqlContext.lastIndexOf("order by")).trim();
|
||||
if (sSqlContextOrderBefore.contains(" where ")) {
|
||||
sSqlContextOrderBefore += " and 1=2";
|
||||
} else {
|
||||
sSqlContextOrderBefore += " where 1=2";
|
||||
}
|
||||
sSql = sSqlContextOrderBefore + " " + sSqlContextOrderAfter;
|
||||
}
|
||||
}
|
||||
// if (sSqlContext.contains("group by")) {
|
||||
// String sSqlContextGroupAfter = sSqlContext.substring(
|
||||
// sSqlContext.lastIndexOf("group by")).trim();
|
||||
// String sSqlContextGroupBefore = sSqlContext.substring(0,
|
||||
// sSqlContext.lastIndexOf("group by")).trim();
|
||||
// // 如果此sql 前部分已经包含where条件,且不在select子查询中,则and相接
|
||||
// if (sSqlContextGroupBefore.contains(" where ")
|
||||
// && !sSqlContextGroupBefore.contains(")")) {
|
||||
// sSqlContextGroupBefore += " and 1=2";
|
||||
// } else {
|
||||
// sSqlContextGroupBefore += " where 1=2";
|
||||
// }
|
||||
// sSql = sSqlContextGroupBefore + " " + sSqlContextGroupAfter;
|
||||
// } else {
|
||||
// if (sSqlContext.contains("order by")) {
|
||||
// String sSqlContextOrderAfter = sSqlContext.substring(
|
||||
// sSqlContext.lastIndexOf("order by")).trim();
|
||||
// String sSqlContextOrderBefore = sSqlContext.substring(0,
|
||||
// sSqlContext.lastIndexOf("order by")).trim();
|
||||
// if (sSqlContextOrderBefore.contains(" where ")) {
|
||||
// sSqlContextOrderBefore += " and 1=2";
|
||||
// } else {
|
||||
// sSqlContextOrderBefore += " where 1=2";
|
||||
// }
|
||||
// sSql = sSqlContextOrderBefore + " " + sSqlContextOrderAfter;
|
||||
// }
|
||||
// }
|
||||
String sFilters = "";
|
||||
String[] aSelFieldName = sStr2.split(",");
|
||||
ASResultSet rs = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user