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 SECURITY_GUARD_EVENT_STORE_H
17#define SECURITY_GUARD_EVENT_STORE_H
18
19#include "rdb_open_callback.h"
20#include "rdb_predicates.h"
21#include "rdb_store.h"
22#include "rdb_store_config.h"
23
24#include "config_define.h"
25#include "store_define.h"
26
27namespace OHOS::Security::SecurityGuard {
28class Database {
29public:
30    Database() = default;
31    ~Database() = default;
32    void CreateRdbStore(const NativeRdb::RdbStoreConfig &config, int version,
33        NativeRdb::RdbOpenCallback &openCallback, int &errCode);
34    int Insert(int64_t &outRowId, const std::string &table, const NativeRdb::ValuesBucket &initialValues);
35    int BatchInsert(int64_t &outInsertNum, const std::string &table,
36        const std::vector<NativeRdb::ValuesBucket> &initialBatchValues);
37    int Update(int &changedRows, const NativeRdb::ValuesBucket &values, const NativeRdb::AbsRdbPredicates &predicates);
38    int Delete(int &deletedRows, const NativeRdb::AbsRdbPredicates &predicates);
39    std::shared_ptr<NativeRdb::ResultSet> Query(
40        const NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> columns);
41    int ExecuteSql(const std::string &sql);
42    int ExecuteAndGetLong(int64_t &outValue, const std::string &sql,
43        const std::vector<NativeRdb::ValueObject> &bindArgs = std::vector<NativeRdb::ValueObject>());
44    int Count(int64_t &outValue, const NativeRdb::AbsRdbPredicates &predicates);
45    int BeginTransaction();
46    int RollBack();
47    int Commit();
48    int Attach(const std::string &alias, const std::string &pathName, const std::vector<uint8_t> destEncryptKey);
49
50private:
51    int IsExistStore();
52    std::shared_ptr<NativeRdb::RdbStore> store_;
53};
54}  // OHOS::Security::SecurityGuard
55
56#endif // SECURITY_GUARD_EVENT_STORE_H
57