Skip to content

Commit

Permalink
Merge pull request #935 from jkgeyti/master
Browse files Browse the repository at this point in the history
Support querying tables with column names with multiple apostrophes
  • Loading branch information
brianc committed Feb 15, 2016
2 parents f26cb73 + 02c47f5 commit 93d1e88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ var inlineParser = function(fieldName, i) {
//fields containing single quotes will break
//the evaluated javascript unless they are escaped
//see https://github.com/brianc/node-postgres/issues/507
fieldName.replace("'", "\\'") +
//Addendum: However, we need to make sure to replace all
//occurences of apostrophes, not just the first one.
//See https://github.com/brianc/node-postgres/issues/934
fieldName.replace(/'/g, "\\'") +
"'] = " +
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
};
Expand Down
13 changes: 13 additions & 0 deletions test/integration/client/query-column-names-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var helper = require(__dirname + '/../test-helper');
var pg = helper.pg;

test('support for complex column names', function() {
pg.connect(helper.config, assert.success(function(client, done) {
client.query("CREATE TEMP TABLE t ( \"complex''column\" TEXT )");
client.query('SELECT * FROM t', assert.success(function(res) {
done();
assert.strictEqual(res.fields[0].name, "complex''column");
pg.end();
}));
}));
});

0 comments on commit 93d1e88

Please sign in to comment.