failing test for parameterized queries

This commit is contained in:
brianc 2011-02-24 21:33:54 -06:00
parent c58037b514
commit cc2ff042ef
3 changed files with 57 additions and 8 deletions

View File

@ -66,7 +66,13 @@ p._pulseQueryQueue = function() {
return;
}
this._activeQuery = query;
this._sendQuery(query.text);
if(query.values) {
//call native function
this._sendQueryWithParams(query.text, query.values)
} else {
//call native function
this._sendQuery(query.text);
}
}
var ctor = function(config) {
@ -107,11 +113,13 @@ var connect = function(config, callback) {
};
//event emitter proxy
var NativeQuery = function(text) {
var NativeQuery = function(text, values) {
if(typeof text == 'object') {
this.text = text.text;
this.values = text.values;
} else {
this.text = text;
this.values = values;
}
EventEmitter.call(this);
};

View File

@ -40,6 +40,7 @@ public:
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
NODE_SET_PROTOTYPE_METHOD(t, "end", End);
target->Set(String::NewSymbol("Connection"), t->GetFunction());
@ -89,6 +90,16 @@ public:
return Undefined();
}
//v8 entry point into Connection#_sendQueryWithParams
static Handle<Value>
SendQueryWithParams(const Arguments& args)
{
HandleScope scope;
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
printf("%d\n", args.Length());
return Undefined();
}
//v8 entry point into Connection#end
static Handle<Value>
End(const Arguments& args)

View File

@ -26,20 +26,22 @@ test('connects', function() {
})
})
})
test('multiple results', function() {
var setupClient = function() {
var client = new Client(conString);
client.connect();
client.query("CREATE TEMP TABLE boom(name varchar(10))");
client.query("INSERT INTO boom(name) VALUES('Aaron')");
client.query("INSERT INTO boom(name) VALUES('Brian')");
return client;
}
test('multiple results', function() {
test('queued queries', function() {
client.query("CREATE TEMP TABLE boom(name varchar(10))");
client.query("INSERT INTO boom(name) VALUES('Aaron')");
client.query("INSERT INTO boom(name) VALUES('Brian')");
var client = setupClient();
var q = client.query("SELECT * from BOOM");
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Aaron');
assert.emits(q, 'row', function(row) {
assert.equal(row.name, "Brian");
})
})
assert.emits(q, 'end', function() {
@ -55,3 +57,31 @@ test('multiple results', function() {
})
})
})
test('parameterized queries', function() {
test('with a single string param', function() {
var client = setupClient();
var q = client.query("SELECT name FROM boom WHERE name = $1", ['Brian']);
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Brian')
})
assert.emits(q, 'end', function() {
client.end();
});
})
test('with object config for query', function() {
var client = setupClient();
var q = client.query({
text: "SELECT name FROM boom WHERE name = $1",
values: ['Brian']
});
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Brian');
})
assert.emits(q, 'end', function() {
client.end();
})
})
})