mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
add type IDs to parse command
This commit is contained in:
parent
1b56e708e9
commit
c176489348
@ -101,14 +101,15 @@ p.parse = function(query) {
|
||||
query.name = query.name || '';
|
||||
//normalize null type array
|
||||
query.types = query.types || [];
|
||||
var len = query.types.length;
|
||||
var buffer = new BufferList()
|
||||
.addCString(query.name) //name of query
|
||||
.addCString(query.text) //actual query text
|
||||
.addInt16(0).join();
|
||||
if(query.types.length) {
|
||||
sys.debug("Typed parameters not supported yet!");
|
||||
.addInt16(len);
|
||||
for(var i = 0; i < len; i++) {
|
||||
buffer.addInt32(query.types[i]);
|
||||
}
|
||||
this.send('P', buffer);
|
||||
this.send('P', buffer.join());
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -1,14 +1,24 @@
|
||||
var Client = require(__dirname+"/../lib/client");
|
||||
var client = new Client({
|
||||
user: 'brian',
|
||||
database: 'postgres'
|
||||
});
|
||||
client.connect();
|
||||
var query = client.query('select oid, typname, typlen from pg_type where typtype = \'b\' order by typname');
|
||||
query.on('row', function(row) {
|
||||
console.log(row);
|
||||
});
|
||||
query.on('end',function() {
|
||||
client.disconnect();
|
||||
})
|
||||
var net = require('net')
|
||||
var Connection = require(__dirname+'/../lib/connection');
|
||||
|
||||
var con = new Connection({stream: new net.Stream()});
|
||||
con.connect('5432', 'localhost');
|
||||
|
||||
con.on('connect', function() {
|
||||
con.startupMessage({
|
||||
user: 'brian',
|
||||
database: 'postgres'
|
||||
});
|
||||
});
|
||||
|
||||
con.on('dataRow', function(msg) {
|
||||
console.log(msg.fields);
|
||||
});
|
||||
|
||||
con.on('readyForQuery', function() {
|
||||
con.query('select oid, typname from pg_type where typtype = \'b\' order by typname');
|
||||
});
|
||||
|
||||
con.on('commandComplete', function() {
|
||||
con.end();
|
||||
});
|
||||
|
||||
@ -56,6 +56,23 @@ test('sends parse message with named query', function() {
|
||||
.addCString("select * from boom")
|
||||
.addInt16(0).join(true,'P');
|
||||
assert.recieved(stream, expected);
|
||||
|
||||
test('with multiple parameters', function() {
|
||||
con.parse({
|
||||
name: 'force',
|
||||
text: 'select * from bang where name = $1',
|
||||
types: [1, 2, 3 ,4]
|
||||
});
|
||||
var expected = new BufferList()
|
||||
.addCString("force")
|
||||
.addCString("select * from bang where name = $1")
|
||||
.addInt16(4)
|
||||
.addInt32(1)
|
||||
.addInt32(2)
|
||||
.addInt32(3)
|
||||
.addInt32(4).join(true,'P');
|
||||
assert.recieved(stream, expected);
|
||||
});
|
||||
});
|
||||
|
||||
test('sends bind to unamed statement with no values', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user