¿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 querySet tSC = ..Adapter.ExecuteUpdateParmArray(.nrows,SQL,.param)
// Check if there is any errorIf$$$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')
??????
}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
Comentarios (0)0
Comments
Nota: Hemo hecho el siguiente código para capturar el error nativo... pero es un poco código chapucero.
// run the querySet tSC = ..Adapter.ExecuteUpdateParmArray(.nrows,SQL,.param)
// Check if there is any errorIf$$$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 recordquit$$$OK
}
else
{
// Generic error... thow excepctionquit tSC
}
}