// ===================================================
// Now we complete the sql statement that is associated
// with this tabular report type. The raw sql statement is provided in
// a config file, but this must be modified before execution.
// ===================================================
SuperString myStatement = new SuperString(sql);
log.debug("Config Query statement before param substitution:" + myStatement);
// ===================================================
// Modify sql statement from the config.
// - If there is no "order by" clause in config file, then order by queryjoin.name
// so that queryResult ordering will match ObjectKeys ordering.
// - Replace any paramters in sql statement with runtime values passed via criteria inputs
// order by clauses at run time.
// - If objectKeys is not null, substitute $queryid with myQueryId governing the join.
// ===================================================
log.debug("Does Config Query have ORDER by clause, not if this index is -1:"
+ (myStatement.toString().toUpperCase().indexOf("ORDER BY ")));
// modified by aleks
if ((myStatement.toString().toUpperCase().indexOf("ORDER BY ")) == - 1 && myQueryId > 0)
{
log.debug("sindex not found, so append");
myStatement.append("\n ORDER BY $orderByClause ");
}
// modified by aleks
try
{
String oneCriteriaCode = null;
for (int i = 0; i < criteria.length; i++)
{
oneCriteriaCode = criteria[i].getAttribute("name");
// ==================================
// Replace 0 or more occurancees of criteria code parameter with value
// ==================================
while (myStatement.toString().indexOf("$" + oneCriteriaCode) != - 1)
{
myStatement = new SuperString(myStatement.replace("$" + oneCriteriaCode,
// BUEROBYTE: Don't cast to String, convert to String!
// (String) criteriaInput.get(oneCriteriaCode)));
criteriaInput.get(oneCriteriaCode).toString()));
// BUEROBYTE
}
// BUEROBYTE: Replace '%'-paramters with a '?' for prepared statements.
while (myStatement.toString().indexOf("%" + oneCriteriaCode) != - 1)
{
myStatement = new SuperString(myStatement.replace("%" + oneCriteriaCode, "?"));
}
// BUEROBYTE
}
}
catch (ConfigurationException ce)
{
throw new QueryException(ce);
}
myStatement = new SuperString(myStatement.replace("$orderByClause", "queryJoin.name"));
myStatement = new SuperString(myStatement.replace("$queryid", (new Integer(myQueryId)).toString()));
//Note: SuperString replace does not change "this", but only return value. Is that desirable?
return myStatement;
}