diff --git a/frameworks/js/napi/rdb/src/napi_result_set.cpp b/frameworks/js/napi/rdb/src/napi_result_set.cpp index 87dd8a47b3f0e7d6d6e9a2867c65f9832b931568..3139233d850d1ecc552635044ab2300d785bd256 100644 --- a/frameworks/js/napi/rdb/src/napi_result_set.cpp +++ b/frameworks/js/napi/rdb/src/napi_result_set.cpp @@ -195,9 +195,6 @@ napi_value ResultSetProxy::InitializeV9(napi_env env, napi_callback_info info) ResultSetProxy::~ResultSetProxy() { LOG_INFO("ResultSetProxy destructor!"); - if (resultSet_ != nullptr && !resultSet_->IsClosed()) { - resultSet_->Close(); - } } ResultSetProxy::ResultSetProxy(std::shared_ptr resultSet) diff --git a/frameworks/js/napi/relationalstore/src/napi_result_set.cpp b/frameworks/js/napi/relationalstore/src/napi_result_set.cpp index 988c70f2fb4485c2f5eea1a9ea020e676d4bcf26..84f709c58557cb9190ecffc5b7632b9c726aa0f6 100644 --- a/frameworks/js/napi/relationalstore/src/napi_result_set.cpp +++ b/frameworks/js/napi/relationalstore/src/napi_result_set.cpp @@ -136,9 +136,6 @@ napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info) ResultSetProxy::~ResultSetProxy() { LOG_INFO("ResultSetProxy destructor!"); - if (resultSet_ != nullptr && !resultSet_->IsClosed()) { - resultSet_->Close(); - } } ResultSetProxy::ResultSetProxy(std::shared_ptr resultSet) diff --git a/frameworks/native/rdb/include/rdb_store_impl.h b/frameworks/native/rdb/include/rdb_store_impl.h index 9faf14ef08523db8758f3e108519d5a5db360611..9c249c2905edcbd5c69999782d258f39dc0db7b5 100644 --- a/frameworks/native/rdb/include/rdb_store_impl.h +++ b/frameworks/native/rdb/include/rdb_store_impl.h @@ -124,8 +124,6 @@ private: const RdbStoreConfig rdbStoreConfig; SqliteConnectionPool *connectionPool; - static const int MAX_IDLE_SESSION_SIZE = 5; - std::mutex sessionMutex; bool isOpen; std::string path; std::string orgPath; @@ -133,7 +131,6 @@ private: bool isMemoryRdb; std::string name; std::string fileType; - std::stack transactionObserverStack; bool isShared_ = false; DistributedRdb::RdbSyncerParam syncerParam_; bool isEncrypt_; diff --git a/frameworks/native/rdb/include/sqlite_shared_result_set.h b/frameworks/native/rdb/include/sqlite_shared_result_set.h index 413d05b48d3e611384028fc4b813c3ee2ec4b191..ce83fe9baa3b5cf03f85d5978ea46f416ae6d8f8 100644 --- a/frameworks/native/rdb/include/sqlite_shared_result_set.h +++ b/frameworks/native/rdb/include/sqlite_shared_result_set.h @@ -22,7 +22,7 @@ #include #include #include -#include "rdb_store_impl.h" +#include "sqlite_connection_pool.h" #include "sqlite_statement.h" #include "shared_block.h" #include "abs_shared_result_set.h" @@ -32,18 +32,14 @@ namespace OHOS { namespace NativeRdb { class SqliteSharedResultSet : public AbsSharedResultSet { public: - SqliteSharedResultSet(std::shared_ptr rdbSreImpl, std::string path, std::string sql, - const std::vector &selectionArgVec); SqliteSharedResultSet(SqliteConnectionPool* connectionPool, std::string path, std::string sql, const std::vector &bindArgs); ~SqliteSharedResultSet() override; - int PrepareStep(SqliteConnection* connection); int GetAllColumnNames(std::vector &columnNames) override; int Close() override; int GetRowCount(int &count) override; bool OnGo(int oldPosition, int newPosition) override; void SetBlock(AppDataFwk::SharedBlock *block) override; - std::shared_ptr GetRdbStore() const; int PickFillBlockStartPosition(int resultSetPosition, int blockCapacity) const; void SetFillBlockForwardOnly(bool isOnlyFillResultSetBlockInput); @@ -51,9 +47,8 @@ protected: void Finalize() override; private: - int PrepareStep(); + std::shared_ptr PrepareStep(SqliteConnection* connection, int &errCode); void FillSharedBlock(int requiredPos); - private: // The specified value is -1 when there is no data static const int NO_COUNT = -1; @@ -63,12 +58,9 @@ private: int resultSetBlockCapacity; // Controls fetching of rows relative to requested position bool isOnlyFillResultSetBlock; - std::mutex sessionMutex; - std::shared_ptr rdbStoreImpl; std::string qrySql; std::vector selectionArgVec; std::shared_ptr sqliteStatement; - std::thread::id tid; // The number of rows in the cursor int rowNum; std::vector columnNames_; diff --git a/frameworks/native/rdb/include/step_result_set.h b/frameworks/native/rdb/include/step_result_set.h index eb43cbac97017ebb5fec8f1e76be3c79a13d2c1d..7ead30596ade6f186fcb2a18dae0ec98e427ed88 100644 --- a/frameworks/native/rdb/include/step_result_set.h +++ b/frameworks/native/rdb/include/step_result_set.h @@ -70,7 +70,6 @@ private: bool isAfterLast; // The value indicates the row count of the result set int rowCount; - std::thread::id tid; std::shared_ptr sqliteStatement; static const int INIT_POS = -1; // Max times of retrying step query diff --git a/frameworks/native/rdb/mock/include/rdb_store_impl.h b/frameworks/native/rdb/mock/include/rdb_store_impl.h index 64f60aebfffc951228d6961a5a408543280d85b4..c1ca8397ab5eb0a6ab23c8d0a7a799498dd3a499 100644 --- a/frameworks/native/rdb/mock/include/rdb_store_impl.h +++ b/frameworks/native/rdb/mock/include/rdb_store_impl.h @@ -105,8 +105,6 @@ private: const RdbStoreConfig rdbStoreConfig; SqliteConnectionPool *connectionPool; - static const int MAX_IDLE_SESSION_SIZE = 5; - std::mutex sessionMutex; bool isOpen; std::string path; std::string orgPath; @@ -114,7 +112,6 @@ private: bool isMemoryRdb; std::string name; std::string fileType; - std::stack transactionObserverStack; bool isEncrypt_; }; } // namespace OHOS::NativeRdb diff --git a/frameworks/native/rdb/mock/include/step_result_set.h b/frameworks/native/rdb/mock/include/step_result_set.h index a16c51c18427e2334db0a83132f8c65cfe078de4..a684362943a69cb110c631d6218e80f015b4224d 100644 --- a/frameworks/native/rdb/mock/include/step_result_set.h +++ b/frameworks/native/rdb/mock/include/step_result_set.h @@ -70,7 +70,6 @@ private: bool isAfterLast; // The value indicates the row count of the result set int rowCount; - std::thread::id tid; std::shared_ptr sqliteStatement; static const int INIT_POS = -1; // Max times of retrying step query diff --git a/frameworks/native/rdb/src/abs_result_set.cpp b/frameworks/native/rdb/src/abs_result_set.cpp index 11d66626dd9caeb5f6c01913709317f6e8b01913..14eb4f9b38f724edd79dba679ace5d488bbcecc5 100644 --- a/frameworks/native/rdb/src/abs_result_set.cpp +++ b/frameworks/native/rdb/src/abs_result_set.cpp @@ -69,7 +69,11 @@ AbsResultSet::AbsResultSet() : rowPos_(INIT_POS), isClosed(false) { } -AbsResultSet::~AbsResultSet() {} +AbsResultSet::~AbsResultSet() +{ + rowPos_ = INIT_POS; + isClosed = false; +} int AbsResultSet::GetRowCount(int &count) { diff --git a/frameworks/native/rdb/src/sqlite_shared_result_set.cpp b/frameworks/native/rdb/src/sqlite_shared_result_set.cpp index a7cf33e44b028d9d0b1081cbcec3d344c6c227c5..881694526a8e084955a3d305c496eb9c83e76375 100644 --- a/frameworks/native/rdb/src/sqlite_shared_result_set.cpp +++ b/frameworks/native/rdb/src/sqlite_shared_result_set.cpp @@ -23,13 +23,6 @@ namespace OHOS { namespace NativeRdb { -SqliteSharedResultSet::SqliteSharedResultSet(std::shared_ptr rdbSreImpl, std::string path, - std::string sql, const std::vector &bindArgs) - : AbsSharedResultSet(path), resultSetBlockCapacity(0), isOnlyFillResultSetBlock(false), rdbStoreImpl(rdbSreImpl), - qrySql(sql), selectionArgVec(bindArgs), rowNum(NO_COUNT), connectionPool_(nullptr) -{ -} - SqliteSharedResultSet::SqliteSharedResultSet(SqliteConnectionPool* connectionPool, std::string path, std::string sql, const std::vector &bindArgs) : AbsSharedResultSet(path), resultSetBlockCapacity(0), isOnlyFillResultSetBlock(false), @@ -40,26 +33,23 @@ SqliteSharedResultSet::SqliteSharedResultSet(SqliteConnectionPool* connectionPoo SqliteSharedResultSet::~SqliteSharedResultSet() {} -int SqliteSharedResultSet::PrepareStep(SqliteConnection* connection) +std::shared_ptr SqliteSharedResultSet::PrepareStep(SqliteConnection* connection, int &errCode) { - if (IsClosed()) { - return E_STEP_RESULT_CLOSED; - } - if (SqliteDatabaseUtils::GetSqlStatementType(qrySql) != SqliteUtils::STATEMENT_SELECT) { LOG_ERROR("StoreSession BeginStepQuery fail : not select sql !"); - return E_EXECUTE_IN_STEP_QUERY; + errCode = E_EXECUTE_IN_STEP_QUERY; + return nullptr; } - int errCode; - sqliteStatement = connection->BeginStepQuery(errCode, qrySql, selectionArgVec); + std::shared_ptr sqliteStatement = connection->BeginStepQuery(errCode, + qrySql, selectionArgVec); if (sqliteStatement == nullptr) { connection->EndStepQuery(); - return errCode; } - return E_OK; + return sqliteStatement; } + int SqliteSharedResultSet::GetAllColumnNames(std::vector &columnNames) { if (!columnNames_.empty()) { @@ -67,13 +57,18 @@ int SqliteSharedResultSet::GetAllColumnNames(std::vector &columnNam return E_OK; } + if (IsClosed()) { + return E_STEP_RESULT_CLOSED; + } + SqliteConnection *connection = connectionPool_->AcquireConnection(true); if (connection == nullptr) { return E_CON_OVER_LIMIT; } - int errCode = PrepareStep(connection); - if (errCode) { + int errCode = E_OK; + std::shared_ptr sqliteStatement = PrepareStep(connection, errCode); + if (sqliteStatement == nullptr) { connectionPool_->ReleaseConnection(connection); return errCode; } @@ -102,37 +97,32 @@ int SqliteSharedResultSet::GetAllColumnNames(std::vector &columnNam columnCount_ = static_cast(columnNames_.size()); connection->EndStepQuery(); connectionPool_->ReleaseConnection(connection); - sqliteStatement = nullptr; return E_OK; } int SqliteSharedResultSet::GetRowCount(int &count) { - if (rowNum == NO_COUNT) { - FillSharedBlock(0); + if (rowNum != NO_COUNT) { + count = rowNum; + return E_OK; + } + + if (IsClosed()) { + return E_STEP_RESULT_CLOSED; } + + FillSharedBlock(0); count = rowNum; return E_OK; } int SqliteSharedResultSet::Close() { - std::lock_guard lock(sessionMutex); - AbsSharedResultSet::Close(); - return E_OK; } -/** - * Get the rdb store that this result set is associated with. - */ -std::shared_ptr SqliteSharedResultSet::GetRdbStore() const -{ - return rdbStoreImpl; -} - bool SqliteSharedResultSet::OnGo(int oldPosition, int newPosition) { if (GetBlock() == nullptr) { @@ -165,7 +155,7 @@ void SqliteSharedResultSet::FillSharedBlock(int requiredPos) std::vector bindArgs; size_t size = selectionArgVec.size(); - + bindArgs.reserve(size); for (size_t i = 0; i < size; i++) { ValueObject vauObj(selectionArgVec[i]); bindArgs.push_back(vauObj); @@ -218,7 +208,7 @@ void SqliteSharedResultSet::SetFillBlockForwardOnly(bool isOnlyFillResultSetBloc void SqliteSharedResultSet::Finalize() { - if (!AbsSharedResultSet::IsClosed()) { + if (!IsClosed()) { Close(); } }