Question
· Oct 17, 2017

How to wrap %SQLCODE into %Status

I have a method would return %Status,

this method would run some sql queries and if the execution of these queries fail, I would like to return asap.

So how could I wrap the %SQLCODE into a %Status variable?

Thank for your help.

Discussion (5)0
Log in or sign up to continue

Another variants:

#Dim sc As %Status $$$OK
s:SQLCODE sc ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg).AsStatus()
s:SQLCODE sc $system.Error.FromSQLCode(SQLCODE,%msg).Status

It should also be noted the %sqlcontext, so final code will look as follows:

if SQLCODE {
 set:$IsObject($get(%sqlcontext)) %sqlcontext.%SQLCODE=SQLCODE%sqlcontext.%Message=$get(%msg)
 set sc=$$$ERROR($$$SQLCode,SQLCODE,$g(%msg))
else set sc=$$$OK }