diff --git a/orm_lib/src/postgresql_impl/PgConnection.cc b/orm_lib/src/postgresql_impl/PgConnection.cc index 7beca50c..2b2f981e 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.cc +++ b/orm_lib/src/postgresql_impl/PgConnection.cc @@ -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(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; diff --git a/orm_lib/src/postgresql_impl/test/test1.cc b/orm_lib/src/postgresql_impl/test/test1.cc index faa419ee..8f88decb 100644 --- a/orm_lib/src/postgresql_impl/test/test1.cc +++ b/orm_lib/src/postgresql_impl/test/test1.cc @@ -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::endl; + std::cout << row["t2"].as() << std::endl; + } + } >> [](const DrogonDbException &e) { + std::cerr << "error:" << e.base().what() << std::endl; + }; getchar(); }