Merge pull request #787 from brianc/warn-on-long-query-names

Add warning on long query names
This commit is contained in:
Brian C 2015-06-07 10:43:13 -04:00
commit 711adfe938
3 changed files with 21 additions and 0 deletions

View File

@ -199,6 +199,11 @@ Connection.prototype.parse = function(query, more) {
//normalize missing query names to allow for null
query.name = query.name || '';
if (query.name.length > 63) {
console.error('Warning! Postgres only supports 63 characters for query names.');
console.error('You supplied', query.name, '(', query.name.length, ')');
console.error('This can cause conflicts and silent errors executing queries');
}
//normalize null type array
query.types = query.types || [];
var len = query.types.length;

View File

@ -85,6 +85,11 @@ NativeQuery.prototype.submit = function(client) {
//named query
if(this.name) {
if (this.name.length > 63) {
console.error('Warning! Postgres only supports 63 characters for query names.');
console.error('You supplied', this.name, '(', this.name.length, ')');
console.error('This can cause conflicts and silent errors executing queries');
}
var values = (this.values||[]).map(utils.prepareValue);
//check if the client has already executed this named query

View File

@ -0,0 +1,11 @@
var helper = require(__dirname + '/../test-helper');
helper.pg.connect(helper.config, function(err,client) {
var q = {
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',
text: 'SELECT NOW()'
};
client.query(q, function() {
client.end();
});
});