• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NATIVE_RDB_RDB_STORE_H
17 #define NATIVE_RDB_RDB_STORE_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "abs_rdb_predicates.h"
24 #include "abs_shared_result_set.h"
25 #include "result_set.h"
26 #include "value_object.h"
27 #include "values_bucket.h"
28 
29 namespace OHOS {
30 namespace NativeRdb {
31 
32 enum class ConflictResolution {
33     ON_CONFLICT_NONE = 0,
34     ON_CONFLICT_ROLLBACK,
35     ON_CONFLICT_ABORT,
36     ON_CONFLICT_FAIL,
37     ON_CONFLICT_IGNORE,
38     ON_CONFLICT_REPLACE,
39 };
40 
41 class RdbStore {
42 public:
~RdbStore()43     virtual ~RdbStore(){};
44     virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) = 0;
45     virtual int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) = 0;
46     virtual int InsertWithConflictResolution(int64_t &outRowId, const std::string &table,
47         const ValuesBucket &initialValues,
48         ConflictResolution conflictResolution = ConflictResolution::ON_CONFLICT_NONE) = 0;
49     virtual int Update(int &changedRows, const std::string &table, const ValuesBucket &values,
50         const std::string &whereClause = "",
51         const std::vector<std::string> &whereArgs = std::vector<std::string>()) = 0;
52     virtual int UpdateWithConflictResolution(int &changedRows, const std::string &table, const ValuesBucket &values,
53         const std::string &whereClause = "", const std::vector<std::string> &whereArgs = std::vector<std::string>(),
54         ConflictResolution conflictResolution = ConflictResolution::ON_CONFLICT_NONE) = 0;
55     virtual int Delete(int &deletedRows, const std::string &table, const std::string &whereClause = "",
56         const std::vector<std::string> &whereArgs = std::vector<std::string>()) = 0;
57     virtual std::unique_ptr<AbsSharedResultSet> Query(int &errCode, bool distinct, const std::string &table,
58         const std::vector<std::string> &columns, const std::string &selection = "",
59         const std::vector<std::string> &selectionArgs = std::vector<std::string>(), const std::string &groupBy = "",
60         const std::string &having = "", const std::string &orderBy = "", const std::string &limit = "") = 0;
61     virtual std::unique_ptr<AbsSharedResultSet> QuerySql(
62         const std::string &sql, const std::vector<std::string> &selectionArgs = std::vector<std::string>()) = 0;
63     virtual std::unique_ptr<ResultSet> QueryByStep(
64         const std::string &sql, const std::vector<std::string> &selectionArgs = std::vector<std::string>()) = 0;
65     virtual int ExecuteSql(
66         const std::string &sql, const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>()) = 0;
67     virtual int ExecuteAndGetLong(int64_t &outValue, const std::string &sql,
68         const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>()) = 0;
69     virtual int ExecuteAndGetString(std::string &outValue, const std::string &sql,
70         const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>()) = 0;
71     virtual int ExecuteForLastInsertedRowId(int64_t &outValue, const std::string &sql,
72         const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>()) = 0;
73     virtual int ExecuteForChangedRowCount(int64_t &outValue, const std::string &sql,
74         const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>()) = 0;
75     virtual int Backup(const std::string databasePath, const std::vector<uint8_t> destEncryptKey) = 0;
76     virtual int Attach(
77         const std::string &alias, const std::string &pathName, const std::vector<uint8_t> destEncryptKey) = 0;
78 
79     virtual int Count(int64_t &outValue, const AbsRdbPredicates &predicates) = 0;
80     virtual std::unique_ptr<AbsSharedResultSet> Query(
81         const AbsRdbPredicates &predicates, const std::vector<std::string> columns) = 0;
82     virtual int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) = 0;
83     virtual int Delete(int &deletedRows, const AbsRdbPredicates &predicates) = 0;
84 
85     virtual int GetVersion(int &version) = 0;
86     virtual int SetVersion(int version) = 0;
87     virtual int BeginTransaction() = 0;
88     virtual int MarkAsCommit() = 0;
89     virtual int EndTransaction() = 0;
90     virtual bool IsInTransaction() = 0;
91     virtual int ChangeEncryptKey(const std::vector<uint8_t> &newKey) = 0;
92     virtual std::string GetPath() = 0;
93 };
94 
95 } // namespace NativeRdb
96 } // namespace OHOS
97 #endif
98