Skip to content

Commit d3ec938

Browse files
committed
Fix remainder of error tests
1 parent 2add7e3 commit d3ec938

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ test-connection:
3636
test-missing-native:
3737
@echo "***Testing optional native install***"
3838
@rm -rf node_modules/pg-native
39+
@rm -rf node_modules/libpq
3940
@node test/native/missing-native.js
4041
@rm -rf node_modules/pg-native
42+
@rm -rf node_modules/libpq
4143

4244
node_modules/pg-native/index.js:
4345
@npm i pg-native

lib/native/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Client.prototype.connect = function(cb) {
109109
// }
110110
Client.prototype.query = function(config, values, callback) {
111111
if (typeof config.submit == 'function') {
112+
// accept query(new Query(...), (err, res) => { }) style
113+
if (typeof values == 'function') {
114+
config.callback = values;
115+
}
112116
this._queryQueue.push(config);
113117
this._pulseQueryQueue();
114118
return config;

lib/native/query.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ var util = require('util');
1111
var utils = require('../utils');
1212
var NativeResult = require('./result');
1313

14-
var NativeQuery = module.exports = function(config, values) {
14+
var NativeQuery = module.exports = function(config, values, callback) {
1515
EventEmitter.call(this);
16-
if (typeof config == 'string') {
17-
config = {
18-
text: config,
19-
values: values,
20-
};
21-
}
16+
config = utils.normalizeQueryConfig(config, values, callback);
2217
this.text = config.text;
2318
this.values = config.values;
2419
this.name = config.name;

test/integration/client/query-error-handling-prepared-statement-tests.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,29 @@ test('client end during query execution of prepared statement', function() {
6464
var client = new Client(helper.args);
6565
client.connect(assert.success(function() {
6666
var sleepQuery = 'select pg_sleep($1)';
67-
var query1 = client.query(new Query({
67+
68+
var queryConfig = {
6869
name: 'sleep query',
6970
text: sleepQuery,
70-
values: [5] },
71-
assert.calls(function(err, result) {
72-
assert.equal(err.message, 'Connection terminated');
73-
})));
71+
values: [5],
72+
}
7473

74+
var queryInstance = new Query(queryConfig, assert.calls(function (err, result) {
75+
assert.equal(err.message, 'Connection terminated');
76+
}))
7577

76-
query1.on('error', function(err) {
78+
var query1 = client.query(queryInstance);
79+
80+
81+
query1.on('error', function (err) {
7782
assert.fail('Prepared statement should not emit error');
7883
});
7984

80-
query1.on('row', function(row) {
85+
query1.on('row', function (row) {
8186
assert.fail('Prepared statement should not emit row');
8287
});
8388

84-
query1.on('end', function(err) {
89+
query1.on('end', function (err) {
8590
assert.fail('Prepared statement when executed should not return before being killed');
8691
});
8792

test/integration/client/query-error-handling-tests.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ test('error during query execution', function() {
4040
}));
4141
});
4242

43-
if(helper.config.native) return;
43+
if (helper.config.native) {
44+
return console.log("\nTODO: this should work on native as well")
45+
}
4446

4547
test('9.3 column error fields', function() {
4648
var client = new Client(helper.args);
@@ -50,12 +52,10 @@ test('9.3 column error fields', function() {
5052
return client.end();
5153
}
5254

53-
client.query('DROP TABLE IF EXISTS column_err_test');
54-
client.query('CREATE TABLE column_err_test(a int NOT NULL)');
55+
client.query('CREATE TEMP TABLE column_err_test(a int NOT NULL)');
5556
client.query('INSERT INTO column_err_test(a) VALUES (NULL)', function (err) {
5657
assert.equal(err.severity, 'ERROR');
5758
assert.equal(err.code, '23502');
58-
assert.equal(err.schema, 'public');
5959
assert.equal(err.table, 'column_err_test');
6060
assert.equal(err.column, 'a');
6161
return client.end();
@@ -73,13 +73,11 @@ test('9.3 constraint error fields', function() {
7373
return client.end();
7474
}
7575

76-
client.query('DROP TABLE IF EXISTS constraint_err_test');
77-
client.query('CREATE TABLE constraint_err_test(a int PRIMARY KEY)');
76+
client.query('CREATE TEMP TABLE constraint_err_test(a int PRIMARY KEY)');
7877
client.query('INSERT INTO constraint_err_test(a) VALUES (1)');
7978
client.query('INSERT INTO constraint_err_test(a) VALUES (1)', function (err) {
8079
assert.equal(err.severity, 'ERROR');
8180
assert.equal(err.code, '23505');
82-
assert.equal(err.schema, 'public');
8381
assert.equal(err.table, 'constraint_err_test');
8482
assert.equal(err.constraint, 'constraint_err_test_pkey');
8583
return client.end();

0 commit comments

Comments
 (0)