Page 1 of 1

Handling odbc exceptions

Posted: Tue 11 Jul 2017 07:22
by mika
Hi,
I have Actian PSQL which I use trough unidac / ODBC provider. Is there anyway to get ODBC error code / SQLstate in case of exception?
Eunierror seems to be allways -1.
Bellow is odbc trace

Code: Select all

errortest       260-1480	ENTER SQLGetDiagRecW 
		SQLSMALLINT                  3 <SQL_HANDLE_STMT>
		SQLHANDLE           0x00709270
		SQLSMALLINT                  1 
		SQLWCHAR *          0x0018F148
		SQLINTEGER *        0x0018F1AC
		SQLWCHAR *          0x00709B38 
		SQLSMALLINT               8192 
		SQLSMALLINT *       0x0018F1AA

errortest       260-1480	EXIT  SQLGetDiagRecW  with return code 0 (SQL_SUCCESS)
		SQLSMALLINT                  3 <SQL_HANDLE_STMT>
		SQLHANDLE           0x00709270
		SQLSMALLINT                  1 
		SQLWCHAR *          0x0018F148 [       5] "HY000"  <-- I WAN'T THIS  ********
		SQLINTEGER *        0x0018F1AC (-4994)  <-- AND THIS ********
		SQLWCHAR *          0x00709B38 [     150] "[Pervasive][ODBC Client Interface][LNA][PSQL][SQL Engine][Data Record Manager]The record has a key field containing a duplicate value(Btrieve Error 5)"
		SQLSMALLINT               8192 
		SQLSMALLINT *       0x0018F1AA (150)

Re: Handling odbc exceptions

Posted: Tue 11 Jul 2017 07:49
by mika
noticed that casting EUnierror.innererror to EODBCError I can get ODBC state but that error code isn't there.

Re: Handling odbc exceptions

Posted: Tue 11 Jul 2017 08:09
by mika
Okay,
some more research ...
Wrote my own exception classs

Code: Select all

EOwnODBCError = class( EDAError)
  private
    FState: string;
    FNativeErrorCode: integer;
  public
    property nativeerrorCode: Integer read fnativeErrorCode; 
    property State: string read FState;
  end;
and then typecast EOdbcError to EOwnOdbcError ...
Will create unit test for this to make sure that future change's will not break it.

Just wondering why ODBCErrorUni.pas / EODBCError.fnativeErrorCode has no public property ?

Re: Handling odbc exceptions

Posted: Wed 12 Jul 2017 13:46
by ViktorV
Thank you for the interest to our product and your contribution in our product development.
We will add the public property NativeErrorCode for the EODBCError class in the next UniDAC build.

Re: Handling odbc exceptions

Posted: Fri 14 Jul 2017 05:30
by mika
Great! Thanks!

Re: Handling odbc exceptions

Posted: Mon 17 Jul 2017 13:40
by ViktorV
Thank you for being interested in our products.
Feel free to contact us if you have any further questions about our products.