1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DATASHARESERVICE_RDB_DELEGATE_H 17 #define DATASHARESERVICE_RDB_DELEGATE_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "concurrent_map.h" 23 #include "db_delegate.h" 24 #include "rdb_errno.h" 25 #include "rdb_helper.h" 26 #include "rdb_store.h" 27 #include "uri_utils.h" 28 #include "rdb_utils.h" 29 30 namespace OHOS::DataShare { 31 using namespace OHOS::NativeRdb; 32 class RdbDelegate final : public DBDelegate { 33 public: 34 explicit RdbDelegate(const std::string &dir, int version, bool registerFunction, 35 bool isEncrypt, const std::string &secretMetaKey); 36 int64_t Insert(const std::string &tableName, const DataShareValuesBucket &valuesBucket) override; 37 int64_t Update(const std::string &tableName, const DataSharePredicates &predicate, 38 const DataShareValuesBucket &valuesBucket) override; 39 int64_t Delete(const std::string &tableName, const DataSharePredicates &predicate) override; 40 std::shared_ptr<DataShareResultSet> Query(const std::string &tableName, const DataSharePredicates &predicates, 41 const std::vector<std::string> &columns, int &errCode) override; 42 std::string Query(const std::string &sql, const std::vector<std::string> &selectionArgs) override; 43 std::shared_ptr<NativeRdb::ResultSet> QuerySql(const std::string &sql) override; 44 45 private: 46 static std::atomic<int32_t> resultSetCount; 47 std::shared_ptr<RdbStore> store_; 48 int errCode_ = E_OK; 49 }; 50 class DefaultOpenCallback : public RdbOpenCallback { 51 public: OnCreate(RdbStore & rdbStore)52 int OnCreate(RdbStore &rdbStore) override 53 { 54 return E_OK; 55 } OnUpgrade(RdbStore & rdbStore,int oldVersion,int newVersion)56 int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override 57 { 58 return E_OK; 59 } 60 }; 61 } // namespace OHOS::DataShare 62 #endif // DATASHARESERVICE_RDB_DELEGATE_H 63