• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sg_sqlite_helper.h"
20 #include "i_model_info.h"
21 #include "store_define.h"
22 
23 namespace OHOS::Security::SecurityGuard {
24 class Database {
25 public:
26     Database() = default;
27     virtual ~Database() = default;
28     void CreateRdbStore(const std::string &dbName, const std::string &dbPath, int version,
29         const std::vector<std::string> &createSqls, int &errCode);
30     int Insert(int64_t &outRowId, const std::string &table, const GenericValues &value);
31     int BatchInsert(int64_t &outInsertNum, const std::string &table,
32         const std::vector<GenericValues> &initialBatchValues);
33     int Update(int &changedRows, const std::string &table, const GenericValues &value);
34     int Delete(int &deletedRows, const std::string &table, const GenericValues &conditions = {});
35     int Query(const std::string &table, const GenericValues &conditions,
36         std::vector<GenericValues> &results, const QueryOptions &options = {});
37     int ExecuteSql(const std::string &sql);
38     int ExecuteAndGetLong(int64_t &outValue, const std::string &sql,
39         const std::vector<std::string> &bindArgs);
40     int Count(int64_t &outValue, const std::string &table,  const GenericValues &conditions = {},
41          const QueryOptions &options = {});
42     int BeginTransaction();
43     int RollBack();
44     int Commit();
45     int Attach(const std::string &alias, const std::string &pathName,
46         const std::vector<uint8_t> destEncryptKey);
47 
48 private:
49     int IsExistStore();
50     std::shared_ptr<SgSqliteHelper> store_;
51 };
52 }  // OHOS::Security::SecurityGuard
53 
54 #endif // SECURITY_GUARD_EVENT_STORE_H