diff --git a/get_version.sh b/get_version.sh index d6334b0d..5065a3cc 100755 --- a/get_version.sh +++ b/get_version.sh @@ -3,7 +3,7 @@ GIT_VER=$(git log|grep ^commit|wc -l|sed -e "s/^ *//") MD5=$(git log|head -1|awk '{printf $2}') TMP_FILE=/tmp/version -echo "#define VERSION \"0.9.29.$GIT_VER\"" > ${TMP_FILE} +echo "#define VERSION \"0.9.30.$GIT_VER\"" > ${TMP_FILE} echo "#define VERSION_MD5 \"$MD5\"" >> ${TMP_FILE} if [ ! -f $1 ];then mv -f ${TMP_FILE} $1 diff --git a/orm_lib/src/postgresql_impl/PgConnection.cc b/orm_lib/src/postgresql_impl/PgConnection.cc index 2b2f981e..740d3657 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.cc +++ b/orm_lib/src/postgresql_impl/PgConnection.cc @@ -233,8 +233,8 @@ void PgConnection::execSqlInLoop(std::string &&sql, else { _isRreparingStatement = true; - auto statementName = getuuid(); - if (PQsendPrepare(_connPtr.get(), statementName.c_str(), _sql.c_str(), paraNum, NULL) == 0) + _statementName = getuuid(); + if (PQsendPrepare(_connPtr.get(), _statementName.c_str(), _sql.c_str(), paraNum, NULL) == 0) { LOG_ERROR << "send query error: " << PQerrorMessage(_connPtr.get()); if (_isWorking) @@ -255,46 +255,10 @@ void PgConnection::execSqlInLoop(std::string &&sql, } return; } - std::weak_ptr weakPtr = shared_from_this(); - _preparingCallback = [weakPtr, - statementName, - paraNum, - parameters = std::move(parameters), - length = std::move(length), - format = std::move(format)]() { - auto thisPtr = weakPtr.lock(); - if (!thisPtr) - return; - thisPtr->_isRreparingStatement = false; - thisPtr->_preparedStatementMap[thisPtr->_sql] = statementName; - if (PQsendQueryPrepared(thisPtr->_connPtr.get(), - statementName.c_str(), - paraNum, - parameters.data(), - length.data(), - format.data(), - 0) == 0) - { - LOG_ERROR << "send query error: " << PQerrorMessage(thisPtr->_connPtr.get()); - if (thisPtr->_isWorking) - { - thisPtr->_isWorking = false; - try - { - throw Failure(PQerrorMessage(thisPtr->_connPtr.get())); - } - catch (...) - { - auto exceptPtr = std::current_exception(); - thisPtr->_exceptCb(exceptPtr); - thisPtr->_exceptCb = nullptr; - } - thisPtr->_cb = nullptr; - thisPtr->_idleCb(); - } - return; - } - }; + _paraNum = paraNum; + _parameters = std::move(parameters); + _length = std::move(length); + _format = std::move(format); } } pgPoll(); @@ -374,8 +338,7 @@ void PgConnection::handleRead() { if (_isRreparingStatement) { - _preparingCallback(); - _preparingCallback = nullptr; + doAfterPreparing(); } else { @@ -385,3 +348,36 @@ void PgConnection::handleRead() } } } + +void PgConnection::doAfterPreparing() +{ + _isRreparingStatement = false; + _preparedStatementMap[_sql] = _statementName; + if (PQsendQueryPrepared(_connPtr.get(), + _statementName.c_str(), + _paraNum, + _parameters.data(), + _length.data(), + _format.data(), + 0) == 0) + { + LOG_ERROR << "send query error: " << PQerrorMessage(_connPtr.get()); + if (_isWorking) + { + _isWorking = false; + try + { + throw Failure(PQerrorMessage(_connPtr.get())); + } + catch (...) + { + auto exceptPtr = std::current_exception(); + _exceptCb(exceptPtr); + _exceptCb = nullptr; + } + _cb = nullptr; + _idleCb(); + } + return; + } +} diff --git a/orm_lib/src/postgresql_impl/PgConnection.h b/orm_lib/src/postgresql_impl/PgConnection.h index 9713567e..6a8b976b 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.h +++ b/orm_lib/src/postgresql_impl/PgConnection.h @@ -95,7 +95,13 @@ class PgConnection : public DbConnection, public std::enable_shared_from_this &&format, ResultCallback &&rcb, std::function &&exceptCallback); - std::function _preparingCallback; + //std::function _preparingCallback; + void doAfterPreparing(); + std::string _statementName; + int _paraNum; + std::vector _parameters; + std::vector _length; + std::vector _format; }; } // namespace orm