Skip to content

Instantly share code, notes, and snippets.

@spillsthrills
Last active October 1, 2020 17:20
Show Gist options
  • Save spillsthrills/31c033e385daff7bee343fdfb7bf0a21 to your computer and use it in GitHub Desktop.
Save spillsthrills/31c033e385daff7bee343fdfb7bf0a21 to your computer and use it in GitHub Desktop.
cfscript query return struct MySQL format
public struct function readTable(required numeric id) {
var response = {
data:"",
recordCount:0,
errorMsg:""
};
var params = {};
var qryRes = {};
var options = {};
var sql = "";
try {
params.id = { value=arguments.id, cfsqltype="cf_sql_integer" };
options = { result="qryRes", dataSource=<my datasource> };
sql = "SELECT
`myTable`.`ID`,
`myTable`.`someColumn`
FROM `mySchema`.`myTable`
WHERE 1=1
AND `myTable`.`ID`= :id;
sql &= ";";
response.data = queryExecute(sql, params, options);
response.recordCount = qryRes.recordCount;
} catch (any excpt) {
response.errorMsg = excpt.message & " |readMyTable| " & sql;
} finally {
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment