mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Merge pull request #712 from rpedela/master
#701 Expose error fields added in PG 9.3.
This commit is contained in:
commit
ba84f30b31
@ -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;
|
||||
|
||||
@ -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();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user