On 09/05/2011 1:06 PM, Thomas Mueller wrote:
Hi,

What is your use case exactly? Do you have an application that needs
to parse the SQL state?

Well, SQL states are not well defined unfortunately. The following statements:

     drop table test;
     create table test(id int, name varchar(255));
     insert into test(id, name) values(1);

will result in different SQL states:

42564 (HSQLDB: row column count mismatch)
42601 (PostgreSQL: INSERT has more target columns than expressions)
42802 (Derby: The number of values assigned is not the same ...)
21S01 (MySQL: Column count doesn't match value count at row 1)
21S02 (H2: Column count does not match)

Regards,
Thomas

Hi Thomas,

My use-case is as follows: Client issues an HTTP request that leads to a database transaction involving an insert. The insert could fail for two reasons:

1. General database error (unrecoverable). Perhaps "retry later" when service is back up. 2. Client violated integrity constraints (attempted to insert an Employee with an invalid Company id)

In the case of #2, I want to inform the user that the referenced Company no longer exists. I do this by parsing SQLState and if it indicates an integrity violation I return one error message or another. It is important to note that I am returning different HTTP return codes for each case so it is important to be able to differentiate between the two cases. A web client will handle HTTP 500 (INTERNAL SERVER ERROR) different from HTTP 400 (BAD REQUEST).

Is there a better way for me to do this? I would love to avoid all this parsing and portability problems.

Thanks,
Gili

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to