Last active
October 1, 2020 17:20
-
-
Save spillsthrills/31c033e385daff7bee343fdfb7bf0a21 to your computer and use it in GitHub Desktop.
cfscript query return struct MySQL format
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
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