Skip to content
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

Multi MySQL STATEMENTS support #416

Open
ihmc3jn09hk opened this issue Apr 25, 2020 · 0 comments
Open

Multi MySQL STATEMENTS support #416

ihmc3jn09hk opened this issue Apr 25, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@ihmc3jn09hk
Copy link
Contributor

Is your feature request related to a problem? Please describe.
DbClient is a handy tool for MySQL query even with transaction. Would it be possible to support Mutliple STATEMENT(s) query? To perform following query, it requires the statement be divided into the corresponding sub-statement and execSqlAsync one-by-one.

INSERT INTO tb_a (a, b) VALUES "new_foo", ?
INSERT INTO tb_b (aa) VALUES ?;
INSERT INTO tb_c (aaa) VALUES ?;
DELETE FROM tb_a
WHERE tb_a.a = "new_foo" AND tb_a.b <> "not_new_b";

This quickly resulted in a callbacks hell, e.g.

auto dbErr = [callbackPtr](const DrogonDbException &e){
  Json::Value ret;
  ret["error"] = e.base().what();
  auto resp = HttpResponse::newHttpJsonResponse(std::move(ret));
  resp->setStatusCode(k400BadRequest);
  (*callbackPtr)(std::move(resp);
};
...
dbClientPtr->execSqlAsync(
  "INSERT INTO tb_a (a, b) VALUES "new_foo", ?",
  [dbClientPtr,dbErr](const Result &r){
    //Checking and other operations
    ...
    dbClientPtr->execSqlAsync("INSERT INTO tb_b (aa) VALUES ?;",
      [dbClientPtr,dbErr](const Result &r){
        //Checking and other operations
        ...
        dbClientPtr->execSqlAsync("INSERT INTO tb_c (aaa) VALUES ?;",
          [dbClientPtr,dbErr](const Result &r){
            //Checking and other operations
            ...
            //Futher dbClientPtr->execSqlAsync
          },
          dbErr,
          "new_aaa"
        );
      },
      dbErr,
      "new_aa"
     );
  },
  dbErr,
  "new_b"
);
...

Would it be worse with transaction since the STATEMENT should be enclosed with transaction. Or how could it be simplified? Sorry for my lack of knowledge in SQL.

Describe the solution you'd like
execSqlAsync() and Transaction could support mutli STATEMENTS

Describe alternatives you've considered
I dont know

@an-tao an-tao added the enhancement New feature or request label Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants