Skip to content

Async Prepared Statement Execution #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MelvinSE opened this issue Feb 13, 2014 · 0 comments
Open

Async Prepared Statement Execution #183

MelvinSE opened this issue Feb 13, 2014 · 0 comments
Labels

Comments

@MelvinSE
Copy link

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.

@Sannis Sannis changed the title Async Prpared Statement Execution Async Prepared Statement Execution Jul 12, 2014
@Sannis Sannis added the docs label Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants