Skip to content

DB2 errors have inconsistent name for SQL state #1016

@asselin

Description

@asselin

Summary

The errors thrown by the library have an inconsistent property name for the SQL state value. In some cases, it uses "state", and in other cases, it uses "sqlstate". The library should standardize on one or the other.

Examples:

Executing an insert query that tries to insert a duplicate row, the SQL state is returned in "state":

{ error: "[ibm_db] SQL_ERROR", sqlcode: -803, message: "[IBM][CLI Driver][DB2] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by \"PRINCSG1\" constrains table \"0000004D02\" from having duplicate values for the index key. SQLSTATE=23505\n", state: "23505", resultset: [ ], }

It looks like those errors are created in odbc.js between lines https://github.com/ibmdb/node-ibm_db/blob/master/lib/odbc.js#L531 and https://github.com/ibmdb/node-ibm_db/blob/master/lib/odbc.js#L631.

Connection errors created by the Node js lib itself use sqlstate, e.g.

var connError = {

var connError = { message: "Connection not open.", sqlstate: "08001", sqlcode: -30081 }; 

and

sqlca = {sqlstate: "08001", sqlcode : -30081};

 if (!self.connected) { sqlca = {sqlstate: "08001", sqlcode : -30081}; deferred ? deferred.reject(connError) : cb(connError, [], sqlca); return next(); } 

IMHO, given that the bulk of errors that are handled are probably ones returned by DB2 rather than the connection errors created by the library, I'd recommend standardizing on "state".

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions