Recent

Author Topic: SQLcode VS SQLstate  (Read 2857 times)

jormik

  • New member
  • *
  • Posts: 7
    • parolescritte
SQLcode VS SQLstate
« on: July 24, 2014, 12:26:22 pm »
When I try to insert, by an elaborate procedure, in a Firebird table a longer string than the one I defined in the appropriate varchar(xxx) field of the database I obtain this error message:

---------------------------------------------------------------------------
-Dynamic SQL Error
-SQL error code = -303
-arithmetic exception, numeric overflow, or string truncation
-string rigth truncation
---------------------------------------------------------------------------

Moreover, Firebird 2.5.x has deprecated the SQL error codes (without yet eliminate them)  preferring the SQL compliant SQLSTATE code variables, but I have not found the corresponding value of SQLCODE number -303.

I would intercept the problem in a Try...ecc. structure or (better) in a trigger procedure of the database to resolve it. Can anyone help me with a skeleton of the appropriate structure/trigger (better using SQLSTATE)?

Thanks!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: SQLcode VS SQLstate
« Reply #1 on: July 24, 2014, 03:31:54 pm »
Edit: It's probably a conversion to a signed integer while the original error code is unsigned.
Nope sqlcode negative values are errors indeed...

There is no support for sqlstate in the Firebird/Interbase driver.

In your stored procedure / PL/SQL code in the database, you can catch errors with WHEN...ANY, see
http://www.firebirdsql.org/refdocs/langrefupd25-sqlstate.html
« Last Edit: July 24, 2014, 03:34:16 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018