diff --git a/frameworks/native/rdb/include/rdb_store_impl.h b/frameworks/native/rdb/include/rdb_store_impl.h index df19a713c2abf9fde9b88a2ab497ca874029f68b..17df2a29ea7aa0da741ecdaeb7c847a79667b31f 100644 --- a/frameworks/native/rdb/include/rdb_store_impl.h +++ b/frameworks/native/rdb/include/rdb_store_impl.h @@ -26,7 +26,6 @@ #include "rdb_store_config.h" #include "sqlite_connection_pool.h" #include "sqlite_statement.h" -#include "store_session.h" #include "transaction_observer.h" namespace OHOS::NativeRdb { @@ -124,8 +123,6 @@ private: SqliteConnectionPool *connectionPool; static const int MAX_IDLE_SESSION_SIZE = 5; std::mutex sessionMutex; - std::map, int>> threadMap; - std::list> idleSessions; bool isOpen; std::string path; std::string orgPath; diff --git a/frameworks/native/rdb/include/sqlite_shared_result_set.h b/frameworks/native/rdb/include/sqlite_shared_result_set.h index 01c0e4dbafa44cbf3587ff0f595fca37b74bab44..f1d69721ddb945b30aba5eec7d7adaefff8fe6f5 100644 --- a/frameworks/native/rdb/include/sqlite_shared_result_set.h +++ b/frameworks/native/rdb/include/sqlite_shared_result_set.h @@ -52,7 +52,6 @@ protected: private: int PrepareStep(); - int CheckSession(); void FillSharedBlock(int requiredPos); private: diff --git a/frameworks/native/rdb/include/step_result_set.h b/frameworks/native/rdb/include/step_result_set.h index 2f10cb56ee567020db8f1dd5d813d4f7f8d8367b..c7ce30a022aada11df4c68c207e1ea81d2d91941 100644 --- a/frameworks/native/rdb/include/step_result_set.h +++ b/frameworks/native/rdb/include/step_result_set.h @@ -54,7 +54,6 @@ public: int PrepareStep(); private: - int CheckSession(); void Reset(); std::shared_ptr rdb; std::string sql; diff --git a/frameworks/native/rdb/include/store_session.h b/frameworks/native/rdb/include/store_session.h deleted file mode 100644 index b678374e59ae34424aaf69a595172aa5b2e4c626..0000000000000000000000000000000000000000 --- a/frameworks/native/rdb/include/store_session.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NATIVE_RDB_RDB_STORE_SESSION_H -#define NATIVE_RDB_RDB_STORE_SESSION_H - -#include -#include -#include - -#include "sqlite_connection.h" -#include "sqlite_connection_pool.h" -#include "value_object.h" -#include "transaction_observer.h" - -namespace OHOS { -namespace NativeRdb { - -class StoreSession { -public: - explicit StoreSession(SqliteConnectionPool &connectionPool); - ~StoreSession(); - int ExecuteSql(const std::string &sql, const std::vector &bindArgs); - int ExecuteForChangedRowCount(int &changedRows, const std::string &sql, const std::vector &bindArgs); - int ExecuteForLastInsertedRowId( - int64_t &outRowId, const std::string &sql, const std::vector &bindArgs); - int ExecuteGetLong(int64_t &outValue, const std::string &sql, const std::vector &bindArgs); - int ExecuteGetString(std::string &outValue, const std::string &sql, const std::vector &bindArgs); - int Backup(const std::string databasePath, const std::vector destEncryptKey); - bool IsHoldingConnection() const; - int GiveConnectionTemporarily(int64_t milliseconds); - int CheckNoTransaction() const; - int BeginTransaction(TransactionObserver *transactionObserver); - int Attach(const std::string &alias, const std::string &pathName, const std::vector destEncryptKey); - bool IsInTransaction() const; - std::shared_ptr BeginStepQuery( - int &errCode, const std::string &sql, const std::vector &selectionArgs); - int EndStepQuery(); - int PrepareAndGetInfo(const std::string &sql, bool &outIsReadOnly, int &numParameters, - std::vector &columnNames); - int ExecuteForSharedBlock(int &rowNum, std::string sql, const std::vector &bindArgs, - AppDataFwk::SharedBlock *sharedBlock, int startPos, int requiredPos, bool isCountAllRows); - - int BeginTransaction(); - int Commit(); - int RollBack(); - int GetConnectionUseCount(); - -private: - - void AcquireConnection(bool isReadOnly); - void ReleaseConnection(bool isReadOnly); - int BeginExecuteSql(const std::string &sql, bool &isReadOnly); - SqliteConnectionPool &connectionPool; - SqliteConnection *readConnection; - SqliteConnection *connection; - int readConnectionUseCount; - int connectionUseCount; - bool isInStepQuery; - - const std::string ATTACH_BACKUP_SQL = "ATTACH ? AS backup KEY ?"; - const std::string ATTACH_SQL = "ATTACH ? AS ? KEY ?"; - const std::string EXPORT_SQL = "SELECT export_database('backup')"; - const std::string DETACH_BACKUP_SQL = "detach backup"; -}; - -} // namespace NativeRdb -} // namespace OHOS -#endif \ No newline at end of file diff --git a/frameworks/native/rdb/mock/include/rdb_store_impl.h b/frameworks/native/rdb/mock/include/rdb_store_impl.h index efd7f3dddd33cc607856108542e8eeae51649953..765306a8ba1d9240b1be66d612a7d5b64f447d89 100644 --- a/frameworks/native/rdb/mock/include/rdb_store_impl.h +++ b/frameworks/native/rdb/mock/include/rdb_store_impl.h @@ -26,7 +26,6 @@ #include "rdb_store_config.h" #include "sqlite_connection_pool.h" #include "sqlite_statement.h" -#include "store_session.h" #include "transaction_observer.h" namespace OHOS::NativeRdb { @@ -104,8 +103,6 @@ private: SqliteConnectionPool *connectionPool; static const int MAX_IDLE_SESSION_SIZE = 5; std::mutex sessionMutex; - std::map, int>> threadMap; - std::list> idleSessions; bool isOpen; std::string path; std::string orgPath; diff --git a/frameworks/native/rdb/mock/include/step_result_set.h b/frameworks/native/rdb/mock/include/step_result_set.h index b817ec66feca7e231f635dd2a16a9f5a187e0934..20854647cf0086e3dd5f2ff22d7dfd53ac3f6765 100644 --- a/frameworks/native/rdb/mock/include/step_result_set.h +++ b/frameworks/native/rdb/mock/include/step_result_set.h @@ -54,7 +54,6 @@ public: int PrepareStep(); private: - int CheckSession(); void Reset(); std::shared_ptr rdb; std::string sql; diff --git a/frameworks/native/rdb/mock/include/store_session.h b/frameworks/native/rdb/mock/include/store_session.h deleted file mode 100644 index 343431ad0f8b85d0314543c6a7968cad0cf0d68e..0000000000000000000000000000000000000000 --- a/frameworks/native/rdb/mock/include/store_session.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NATIVE_RDB_RDB_STORE_SESSION_H -#define NATIVE_RDB_RDB_STORE_SESSION_H - -#include -#include -#include - -#include "sqlite_connection.h" -#include "sqlite_connection_pool.h" -#include "value_object.h" -#include "transaction_observer.h" - -namespace OHOS { -namespace NativeRdb { -class StoreSession { -public: - explicit StoreSession(SqliteConnectionPool &connectionPool); - ~StoreSession(); - int ExecuteSql(const std::string &sql, const std::vector &bindArgs); - int ExecuteForChangedRowCount(int &changedRows, const std::string &sql, const std::vector &bindArgs); - int ExecuteForLastInsertedRowId( - int64_t &outRowId, const std::string &sql, const std::vector &bindArgs); - int ExecuteGetLong(int64_t &outValue, const std::string &sql, const std::vector &bindArgs); - int ExecuteGetString(std::string &outValue, const std::string &sql, const std::vector &bindArgs); - int Backup(const std::string databasePath, const std::vector destEncryptKey); - bool IsHoldingConnection() const; - int GiveConnectionTemporarily(int64_t milliseconds); - int CheckNoTransaction() const; - int BeginTransaction(TransactionObserver *transactionObserver); - int Attach(const std::string &alias, const std::string &pathName, const std::vector destEncryptKey); - bool IsInTransaction() const; - std::shared_ptr BeginStepQuery( - int &errCode, const std::string &sql, const std::vector &selectionArgs); - int EndStepQuery(); - int PrepareAndGetInfo(const std::string &sql, bool &outIsReadOnly, int &numParameters, - std::vector &columnNames); - - int BeginTransaction(); - int Commit(); - int RollBack(); - int GetConnectionUseCount(); - -private: - void AcquireConnection(bool isReadOnly); - void ReleaseConnection(bool isReadOnly); - int BeginExecuteSql(const std::string &sql, bool &isReadOnly); - SqliteConnectionPool &connectionPool; - SqliteConnection *readConnection; - SqliteConnection *connection; - int readConnectionUseCount; - int connectionUseCount; - bool isInStepQuery; - - const std::string ATTACH_BACKUP_SQL = "ATTACH ? AS backup KEY ?"; - const std::string ATTACH_SQL = "ATTACH ? AS ? KEY ?"; - const std::string EXPORT_SQL = "SELECT export_database('backup')"; - const std::string DETACH_BACKUP_SQL = "detach backup"; -}; -} // namespace NativeRdb -} // namespace OHOS -#endif \ No newline at end of file diff --git a/frameworks/native/rdb/src/rdb_store_impl.cpp b/frameworks/native/rdb/src/rdb_store_impl.cpp index 44664c97023f1e20904cfa70885d92ab04a75634..57b276dd7ab0336f0c64d4d9b330cad08b84d582 100644 --- a/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -110,8 +110,6 @@ RdbStoreImpl::RdbStoreImpl() RdbStoreImpl::~RdbStoreImpl() { delete connectionPool; - threadMap.clear(); - idleSessions.clear(); #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) if (isShared_) { auto service = DistributedRdb::RdbManager::GetRdbService(syncerParam_); diff --git a/frameworks/native/rdb/src/sqlite_shared_result_set.cpp b/frameworks/native/rdb/src/sqlite_shared_result_set.cpp index 14cf350a588b7414f15c9585531bfab133826f8a..23be609b06901ba4d5d5677aad636b6d1e914843 100644 --- a/frameworks/native/rdb/src/sqlite_shared_result_set.cpp +++ b/frameworks/native/rdb/src/sqlite_shared_result_set.cpp @@ -214,13 +214,5 @@ void SqliteSharedResultSet::Finalize() Close(); } } - -int SqliteSharedResultSet::CheckSession() -{ - if (std::this_thread::get_id() != tid) { - return E_STEP_RESULT_SET_CROSS_THREADS; - } - return E_OK; -} } // namespace NativeRdb } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/rdb/src/step_result_set.cpp b/frameworks/native/rdb/src/step_result_set.cpp index 88b0610aac2c104b8406bc56ae8162ffd4186c67..028aa6da08e984511b9fb60b17012135659b176a 100644 --- a/frameworks/native/rdb/src/step_result_set.cpp +++ b/frameworks/native/rdb/src/step_result_set.cpp @@ -223,11 +223,6 @@ int StepResultSet::Close() return errCode; } -int StepResultSet::CheckSession() -{ - return E_OK; -} - /** * Obtain session and prepare precompile statement for step query */ @@ -261,20 +256,17 @@ int StepResultSet::PrepareStep() */ int StepResultSet::FinishStep() { - int errCode = CheckSession(); - if (errCode != E_OK) { - return errCode; - } - if (sqliteStatement == nullptr) { return E_OK; } sqliteStatement = nullptr; rowPos_ = INIT_POS; - if (connection_ != nullptr) { - errCode = connection_->EndStepQuery(); + if (connection_ == nullptr) { + return E_OK; } + + int errCode = connection_->EndStepQuery(); if (errCode != E_OK) { LOG_ERROR("StepResultSet::FinishStep err = %d", errCode); } diff --git a/frameworks/native/rdb/src/store_session.cpp b/frameworks/native/rdb/src/store_session.cpp deleted file mode 100644 index 312a822c9e32dc2c83bd58b130b772670cb9f6a7..0000000000000000000000000000000000000000 --- a/frameworks/native/rdb/src/store_session.cpp +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "store_session.h" -#include -#include -#include -#include "logger.h" -#include "rdb_errno.h" -#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) -#include "shared_block.h" -#endif -#include "sqlite_database_utils.h" -#include "sqlite_utils.h" -#include "base_transaction.h" - -namespace OHOS::NativeRdb { -StoreSession::StoreSession(SqliteConnectionPool &connectionPool) - : connectionPool(connectionPool), readConnection(nullptr), connection(nullptr), - readConnectionUseCount(0), connectionUseCount(0), isInStepQuery(false) -{ -} - -StoreSession::~StoreSession() -{ -} - -void StoreSession::AcquireConnection(bool isReadOnly) -{ - if (isReadOnly) { - if (readConnection == nullptr) { - readConnection = connectionPool.AcquireConnection(true); - } - readConnectionUseCount += 1; - return; - } - if (connection == nullptr) { - connection = connectionPool.AcquireConnection(false); - } - connectionUseCount += 1; - return; -} - -void StoreSession::ReleaseConnection(bool isReadOnly) -{ - if (isReadOnly) { - if ((readConnection == nullptr) || (readConnectionUseCount <= 0)) { - LOG_ERROR("SQLiteSession ReleaseConnection repeated release"); - return; - } - if (--readConnectionUseCount == 0) { - connectionPool.ReleaseConnection(readConnection); - readConnection = nullptr; - } - return; - } - if ((connection == nullptr) || (connectionUseCount <= 0)) { - LOG_ERROR("SQLiteSession ReleaseConnection repeated release"); - return; - } - - if (--connectionUseCount == 0) { - connectionPool.ReleaseConnection(connection); - connection = nullptr; - } -} - -int StoreSession::PrepareAndGetInfo( - const std::string &sql, bool &outIsReadOnly, int &numParameters, std::vector &columnNames) -{ - // Obtains the type of SQL statement. - int type = SqliteUtils::GetSqlStatementType(sql); - if (SqliteUtils::IsSpecial(type)) { - return E_TRANSACTION_IN_EXECUTE; - } - bool assumeReadOnly = SqliteUtils::IsSqlReadOnly(type); - AcquireConnection(assumeReadOnly); - auto con = assumeReadOnly ? readConnection : connection; - int errCode = con->PrepareAndGetInfo(sql, outIsReadOnly, numParameters, columnNames); - if (errCode != 0) { - ReleaseConnection(assumeReadOnly); - return errCode; - } - - ReleaseConnection(assumeReadOnly); - return E_OK; -} - -int StoreSession::BeginExecuteSql(const std::string &sql, bool &isReadOnly) -{ - int type = SqliteUtils::GetSqlStatementType(sql); - if (SqliteUtils::IsSpecial(type)) { - return E_TRANSACTION_IN_EXECUTE; - } - - bool assumeReadOnly = SqliteUtils::IsSqlReadOnly(type); - AcquireConnection(assumeReadOnly); - SqliteConnection *con = assumeReadOnly ? readConnection : connection; - int errCode = con->Prepare(sql, isReadOnly); - if (errCode != 0) { - ReleaseConnection(assumeReadOnly); - return errCode; - } - isReadOnly = assumeReadOnly; - return E_OK; -} -int StoreSession::ExecuteSql(const std::string &sql, const std::vector &bindArgs) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != 0) { - return errCode; - } - SqliteConnection *con = isReadOnly ? readConnection : connection; - errCode = con->ExecuteSql(sql, bindArgs); - ReleaseConnection(isReadOnly); - return errCode; -} - -int StoreSession::ExecuteForChangedRowCount( - int &changedRows, const std::string &sql, const std::vector &bindArgs) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != 0) { - return errCode; - } - auto con = isReadOnly ? readConnection : connection; - errCode = con->ExecuteForChangedRowCount(changedRows, sql, bindArgs); - ReleaseConnection(isReadOnly); - return errCode; -} - -int StoreSession::ExecuteForLastInsertedRowId( - int64_t &outRowId, const std::string &sql, const std::vector &bindArgs) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != 0) { - LOG_ERROR("rdbStore BeginExecuteSql failed"); - return errCode; - } - auto con = isReadOnly ? readConnection : connection; - errCode = con->ExecuteForLastInsertedRowId(outRowId, sql, bindArgs); - if (errCode != E_OK) { - LOG_ERROR("rdbStore ExecuteForLastInsertedRowId FAILED"); - } - ReleaseConnection(isReadOnly); - return errCode; -} - -int StoreSession::ExecuteGetLong(int64_t &outValue, const std::string &sql, const std::vector &bindArgs) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != 0) { - return errCode; - } - auto con = isReadOnly ? readConnection : connection; - errCode = con->ExecuteGetLong(outValue, sql, bindArgs); - ReleaseConnection(isReadOnly); - return errCode; -} - -int StoreSession::ExecuteGetString( - std::string &outValue, const std::string &sql, const std::vector &bindArgs) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != 0) { - return errCode; - } - auto con = isReadOnly ? readConnection : connection; - std::string sqlstr = sql; - int type = SqliteDatabaseUtils::GetSqlStatementType(sqlstr); - if (type == STATEMENT_PRAGMA) { - ReleaseConnection(isReadOnly); - AcquireConnection(false); - con = connection; - } - - errCode = con->ExecuteGetString(outValue, sql, bindArgs); - ReleaseConnection(isReadOnly); - return errCode; -} - -int StoreSession::Backup(const std::string databasePath, const std::vector destEncryptKey) -{ - std::vector bindArgs; - bindArgs.push_back(ValueObject(databasePath)); - if (destEncryptKey.size() != 0) { - bindArgs.push_back(ValueObject(destEncryptKey)); - } else { - std::string str = ""; - bindArgs.push_back(ValueObject(str)); - } - - int errCode = ExecuteSql(ATTACH_BACKUP_SQL, bindArgs); - if (errCode != E_OK) { - LOG_ERROR("ExecuteSql ATTACH_BACKUP_SQL error %{public}d", errCode); - return errCode; - } - int64_t count; - errCode = ExecuteGetLong(count, EXPORT_SQL, std::vector()); - if (errCode != E_OK) { - LOG_ERROR("ExecuteSql EXPORT_SQL error %{public}d", errCode); - return errCode; - } - - errCode = ExecuteSql(DETACH_BACKUP_SQL, std::vector()); - if (errCode != E_OK) { - LOG_ERROR("ExecuteSql DETACH_BACKUP_SQL error %{public}d", errCode); - return errCode; - } - return E_OK; -} - -// Checks whether this thread holds a database connection. -bool StoreSession::IsHoldingConnection() const -{ - if (connection == nullptr && readConnection == nullptr) { - return false; - } else { - return true; - } -} - -int StoreSession::CheckNoTransaction() const -{ - int errorCode = 0; - if (connectionPool.getTransactionStack().empty()) { - errorCode = E_STORE_SESSION_NO_CURRENT_TRANSACTION; - return errorCode; - } - return E_OK; -} - -int StoreSession::GiveConnectionTemporarily(int64_t milliseconds) -{ - int errorCode = CheckNoTransaction(); - if (errorCode != E_OK) { - return errorCode; - } - BaseTransaction transaction = connectionPool.getTransactionStack().top(); - if (transaction.IsMarkedSuccessful() || connectionPool.getTransactionStack().size() > 1) { - errorCode = E_STORE_SESSION_NOT_GIVE_CONNECTION_TEMPORARILY; - return errorCode; - } - - if (milliseconds > 0) { - std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); - } - BeginTransaction(); - return E_OK; -} - -int StoreSession::Attach( - const std::string &alias, const std::string &pathName, const std::vector destEncryptKey) -{ - std::string journalMode; - int errCode = ExecuteGetString(journalMode, "PRAGMA journal_mode", std::vector()); - if (errCode != E_OK) { - LOG_ERROR("RdbStoreImpl CheckAttach fail to get journal mode : %{public}d", errCode); - return errCode; - } - journalMode = SqliteUtils::StrToUpper(journalMode); - if (journalMode == "WAL") { - LOG_ERROR("RdbStoreImpl attach is not supported in WAL mode"); - return E_NOT_SUPPORTED_ATTACH_IN_WAL_MODE; - } - - std::vector bindArgs; - bindArgs.push_back(ValueObject(pathName)); - bindArgs.push_back(ValueObject(alias)); - if (destEncryptKey.size() != 0) { - bindArgs.push_back(ValueObject(destEncryptKey)); - } else { - std::string str = ""; - bindArgs.push_back(ValueObject(str)); - } - errCode = ExecuteSql(ATTACH_SQL, bindArgs); - if (errCode != E_OK) { - LOG_ERROR("ExecuteSql ATTACH_SQL error %{public}d", errCode); - return errCode; - } - - return E_OK; -} - -int StoreSession::BeginTransaction(TransactionObserver *transactionObserver) -{ - if (connectionPool.getTransactionStack().empty()) { - AcquireConnection(false); - - int errCode = connection->ExecuteSql("BEGIN EXCLUSIVE;"); - if (errCode != E_OK) { - ReleaseConnection(false); - return errCode; - } - } - - if (transactionObserver != nullptr) { - transactionObserver->OnBegin(); - } - - BaseTransaction transaction(connectionPool.getTransactionStack().size()); - connectionPool.getTransactionStack().push(transaction); - - return E_OK; -} - -bool StoreSession::IsInTransaction() const -{ - return !connectionPool.getTransactionStack().empty(); -} - -std::shared_ptr StoreSession::BeginStepQuery( - int &errCode, const std::string &sql, const std::vector &selectionArgs) -{ - if (isInStepQuery == true) { - LOG_ERROR("StoreSession BeginStepQuery fail : begin more step query in one session !"); - errCode = E_MORE_STEP_QUERY_IN_ONE_SESSION; - return nullptr; // fail,already in - } - - if (SqliteUtils::GetSqlStatementType(sql) != SqliteUtils::STATEMENT_SELECT) { - LOG_ERROR("StoreSession BeginStepQuery fail : not select sql !"); - errCode = E_EXECUTE_IN_STEP_QUERY; - return nullptr; - } - - AcquireConnection(true); - std::shared_ptr statement = readConnection->BeginStepQuery(errCode, sql, selectionArgs); - if (statement == nullptr) { - ReleaseConnection(true); - return nullptr; - } - isInStepQuery = true; - return statement; -} - -int StoreSession::EndStepQuery() -{ - if (isInStepQuery == false) { - return E_OK; - } - - int errCode = readConnection->EndStepQuery(); - isInStepQuery = false; - ReleaseConnection(true); - return errCode; -} - -#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) -int StoreSession::ExecuteForSharedBlock(int &rowNum, std::string sql, const std::vector &bindArgs, - AppDataFwk::SharedBlock *sharedBlock, int startPos, int requiredPos, bool isCountAllRows) -{ - bool isReadOnly = false; - int errCode = BeginExecuteSql(sql, isReadOnly); - if (errCode != E_OK) { - return errCode; - } - SqliteConnection *con = isReadOnly ? readConnection : connection; - errCode = - con->ExecuteForSharedBlock(rowNum, sql, bindArgs, sharedBlock, startPos, requiredPos, isCountAllRows); - ReleaseConnection(isReadOnly); - return errCode; -} -#endif - -int StoreSession::BeginTransaction() -{ - AcquireConnection(false); - - BaseTransaction transaction(connectionPool.getTransactionStack().size()); - int errCode = connection->ExecuteSql(transaction.GetTransactionStr()); - if (errCode != E_OK) { - LOG_DEBUG("storeSession BeginTransaction Failed"); - ReleaseConnection(false); - return errCode; - } - connectionPool.getTransactionStack().push(transaction); - ReleaseConnection(false); - return E_OK; -} - -int StoreSession::Commit() -{ - if (connectionPool.getTransactionStack().empty()) { - return E_OK; - } - BaseTransaction transaction = connectionPool.getTransactionStack().top(); - std::string sqlStr = transaction.GetCommitStr(); - if (sqlStr.size() <= 1) { - connectionPool.getTransactionStack().pop(); - return E_OK; - } - - AcquireConnection(false); - int errCode = connection->ExecuteSql(sqlStr); - ReleaseConnection(false); - if (errCode != E_OK) { - // if error the transaction is leaving for rollback - return errCode; - } - connectionPool.getTransactionStack().pop(); - return E_OK; -} - -int StoreSession::RollBack() -{ - std::stack transactionStack = connectionPool.getTransactionStack(); - if (transactionStack.empty()) { - return E_NO_TRANSACTION_IN_SESSION; - } - BaseTransaction transaction = transactionStack.top(); - transactionStack.pop(); - if (transaction.GetType() != TransType::ROLLBACK_SELF && !transactionStack.empty()) { - transactionStack.top().SetChildFailure(true); - } - AcquireConnection(false); - int errCode = connection->ExecuteSql(transaction.GetRollbackStr()); - ReleaseConnection(false); - if (errCode != E_OK) { - LOG_ERROR("storeSession RollBack Fail"); - } - - return errCode; -} - -int StoreSession::GetConnectionUseCount() -{ - return connectionUseCount; -} -} // namespace OHOS::NativeRdb diff --git a/interfaces/inner_api/rdb/BUILD.gn b/interfaces/inner_api/rdb/BUILD.gn index c5a0a05b6a3ad3b2ffbf782b17cd0ffb49529baf..b00747c85014ca506d818825bc73d4e1ec85fe79 100644 --- a/interfaces/inner_api/rdb/BUILD.gn +++ b/interfaces/inner_api/rdb/BUILD.gn @@ -104,7 +104,6 @@ base_sources = [ "${relational_store_native_path}/rdb/src/sqlite_statement.cpp", "${relational_store_native_path}/rdb/src/sqlite_utils.cpp", "${relational_store_native_path}/rdb/src/step_result_set.cpp", - "${relational_store_native_path}/rdb/src/store_session.cpp", "${relational_store_native_path}/rdb/src/string_utils.cpp", "${relational_store_native_path}/rdb/src/value_object.cpp", "${relational_store_native_path}/rdb/src/values_bucket.cpp",