I am working on one customization through infowindow, in which I have put the Group by clause in Other SQL Clause field in infowindow, which leads and error in some scenario. The problem I have found in testCount() method in infopanel and infowindow class in which this clause is not appended while building the query so m_count and actual line count while rending lines are different.
I have put the code for appending other Sql clause in this method and works fine. Anyone has faced this scenarios and is there any impact of below code :
protected boolean testCount()
{
long start = System.currentTimeMillis();
String dynWhere = getSQLWhere();
StringBuilder sql = new StringBuilder (m_sqlCount);
if (dynWhere.length() > 0)
sql.append(dynWhere); // includes first AND
String countSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables
if (countSql.trim().endsWith("WHERE")) {
countSql = countSql.trim();
countSql = countSql.substring(0, countSql.length() - 5);
}
countSql = MRole.getDefault().addAccessSQL(countSql, getTableName(), MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
// start
if (infoWindow.getOtherClause() != null && infoWindow.getOtherClause().trim().length() > 0) {
String otherClause = infoWindow.getOtherClause();
if (otherClause.indexOf("@") >= 0) {
String s = Env.parseContext(Env.getCtx(), p_WindowNo, otherClause, false, false);
if (s.length() == 0) {
log.severe("Failed to parse other clause. " + otherClause);
} else {
otherClause = s;
}
}
countSql = countSql + " " + otherClause;
}// end
if (log.isLoggable(Level.FINER))
log.finer(countSql);
m_count = -1;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(countSql, null);
setParameters (pstmt, true);
rs = pstmt.executeQuery();
if (rs.next())
m_count = rs.getInt(1);
}
catch (Exception e)
{
log.log(Level.SEVERE, countSql, e);
m_count = -2;
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (log.isLoggable(Level.FINE))
log.fine("#" + m_count + " - " + (System.currentTimeMillis()-start) + "ms");
return true;
} // testCount