In SQLRPGLE programming I have seen that the SQLSTATE and SQLCODE being used in several areas in order to catch an error in the sql statement. My query is what is the difference between SQLSTATE and SQLCODE because I see them to be used for similar purpose. Is there any special scenario where SQLSTATE or SQLCODE is used or are they the same?
Asked
Active
Viewed 641 times
1
-
During SQLRPGLE programming using SQLCODE is more simple.. [Look here](https://www.ibm.com/docs/en/i/7.3?topic=codes-listing-sqlstate-values) ... SQLCode Zero (no error) can have more SQLSTATE (with only a warning) – Nifriz Feb 14 '22 at 09:47
-
Unfortunately, I don't think it's clear which is more simple. The [docs](https://www.ibm.com/docs/en/i/7.4?topic=codes-sqlcode-sqlstate-concepts) actually say "SQLSTATE is related to SQLCODE. Every SQLSTATE has one or more SQLCODEs associated with it. An SQLSTATE can refer to more than one SQLCODE." Which sounds kind of like the opposite of what Nifriz is saying. However, that is an oversimplification as well. Some SQLCODE values correspond to more than one SQLSTATE (as Nifriz points out). So you really have to just look at the meanings and decide what you are really testing for. – John Y Feb 14 '22 at 15:25
1 Answers
4
Short version, SQLCODE is DB2 for IBM i specific, SQLSTATE is standard
See here
SQLSTATE is the preferred standard return code. It provides application programs with return codes for common error conditions found among the DB2® products.
SQLSTATE values are consistent with the SQLSTATE specifications that are contained in the SQL 1999 standard.
-
you should try to include relevant quotes, to back up your summary and in case the link goes bad. – Charles Feb 14 '22 at 15:33
-