mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
don't mutate params when preparing statement (#992)
This commit is contained in:
parent
5d3b506c70
commit
55abbaa844
@ -146,11 +146,8 @@ Query.prototype.prepare = function(connection) {
|
||||
}, true);
|
||||
}
|
||||
|
||||
//TODO is there some better way to prepare values for the database?
|
||||
if(self.values) {
|
||||
for(var i = 0, len = self.values.length; i < len; i++) {
|
||||
self.values[i] = utils.prepareValue(self.values[i]);
|
||||
}
|
||||
self.values = self.values.map(utils.prepareValue);
|
||||
}
|
||||
|
||||
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
|
||||
|
||||
@ -57,6 +57,31 @@ test("simple query interface using addRow", function() {
|
||||
});
|
||||
});
|
||||
|
||||
test("prepared statements do not mutate params", function() {
|
||||
|
||||
var client = helper.client();
|
||||
|
||||
var params = [1]
|
||||
|
||||
var query = client.query("select name from person where $1 = 1 order by name", params);
|
||||
|
||||
assert.deepEqual(params, [1])
|
||||
|
||||
client.on('drain', client.end.bind(client));
|
||||
|
||||
query.on('row', function(row, result) {
|
||||
assert.ok(result);
|
||||
result.addRow(row);
|
||||
});
|
||||
|
||||
query.on('end', function(result) {
|
||||
assert.lengthIs(result.rows, 26, "result returned wrong number of rows");
|
||||
assert.lengthIs(result.rows, result.rowCount);
|
||||
assert.equal(result.rows[0].name, "Aaron");
|
||||
assert.equal(result.rows[25].name, "Zanzabar");
|
||||
});
|
||||
});
|
||||
|
||||
test("multiple simple queries", function() {
|
||||
var client = helper.client();
|
||||
client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');"})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user