125c1cde8Sopenharmony_ci/*
225c1cde8Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
325c1cde8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
425c1cde8Sopenharmony_ci * you may not use this file except in compliance with the License.
525c1cde8Sopenharmony_ci * You may obtain a copy of the License at
625c1cde8Sopenharmony_ci *
725c1cde8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
825c1cde8Sopenharmony_ci *
925c1cde8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1025c1cde8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1125c1cde8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1225c1cde8Sopenharmony_ci * See the License for the specific language governing permissions and
1325c1cde8Sopenharmony_ci * limitations under the License.
1425c1cde8Sopenharmony_ci */
1525c1cde8Sopenharmony_ci
1625c1cde8Sopenharmony_ci#ifndef DATA_STORAGE_RDB_BASE_HELPER_H
1725c1cde8Sopenharmony_ci#define DATA_STORAGE_RDB_BASE_HELPER_H
1825c1cde8Sopenharmony_ci
1925c1cde8Sopenharmony_ci#include <stdint.h>
2025c1cde8Sopenharmony_ci
2125c1cde8Sopenharmony_ci#include "data_storage_log_wrapper.h"
2225c1cde8Sopenharmony_ci#include "iosfwd"
2325c1cde8Sopenharmony_ci#include "memory"
2425c1cde8Sopenharmony_ci#include "string"
2525c1cde8Sopenharmony_ci#include "vector"
2625c1cde8Sopenharmony_ci
2725c1cde8Sopenharmony_cinamespace OHOS {
2825c1cde8Sopenharmony_cinamespace NativeRdb {
2925c1cde8Sopenharmony_ciclass AbsRdbPredicates;
3025c1cde8Sopenharmony_ciclass ResultSet;
3125c1cde8Sopenharmony_ciclass RdbOpenCallback;
3225c1cde8Sopenharmony_ciclass RdbStore;
3325c1cde8Sopenharmony_ciclass RdbStoreConfig;
3425c1cde8Sopenharmony_ciclass ValueObject;
3525c1cde8Sopenharmony_ciclass ValuesBucket;
3625c1cde8Sopenharmony_ci} // namespace NativeRdb
3725c1cde8Sopenharmony_cinamespace Telephony {
3825c1cde8Sopenharmony_ciclass RdbBaseHelper {
3925c1cde8Sopenharmony_cipublic:
4025c1cde8Sopenharmony_ci    RdbBaseHelper() {};
4125c1cde8Sopenharmony_ci    ~RdbBaseHelper() = default;
4225c1cde8Sopenharmony_ci    int Insert(int64_t &id, const NativeRdb::ValuesBucket &initialValues, const std::string &table);
4325c1cde8Sopenharmony_ci    int BatchInsert(int64_t &id, const NativeRdb::ValuesBucket &initialValues, const std::string &table);
4425c1cde8Sopenharmony_ci    int Update(int &changedRows, const std::string &table, const NativeRdb::ValuesBucket &values,
4525c1cde8Sopenharmony_ci        const std::string &whereClause = "",
4625c1cde8Sopenharmony_ci        const std::vector<std::string> &whereArgs = std::vector<std::string>());
4725c1cde8Sopenharmony_ci    int Update(int &changedRows, const NativeRdb::ValuesBucket &values, const NativeRdb::AbsRdbPredicates &predicates);
4825c1cde8Sopenharmony_ci    int Delete(int &changedRows, const std::string &table, const std::string &whereClause = "",
4925c1cde8Sopenharmony_ci        const std::vector<std::string> &whereArgs = std::vector<std::string>());
5025c1cde8Sopenharmony_ci    int Delete(int &deletedRows, const NativeRdb::AbsRdbPredicates &predicates);
5125c1cde8Sopenharmony_ci    std::shared_ptr<NativeRdb::ResultSet> QuerySql(
5225c1cde8Sopenharmony_ci        const std::string &sql, const std::vector<std::string> &selectionArgs = std::vector<std::string>());
5325c1cde8Sopenharmony_ci    std::shared_ptr<NativeRdb::ResultSet> Query(
5425c1cde8Sopenharmony_ci        const NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> columns);
5525c1cde8Sopenharmony_ci    int ExecuteSql(const std::string &sql);
5625c1cde8Sopenharmony_ci    int ExecuteSql(const std::string &sql, const std::vector<NativeRdb::ValueObject> &bindArgs);
5725c1cde8Sopenharmony_ci    void CreateRdbStore(const NativeRdb::RdbStoreConfig &config, int version,
5825c1cde8Sopenharmony_ci        NativeRdb::RdbOpenCallback &openCallback, int &errCode);
5925c1cde8Sopenharmony_ci    int BeginTransaction();
6025c1cde8Sopenharmony_ci    int RollBack();
6125c1cde8Sopenharmony_ci    int Commit();
6225c1cde8Sopenharmony_ci
6325c1cde8Sopenharmony_ci    void ReplaceAllStr(std::string &path, const std::string &oldStr, const std::string &newStr);
6425c1cde8Sopenharmony_ci
6525c1cde8Sopenharmony_cipublic:
6625c1cde8Sopenharmony_ci    const std::string FOLDER_PATH = "/data/accounts/account_0/appdata/com.ohos.smsmmsability/database/";
6725c1cde8Sopenharmony_ci
6825c1cde8Sopenharmony_ciprotected:
6925c1cde8Sopenharmony_ci    std::shared_ptr<NativeRdb::RdbStore> store_;
7025c1cde8Sopenharmony_ci
7125c1cde8Sopenharmony_ciprivate:
7225c1cde8Sopenharmony_ci    int IsExistStore();
7325c1cde8Sopenharmony_ci};
7425c1cde8Sopenharmony_ci} // namespace Telephony
7525c1cde8Sopenharmony_ci} // namespace OHOS
7625c1cde8Sopenharmony_ci#endif // DATA_STORAGE_RDB_BASE_HELPER_H
77