Sannis / node-mysql-libmysqlclient

Asynchronous MySQL binding for Node.js
http://sannis.github.com/node-mysql-libmysqlclient
Other
229 stars 47 forks source link

Async Prepared Statement Execution #183

Open MelvinSE opened 10 years ago

MelvinSE commented 10 years ago

Really great work on this library. Thanks.

I'm working on executing prepared statements asynchronously. By the looks of the code, this is still in development, but I wanted to make sure I wasn't making a mistake in my implementation. When initializing the parent class, I do the following:

The parent class has methods to query the DB. When on of those methods is invoked, the code then does the following:

I had previously written this code to use the synchronous methods for testing my SQL statements and it worked great. However, I must use the async calls in the final application. The code above doesn't fail, but returns no data. I have a feeling I'm not binding the results correctly before calling fetchAll().

The source code for the execute() block is here, where the statement object has already been initialized and prepared:

statement.execute(function(err, result) {
  if (err) { return fn(err); }

  statement.bindResultSync();
  statement.fetchAll(function(err, rows) {
    if (err) { return fn(err); }

    return fn(null, rows);
  });
});

As I said, it seems the support for async prepared statement execution might not be completed. That's OK, but I wanted to make sure my code wasn't wrong and that's why I'm getting an empty array back.