¿Cómo obtener el error SQL nativo en SQL Outbound adapter?
Hola a todos,
Tenemos una restricción en una base de datos de SQL con un índice único.
Queremos capturar la excepción cuando intenta insertar o actualizar un valor que incumpla la condición del índice único.
// run the query
Set tSC = ..Adapter.ExecuteUpdateParmArray(.nrows,SQL,.param)
// Check if there is any error
If $$$ISERR(tSC)
{
Set msgError = $System.Status.GetErrorText(tSC)
// Check here if the native error code is 2601 (Cannot insert duplicate key row into object 'MYPATIENTS' with unique index 'UQ_UNIQUE_INDEX')
??????
}
ObjectScriptObjectScript
He intentado capturar el valor de ..Adapter.%SQLCODE, pero está vacío
¿Está este código oculto en la variable tSC? Me explico, de la misma forma que pueda capturar el texto del error usando la clase $System.Status, ¿Hay algún método para capturar el error nativo?
Saludos cordiales
Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1.3 (Build 389U) Wed Feb 15 2023 14:50:06 EST
Ir a la publicación original, escrita por @Kurro Lopez
Nota: Hemo hecho el siguiente código para capturar el error nativo... pero es un poco código chapucero.
// run the query Set tSC = ..Adapter.ExecuteUpdateParmArray(.nrows,SQL,.param) // Check if there is any error If $$$ISERR(tSC) { Set msgError = $System.Status.GetErrorText(tSC) // Check here if the native error code is 2601 (Cannot insert duplicate key row into object 'MYPATIENTS' with unique index 'UQ_UNIQUE_INDEX') if $FIND(msgError, "[2601]") > 0 { // This is a insert/update that violates the unique code // remove duplicate record quit $$$OK } else { // Generic error... thow excepction quit tSC } }