Merge pull request #60 from an-tao/dev

Use the PQSendQuery() function instead of the PQsendQueryParams() function when the number of parameters is 0.
This commit is contained in:
An Tao 2019-02-25 21:00:52 +08:00 committed by GitHub
commit 037b9e7eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -172,14 +172,7 @@ void PgConnection::execSqlInLoop(std::string &&sql,
if (paraNum == 0)
{
_isRreparingStatement = false;
if (PQsendQueryParams(_connPtr.get(),
_sql.c_str(),
paraNum,
nullptr,
parameters.data(),
length.data(),
format.data(),
0) == 0)
if (PQsendQuery(_connPtr.get(), _sql.c_str()) == 0)
{
LOG_ERROR << "send query error: " << PQerrorMessage(_connPtr.get());
if (_isWorking)
@ -340,7 +333,6 @@ void PgConnection::handleRead()
}
if (_channel.isWriting())
_channel.disableWriting();
bool isPreparing = false;
while ((res = std::shared_ptr<PGresult>(PQgetResult(_connPtr.get()), [](PGresult *p) {
PQclear(p);
})))
@ -368,11 +360,7 @@ void PgConnection::handleRead()
{
if (_isWorking)
{
if (_isRreparingStatement)
{
isPreparing = true;
}
else
if (!_isRreparingStatement)
{
auto r = makeResult(res, _sql);
_cb(r);
@ -384,7 +372,7 @@ void PgConnection::handleRead()
}
if (_isWorking)
{
if (isPreparing)
if (_isRreparingStatement)
{
_preparingCallback();
_preparingCallback = nullptr;

View File

@ -120,5 +120,15 @@ int main()
std::cerr << "error:" << e.base().what() << std::endl;
},
"default");
*clientPtr << "select t2,t9 from ttt where t7=2" >> [](const Result &r) {
std::cout << r.size() << " rows selected!" << std::endl;
for (auto row : r)
{
std::cout << row["t9"].as<std::string>() << std::endl;
std::cout << row["t2"].as<int>() << std::endl;
}
} >> [](const DrogonDbException &e) {
std::cerr << "error:" << e.base().what() << std::endl;
};
getchar();
}