Skip to content

Commit 711adfe

Browse files
committed
Merge pull request brianc#787 from brianc/warn-on-long-query-names
Add warning on long query names
2 parents eb89490 + 17f14f4 commit 711adfe

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/connection.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ Connection.prototype.parse = function(query, more) {
199199

200200
//normalize missing query names to allow for null
201201
query.name = query.name || '';
202+
if (query.name.length > 63) {
203+
console.error('Warning! Postgres only supports 63 characters for query names.');
204+
console.error('You supplied', query.name, '(', query.name.length, ')');
205+
console.error('This can cause conflicts and silent errors executing queries');
206+
}
202207
//normalize null type array
203208
query.types = query.types || [];
204209
var len = query.types.length;

lib/native/query.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ NativeQuery.prototype.submit = function(client) {
8585

8686
//named query
8787
if(this.name) {
88+
if (this.name.length > 63) {
89+
console.error('Warning! Postgres only supports 63 characters for query names.');
90+
console.error('You supplied', this.name, '(', this.name.length, ')');
91+
console.error('This can cause conflicts and silent errors executing queries');
92+
}
8893
var values = (this.values||[]).map(utils.prepareValue);
8994

9095
//check if the client has already executed this named query
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var helper = require(__dirname + '/../test-helper');
2+
3+
helper.pg.connect(helper.config, function(err,client) {
4+
var q = {
5+
name: 'This is a super long query name just so I can test that an error message is properly spit out to console.error without throwing an exception or anything',
6+
text: 'SELECT NOW()'
7+
};
8+
client.query(q, function() {
9+
client.end();
10+
});
11+
});

0 commit comments

Comments
 (0)