Skip to content

Instantly share code, notes, and snippets.

@sudarshan-webonise
Created November 5, 2015 12:18
Show Gist options
  • Save sudarshan-webonise/53bd0cd345ed606602e5 to your computer and use it in GitHub Desktop.
Save sudarshan-webonise/53bd0cd345ed606602e5 to your computer and use it in GitHub Desktop.
@Override
String getCSVRecordForReport(Report report) {
String reportSql = getReportSql(report.getReportId())
log.debug("${reportSql}")
def query = dslContextReadOnly.query(reportSql)
query = bindParams(query, reportSql, report.reportParamsMap)
String csvResult = this.dslContextReadOnly.fetch(query as ReaultQuery).formatCSV()
return csvResult
}
private Query bindParams(Query query, String sql, Map<String, String> parameters) {
parameters.each {
Matcher matcher = Pattern.compile("@" + it.getKey()).matcher(sql);
while (matcher.find()) {
String value = it.getValue()
if (!StringUtils.isNumeric(value) && value.indexOf("\'") < 0) {
value = String.format("'%s'", value)
}
query.bind("${it.key}", value)
}
}
return query
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment