archibus.log sql statements
Starting from 2022.02 seems that there is no more option to disable prepared statements globally in web central.
You need to take each parameter one by one and replace the ? value in original sql. If the parameter is of type date the thing is even more complex as you need to convert the date string into date object (to_date(……).
So for debug purposes these are almost useless.
My suggestion is to update DbConnectionImpl class and to adapt these 2 methods and use them instead of just logging the original sql string. This should work for Oracle
private String formatSql(String sqlQuery, Object... parameters) {
String[] parts = sqlQuery.split("\\?");
StringBuilder sb = new StringBuilder();
// This might be wrong if some '?' are used as litteral '?'
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
sb.append(part);
if (i < parameters.length) {
sb.append(formatParameter(parameters[i]));
}
}
return sb.toString();
}
private String formatParameter(Object parameter) {
if (parameter == null) {
return "NULL";
} else {
if (parameter instanceof String) {
return "'" + ((String) parameter).replace("'", "''") + "'";
} else if (parameter instanceof Timestamp) {
return "to_timestamp('" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS").
format(parameter) + "', 'mm/dd/yyyy hh24:mi:ss.ff3')";
} else if (parameter instanceof oracle.sql.DATE) {
return "to_date('" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").
format(((DATE) parameter).timestampValue()) + "', 'mm/dd/yyyy hh24:mi:ss')";
} else if (parameter instanceof Boolean) {
return ((Boolean) parameter).booleanValue() ? "1" : "0";
} else {
return parameter.toString();
}
}
}
Thanks
3
votes
