Handling odbc exceptions

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mika
Posts: 20
Joined: Thu 08 May 2014 06:15

Handling odbc exceptions

Post by mika » Tue 11 Jul 2017 07:22

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)

mika
Posts: 20
Joined: Thu 08 May 2014 06:15

Re: Handling odbc exceptions

Post by mika » Tue 11 Jul 2017 07:49

noticed that casting EUnierror.innererror to EODBCError I can get ODBC state but that error code isn't there.

mika
Posts: 20
Joined: Thu 08 May 2014 06:15

Re: Handling odbc exceptions

Post by mika » Tue 11 Jul 2017 08:09

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 ?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Handling odbc exceptions

Post by ViktorV » Wed 12 Jul 2017 13:46

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.

mika
Posts: 20
Joined: Thu 08 May 2014 06:15

Re: Handling odbc exceptions

Post by mika » Fri 14 Jul 2017 05:30

Great! Thanks!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Handling odbc exceptions

Post by ViktorV » Mon 17 Jul 2017 13:40

Thank you for being interested in our products.
Feel free to contact us if you have any further questions about our products.

Post Reply