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