Created
November 5, 2015 12:18
-
-
Save sudarshan-webonise/53bd0cd345ed606602e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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