Skip to content

Async Prepared Statement Execution #183

Open
@MelvinSE

Description

@MelvinSE

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:

  • Create a new statement with initStatementSync();.
  • Prepare the statement SQL with prepareSync();.
  • Store that MysqlStatment object in my parent class.

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

  • Get the saved MysqlStatment that was previously prepared
  • Set the params with bindParamsSync();.
  • Call execute() on the statement.
  • In the callback of the execute method, call bindResultSync();
  • After binding the results, call fetchAll() to get the dataset.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions