From f07d9e03e107fe20d1c420785bbc6415eb254dea Mon Sep 17 00:00:00 2001 From: An Tao Date: Sat, 4 Jan 2020 09:36:14 +0800 Subject: [PATCH] Use shorter stmt names in postgresql connections(#326) --- orm_lib/src/postgresql_impl/PgBatchConnection.cc | 6 ++++-- orm_lib/src/postgresql_impl/PgConnection.cc | 2 +- orm_lib/src/postgresql_impl/PgConnection.h | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/orm_lib/src/postgresql_impl/PgBatchConnection.cc b/orm_lib/src/postgresql_impl/PgBatchConnection.cc index 52a7869b..bdec0d4e 100644 --- a/orm_lib/src/postgresql_impl/PgBatchConnection.cc +++ b/orm_lib/src/postgresql_impl/PgBatchConnection.cc @@ -46,7 +46,9 @@ bool checkSql(const string_view &sql_) sql.find("delete") != std::string::npos || sql.find("drop") != std::string::npos || sql.find("truncate") != std::string::npos || - sql.find("lock") != std::string::npos); + sql.find("lock") != std::string::npos || + sql.find("create") != std::string::npos || + sql.find("alter") != std::string::npos); } } // namespace orm @@ -273,7 +275,7 @@ void PgConnection::sendBatchedSql() auto iter = preparedStatementsMap_.find(cmd->sql_); if (iter == preparedStatementsMap_.end()) { - statName = utils::getUuid(); + statName = newStmtName(); if (PQsendPrepare(connectionPtr_.get(), statName.c_str(), cmd->sql_.data(), diff --git a/orm_lib/src/postgresql_impl/PgConnection.cc b/orm_lib/src/postgresql_impl/PgConnection.cc index b6a0d099..fa7046b7 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.cc +++ b/orm_lib/src/postgresql_impl/PgConnection.cc @@ -252,7 +252,7 @@ void PgConnection::execSqlInLoop( else { isRreparingStatement_ = true; - statementName_ = utils::getUuid(); + statementName_ = newStmtName(); if (PQsendPrepare(connectionPtr_.get(), statementName_.c_str(), sql_.data(), diff --git a/orm_lib/src/postgresql_impl/PgConnection.h b/orm_lib/src/postgresql_impl/PgConnection.h index d2e50236..865af427 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.h +++ b/orm_lib/src/postgresql_impl/PgConnection.h @@ -91,6 +91,12 @@ class PgConnection : public DbConnection, std::shared_ptr connectionPtr_; trantor::Channel channel_; bool isRreparingStatement_{false}; + size_t preparedStatementsID_{0}; + std::string newStmtName() + { + loop_->assertInLoopThread(); + return std::to_string(++preparedStatementsID_); + } void handleRead(); void pgPoll(); void handleClosed();