Browse files

make the query async callback function have the same signature as nod…

  • Loading branch information...
1 parent 2e761db commit 091376ac5a0f51301d4941390dd23ca7977f7b4a @ssinghi ssinghi committed with Aug 18, 2010
Showing with 21 additions and 12 deletions.
  1. +4 −7 src/mysql_bindings_connection.cc
  2. +17 −5 tests/test-async.js
View
11 src/mysql_bindings_connection.cc
@@ -826,26 +826,23 @@ int MysqlConn::EIO_After_Query(eio_req *req) {
ev_unref(EV_DEFAULT_UC);
struct query_request *query_req = (struct query_request *)(req->data);
- int argc = 0;
+ int argc = 1; /* node.js convention, there is always one argument */
Local<Value> argv[2];
HandleScope scope;
if (req->result) {
argv[0] = Exception::Error(String::New("Error on query execution"));
- argc = 1;
} else {
if (req->int1) {
argv[0] = External::New(query_req->my_result);
argv[1] = Integer::New(query_req->field_count);
Persistent<Object> js_result(MysqlResult::constructor_template->
GetFunction()->NewInstance(2, argv));
- argv[0] = Local<Value>::New(scope.Close(js_result));
- argc = 1;
- } else {
- /* no result set - not a SELECT, SHOW, DESCRIBE or EXPLAIN */
- argc = 0;
+ argv[1] = Local<Value>::New(scope.Close(js_result));
+ argc = 2;
}
+ argv[0] = Local<Value>::New(Null());
}
TryCatch try_catch;
View
22 tests/test-async.js
@@ -14,7 +14,7 @@ var
exports.async = function (test) {
var conn = mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database);
-
+
conn.async(function () {
conn.close();
test.done();
@@ -31,12 +31,24 @@ exports.queryAsync = function (test) {
" PRIMARY KEY (autoincrement_id)) TYPE=MEMORY;");
test.expect(2);
- conn.queryAsync("SHOW TABLES", function (result) {
- test.ok(result.fieldCount() === 1, "show results field count === 1");
- var res = result.fetchAll();
+ conn.queryAsync("SHOW TABLES", function (err, result) {
+ test.ok(result.fieldCount() === 1, "show results field count === 1");
+ var res = result.fetchAll();
test.ok(res.some(function (r) {
return r['Tables_in_' + cfg.database] === cfg.test_table;
- }), "find the test table in results");
+ }), "find the test table in results");
+ conn.close();
+ test.done();
+ });
+};
+
+exports.queryAsyncWithError = function (test) {
+ var conn = mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database), res;
+
+ test.expect(2);
+ conn.queryAsync("SHOW TABLESaagh", function (err, result) {
+ test.ok(!result, "result is not defined");
+ test.ok(err, "error object is present");
conn.close();
test.done();
});

0 comments on commit 091376a

Please sign in to comment.