@Test public void testRemoveOrderBy02() { String sql = "select a,b from c where a=1 $$order by a asc"; Assert.assertEquals("select a,b from c where a=1 ", SqlObject.removeOrderBy(sql)); }
public static String removeOrderBy(String queryString) { int index = queryString.indexOf("!!order"); if (index != -1) { return queryString.substring(0, index); } else { int last_index_or = queryString.lastIndexOf("order by"); int last_index_ = queryString.lastIndexOf(")"); if (last_index_ > last_index_or) { return queryString; } Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); } }
SqlObject extends PagingQueryConfig { public static String removeOrderBy(String queryString) { int index = queryString.indexOf("!!order"); if (index != -1) { return queryString.substring(0, index); } else { int last_index_or = queryString.lastIndexOf("order by"); int last_index_ = queryString.lastIndexOf(")"); if (last_index_ > last_index_or) { return queryString; } Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); } } }
SqlObject extends PagingQueryConfig { public static String removeOrderBy(String queryString) { int index = queryString.indexOf("!!order"); if (index != -1) { return queryString.substring(0, index); } else { int last_index_or = queryString.lastIndexOf("order by"); int last_index_ = queryString.lastIndexOf(")"); if (last_index_ > last_index_or) { return queryString; } Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); } } SqlObject();  SqlObject(String sql, List<Object> args); }
SqlObject extends PagingQueryConfig { public static String removeOrderBy(String queryString) { int index = queryString.indexOf("!!order"); if (index != -1) { return queryString.substring(0, index); } else { int last_index_or = queryString.lastIndexOf("order by"); int last_index_ = queryString.lastIndexOf(")"); if (last_index_ > last_index_or) { return queryString; } Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); } } SqlObject();  SqlObject(String sql, List<Object> args); String getNativeSql(Condition condition); String getNativeSql(); String getSql(Condition condition); String getSql(); SqlObject<T> setSql(String sql); RowMapper<T> getRowMapper(); SqlObject<T> setRowMapper(RowMapper<T> rowMapper); SqlObject<T> setSelect(String select); String getSelect(); String getFrom(); SqlObject<T> setFrom(String from); SqlObject<T> setWhere(String where); void setGroupBy(String groupBy); SqlObject<T> setOrderBy(String orderBy); String getCountSql(Condition condition); String getFromWhereSql(Condition condition); String getFromWhereSql(); static String removeOrderBy(String queryString); static String removeSelect(String queryString); List<Object> getArgs(); SqlObject<T> setArgs(List<Object> args); @Override List<Object> getTotalnumQueryParams(Condition condition); @Override String getQueryString(Condition condition); @Override String getTotalnumQueryString(Condition condition); }
SqlObject extends PagingQueryConfig { public static String removeOrderBy(String queryString) { int index = queryString.indexOf("!!order"); if (index != -1) { return queryString.substring(0, index); } else { int last_index_or = queryString.lastIndexOf("order by"); int last_index_ = queryString.lastIndexOf(")"); if (last_index_ > last_index_or) { return queryString; } Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryString); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); } } SqlObject();  SqlObject(String sql, List<Object> args); String getNativeSql(Condition condition); String getNativeSql(); String getSql(Condition condition); String getSql(); SqlObject<T> setSql(String sql); RowMapper<T> getRowMapper(); SqlObject<T> setRowMapper(RowMapper<T> rowMapper); SqlObject<T> setSelect(String select); String getSelect(); String getFrom(); SqlObject<T> setFrom(String from); SqlObject<T> setWhere(String where); void setGroupBy(String groupBy); SqlObject<T> setOrderBy(String orderBy); String getCountSql(Condition condition); String getFromWhereSql(Condition condition); String getFromWhereSql(); static String removeOrderBy(String queryString); static String removeSelect(String queryString); List<Object> getArgs(); SqlObject<T> setArgs(List<Object> args); @Override List<Object> getTotalnumQueryParams(Condition condition); @Override String getQueryString(Condition condition); @Override String getTotalnumQueryString(Condition condition);  }