Forked from guitrspaz/cfdao.returnID.sublime-snippet
Last active
July 26, 2017 14:45
-
-
Save obxpete/038e7744cea1118b959f25fec1c93aea to your computer and use it in GitHub Desktop.
Creates a query function to return the resulting ID or other numeric value
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
<snippet> | |
<content><![CDATA[/** | |
* @name: ${TM_FILENAME/(.+)\..+|.*/$1/:name}.${1:functionName} | |
* @hint: ${2:Description} | |
* @returns: Numeric record ID | |
* @date: ${3:Date} | |
* @author: $TM_FULLNAME ($TM_EMAIL) | |
*/ | |
${4:public} Numeric function ${1:functionName}( | |
${5} | |
){ | |
var errorStruct={ | |
arguments:arguments, | |
logType:"warning", | |
start:Now(), | |
stackTrace:getStackTrace(), | |
sql:{ | |
string:"", | |
prefix:{} | |
}, | |
result:0 | |
}; | |
try{ | |
transaction action="begin" isolation="read_uncommitted" { | |
var queryService=new Query( | |
name="q${1}", | |
datasource=this.getdsn() | |
); | |
savecontent variable="errorStruct.sql.string"{ | |
WriteOutput(' | |
${6} | |
'); | |
} | |
var queryData=queryService.execute(sql=errorStruct.sql.string); | |
errorStruct.sql.prefix=queryData.getPrefix(); | |
} | |
transaction action="commit"; | |
if( structKeyExists(errorStruct.sql.prefix,'IDENTITYCOL') ){ | |
errorStruct.result=errorStruct.sql.prefix.IDENTITYCOL; | |
} | |
errorStruct.logType="information"; | |
} catch( Any e ){ | |
transaction action="rollback"; | |
errorStruct.logType="error"; | |
errorStruct.cfcatch=e; | |
} | |
errorStruct.end=Now(); | |
errorStruct.diff=DateDiff('s',errorStruct.start,errorStruct.end); | |
if( errorStruct.logType!='information' || this.getdebugMode() ){ | |
createLog( | |
logName=this.getdefaultLog(), | |
logType=errorStruct.logType, | |
functName=this.getcaller()&".${1:functionName}()", | |
args=errorStruct | |
); | |
} | |
return errorStruct.result; | |
} | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>daonumeric</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<scope>text.html.cfc</scope> | |
</snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment