Hi,
Where and how can I track DBError of SQLCA transaction object when I'm using Datastore? In Datawindow there is dberror event but how to do it with datastores?
BR, Hannu
Hi,
Where and how can I track DBError of SQLCA transaction object when I'm using Datastore? In Datawindow there is dberror event but how to do it with datastores?
BR, Hannu
Event / Declaration
Code
Code on new n_ds
Instance variables
PUBLIC:
// Most recent error reported by DBError event
// TIP: Call of_ResetDBError() to clear these data
DWBuffer DBError_Buffer
long DBError_Row
long DBError_SQLDBCode
string DBError_SQLErrText
string DBError_SQLSyntax
DBError event
// Retain error info in DBError_XXX variables
this.DBError_Buffer = Buffer
this.DBError_Row = Row
this.DBError_SQLDBCode = SQLDBCode
this.DBError_SQLErrText = SQLErrText
this.DBError_SQLSyntax = SQLSyntax
PUBLIC of_ResetDBError
// Clear all DBError_XXX variables
this.DBError_Buffer = Primary!
this.DBError_Row = 0
this.DBError_SQLDBCode = 0
this.DBError_SQLErrText = ""
this.DBError_SQLSyntax = ""
And this shows how you can use such functionality:
Code Example
How to ... Use the new n_ds
// FUNCTION of_Process( )
// RETURNS long >= 0: Number of rows processed.
// 0: Error.
long ll_retrieveStatus
n_ds lds_data
lds_data = create n_ds
lds_data.DataObject = "d_MyData"
lds_data.SetTransObject(SQLCA)
lds_data.of_ResetDBError( )
ll_retrieveStatus = lds_data.Retrieve( ... )
if ll_retrieveStatus 0 then
// Error occurred during data retrieval
MessageBox("DB Error During Data Retrieval", &
"Error Code: " + string(lds_data.DBError_SQLDBCode), &
"Error Text: " + lds_data.DBError_SQLErrText, &
Exclamation!)
return ll_retrieveStatus // Data retrieval failed => ABORT
end if
// Data retrieval succeeded => Process data
...
NOTE: It is against best practice (though good for demo) to display message boxes in the middle of "non-visual" code.
ds_kuormakirja kuormakirja
kuormakirja = CREATE ds_kuormakirja
kuormakirja.dataObject = 'dw_kuormakirja'
kuormakirja.setTransObject(SQLCA)
Now that ds_kuormakirja has already dberror event with all necessary error handling I need. And it can be adjusted for special needs. So simple and I have never thought about it.
Thanks a lot for the help!