drogonframework / drogonframework/drogon
Multi MySQL STATEMENTS support
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**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.
```sql
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.
```c++
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
Contributor guide
Assessment
This issue has not been assessed yet.