diff --git a/lib/connection.js b/lib/connection.js index cc23343aa..f11ecf05c 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -551,6 +551,11 @@ Connection.prototype.parseE = function(buffer, length) { msg.internalPosition = fields.p; msg.internalQuery = fields.q; msg.where = fields.W; + msg.schema = fields.s; + msg.table = fields.t; + msg.column = fields.c; + msg.dataType = fields.d; + msg.constraint = fields.n; msg.file = fields.F; msg.line = fields.L; msg.routine = fields.R; diff --git a/test/integration/client/query-error-handling-tests.js b/test/integration/client/query-error-handling-tests.js index 2b708b8d8..6320beff7 100644 --- a/test/integration/client/query-error-handling-tests.js +++ b/test/integration/client/query-error-handling-tests.js @@ -35,3 +35,50 @@ test('error during query execution', function() { })); })); }); + +test('9.3 column error fields', function() { + var client = new Client(helper.args); + client.connect(assert.success(function() { + helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) { + if(!isGreater) { + console.log('skip 9.3 error field on older versions of postgres'); + return client.end(); + } + + client.query('DROP TABLE IF EXISTS column_err_test'); + client.query('CREATE TABLE column_err_test(a int NOT NULL)'); + client.query('INSERT INTO column_err_test(a) VALUES (NULL)', function (err) { + assert.equal(err.severity, 'ERROR'); + assert.equal(err.code, '23502'); + assert.equal(err.schema, 'public'); + assert.equal(err.table, 'column_err_test'); + assert.equal(err.column, 'a'); + return client.end(); + }); + })); + })); +}); + +test('9.3 constraint error fields', function() { + var client = new Client(helper.args); + client.connect(assert.success(function() { + helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) { + if(!isGreater) { + console.log('skip 9.3 error field on older versions of postgres'); + return client.end(); + } + + client.query('DROP TABLE IF EXISTS constraint_err_test'); + client.query('CREATE TABLE constraint_err_test(a int PRIMARY KEY)'); + client.query('INSERT INTO constraint_err_test(a) VALUES (1)'); + client.query('INSERT INTO constraint_err_test(a) VALUES (1)', function (err) { + assert.equal(err.severity, 'ERROR'); + assert.equal(err.code, '23505'); + assert.equal(err.schema, 'public'); + assert.equal(err.table, 'constraint_err_test'); + assert.equal(err.constraint, 'constraint_err_test_pkey'); + return client.end(); + }); + })); + })); +}); \ No newline at end of file