1. Yuri Denshchik
  2. PowerBuilder
  3. Tuesday, 17 April 2018 17:41 PM UTC

Is there a way to capture SQL error when run datastore.update() return -1? For some reason SQLCA.SQLCode and SQLErrorText are empty  when ds failed to Insert or Update a row.

Thanks,

Yuri

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 17 April 2018 21:02 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Yuri,

I always use a ds_base custom datastore class instead of the system class. For your case I would add the following instance variables and event code:

INSTANCE VARIABLES
PUBLIC:
boolean​  DisplayDBError     // Governs DBError return value
​DWBuffer DBError_Buffer
long     DBError_Row
long     DBError_SQLDBCode
string   DBError_SQLErrText
string   DBError_SQLSyntax
​
​EVENT DBError
this.DBError_Buffer = Buffer
this.DBError_Row = Row
this.DBError_SQLDBCode = SQLDBCode
this.DBError_SQLErrText = SQLErrText
this.DBError_SQLSyntax = SQLSyntax

​if this.DisplayDBError then return 0 else return 1

ANYWHERE ELSE IN CODE
ds_base lds_data
lds_data = create ds_base
​lds_data.DataObject = "d_myData"
lds_data.Set​TransObject(SQLCA)
...
IF lds_data.Update( ) < 0 THEN
   // Error details =>
   // ​lds_data.DBError_SQLDBCode, lds_data.DBError_SQLErrText, ...
END IF

HTH /Michael

Comment
  1. Michael Kramer
  2. Tuesday, 17 April 2018 21:08 PM UTC
I missed >>> In your scenario, I expect to see SQLDBCode = -3 (Row changed between retrieve and update).



DW engine expects SQLNRows = 1 for each UPDATE/DELETE but DBMS returned SQLNRows = 0.

  1. Helpful
  1. Yuri Denshchik
  2. Tuesday, 17 April 2018 22:50 PM UTC
Perfect!



Thank you Michael

  1. Helpful
There are no comments made yet.
Georgios Papageorgiou Accepted Answer Pending Moderation
  1. Tuesday, 17 April 2018 19:18 PM UTC
  2. PowerBuilder
  3. # 1

Hi,

 

You can Insert -> Object -> "datastore (or userobject - n_ds)" into your Window/userobject

 

You have now access to the dberror event ( and sqlpreview ) on the inserted object

 

Regards

Georgios

 

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.