1 /*
2  * Copyright (c) 2024 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 OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_INCLUDE_STATEMENT_H
17 #define OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_INCLUDE_STATEMENT_H
18 #include <functional>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "value_object.h"
24 namespace OHOS::NativeRdb {
25 struct SharedBlockInfo;
26 class Statement {
27 public:
28     static constexpr int32_t COLUMN_TYPE_INVALID = 0;
29     static constexpr int32_t COLUMN_TYPE_ASSET = 1000;
30     static constexpr int32_t COLUMN_TYPE_ASSETS = 1001;
31     static constexpr int32_t COLUMN_TYPE_FLOATS = 1002;
32     static constexpr int32_t COLUMN_TYPE_BIGINT = 1003;
33 
34     virtual ~Statement() = default;
35     virtual int32_t Prepare(const std::string &sql) = 0;
36     virtual int32_t Bind(const std::vector<ValueObject> &args = {}) = 0;
37     virtual std::pair<int32_t, int32_t> Count() = 0;
38     virtual int32_t Step() = 0;
39     virtual int32_t Reset() = 0;
40     virtual int32_t Finalize() = 0;
41     virtual int32_t Execute(const std::vector<ValueObject> &args = {}) = 0;
42     virtual int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) = 0;
43 
44     virtual std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args = {}) = 0;
45     virtual int32_t Changes() const = 0;
46     virtual int64_t LastInsertRowId() const = 0;
47 
48     virtual int32_t GetColumnCount() const = 0;
49     virtual std::pair<int32_t, std::string> GetColumnName(int32_t index) const = 0;
50     virtual std::pair<int32_t, int32_t> GetColumnType(int32_t index) const = 0;
51     virtual std::pair<int32_t, size_t> GetSize(int32_t index) const = 0;
52     virtual std::pair<int32_t, ValueObject> GetColumn(int32_t index) const = 0;
53     virtual bool ReadOnly() const = 0;
54     virtual bool SupportBlockInfo() const = 0;
55     virtual int32_t FillBlockInfo(SharedBlockInfo *info) const = 0;
ModifyLockStatus(const std::string & table,const std::vector<std::vector<uint8_t>> & hashKeys,bool isLock)56     virtual int ModifyLockStatus(const std::string &table, const std::vector<std::vector<uint8_t>> &hashKeys,
57         bool isLock)
58     {
59         return 0;
60     }
61 
62     static constexpr int INVALID_COUNT = -1;
63 };
64 } // namespace OHOS::NativeRdb
65 #endif // OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_INCLUDE_STATEMENT_H
66