1 /* 2 * Copyright (C) 2021 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 DATA_STORAGE_RDB_BASE_HELPER_H 17 #define DATA_STORAGE_RDB_BASE_HELPER_H 18 19 #include "rdb_helper.h" 20 #include "rdb_base_callback.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 class RdbBaseHelper { 25 public: RdbBaseHelper()26 RdbBaseHelper() {}; 27 ~RdbBaseHelper() = default; 28 int Insert(int64_t &id, const NativeRdb::ValuesBucket &initialValues, const std::string &table); 29 int BatchInsert(int64_t &id, const NativeRdb::ValuesBucket &initialValues, const std::string &table); 30 int Update(int &changedRows, const std::string &table, const NativeRdb::ValuesBucket &values, 31 const std::string &whereClause = "", 32 const std::vector<std::string> &whereArgs = std::vector<std::string>()); 33 int Update(int &changedRows, const NativeRdb::ValuesBucket &values, const NativeRdb::AbsRdbPredicates &predicates); 34 int Delete(int &changedRows, const std::string &table, const std::string &whereClause = "", 35 const std::vector<std::string> &whereArgs = std::vector<std::string>()); 36 int Delete(int &deletedRows, const NativeRdb::AbsRdbPredicates &predicates); 37 std::unique_ptr<NativeRdb::AbsSharedResultSet> QuerySql( 38 const std::string &sql, const std::vector<std::string> &selectionArgs = std::vector<std::string>()); 39 std::unique_ptr<NativeRdb::AbsSharedResultSet> Query( 40 const NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> columns); 41 int ExecuteSql(const std::string &sql); 42 int ExecuteSql(const std::string &sql, const std::vector<NativeRdb::ValueObject> &bindArgs); 43 void CreateRdbStore(const NativeRdb::RdbStoreConfig &config, int version, 44 NativeRdb::RdbOpenCallback &openCallback, int &errCode); 45 int BeginTransaction(); 46 int RollBack(); 47 int MarkAsCommit(); 48 int Commit(); 49 int EndTransaction(); 50 51 void ReplaceAllStr(std::string &path, const std::string &oldStr, const std::string &newStr); 52 53 public: 54 const std::string FOLDER_PATH = "/data/accounts/account_0/appdata/com.ohos.smsmmsability/database/"; 55 56 private: 57 int IsExistStore(); 58 59 private: 60 std::shared_ptr<NativeRdb::RdbStore> store_; 61 }; 62 } // namespace Telephony 63 } // namespace OHOS 64 #endif // DATA_STORAGE_RDB_BASE_HELPER_H 65