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 KV_STORE_RESULT_SET_H
17 #define KV_STORE_RESULT_SET_H
18 
19 #include "distributeddb/result_set.h"
20 #include "store_types.h"
21 
22 namespace DistributedDB {
23 class KvStoreResultSet : public ResultSet {
24 public:
~KvStoreResultSet()25     DB_API virtual ~KvStoreResultSet() {};
26 
27     // Returns the count of rows in the result set.
28     DB_API virtual int GetCount() const = 0;
29 
30     // Returns the current read position of the result set.
31     DB_API virtual int GetPosition() const = 0;
32 
33     // Move the read position to the first row, return false if the result set is empty.
34     DB_API virtual bool MoveToFirst() = 0;
35 
36     // Move the read position to the last row, return false if the result set is empty.
37     DB_API virtual bool MoveToLast() = 0;
38 
39     // Move the read position to the next row, return false if the result set is empty
40     // or the read position is already past the last entry in the result set.
41     DB_API virtual bool MoveToNext() = 0;
42 
43     // Move the read position to the previous row, return false if the result set is empty
44     // or the read position is already before the first entry in the result set.
45     DB_API virtual bool MoveToPrevious() = 0;
46 
47     // Move the read position by a relative amount from the current position.
48     DB_API virtual bool Move(int offset) = 0;
49 
50     // Move the read position to an absolute position value.
51     DB_API virtual bool MoveToPosition(int position) = 0;
52 
53     // Returns whether the read position is pointing to the first row.
54     DB_API virtual bool IsFirst() const = 0;
55 
56     // Returns whether the read position is pointing to the last row.
57     DB_API virtual bool IsLast() const = 0;
58 
59     // Returns whether the read position is before the first row.
60     DB_API virtual bool IsBeforeFirst() const = 0;
61 
62     // Returns whether the read position is after the last row
63     DB_API virtual bool IsAfterLast() const = 0;
64 
65     // Get a key-value entry.
66     DB_API virtual DBStatus GetEntry(Entry &entry) const = 0;
67 
68     // Returns whether the result set is empty.
69     DB_API virtual bool IsClosed() const = 0;
70 
71     // Clear the result set. Set the position -1.
72     DB_API virtual void Close() = 0;
73 
74     // Get column names.
75     DB_API virtual void GetColumnNames(std::vector<std::string> &columnNames) const = 0;
76 
77     // Get the column name by column index. Returns OK, NOT_FOUND or NONEXISTENT.
78     DB_API virtual DBStatus GetColumnType(int columnIndex, ColumnType &columnType) const = 0;
79 
80     // Get the column index by column name. Returns OK, NOT_FOUND or NONEXISTENT.
81     DB_API virtual DBStatus GetColumnIndex(const std::string &columnName, int &columnIndex) const = 0;
82 
83     // Get the column name by column index. Returns OK, NOT_FOUND or NONEXISTENT.
84     DB_API virtual DBStatus GetColumnName(int columnIndex, std::string &columnName) const = 0;
85 
86     // Get blob. Returns OK,, NOT_FOUND NONEXISTENT or TYPE_MISMATCH.
87     DB_API virtual DBStatus Get(int columnIndex, std::vector<uint8_t> &value) const = 0;
88 
89     // Get string. Returns OK, NOT_FOUND, NONEXISTENT or TYPE_MISMATCH.
90     DB_API virtual DBStatus Get(int columnIndex, std::string &value) const = 0;
91 
92     // Get int64. Returns OK, NOT_FOUND, NONEXISTENT or TYPE_MISMATCH.
93     DB_API virtual DBStatus Get(int columnIndex, int64_t &value) const = 0;
94 
95     // Get double. Returns OK, NOT_FOUND, NONEXISTENT or TYPE_MISMATCH.
96     DB_API virtual DBStatus Get(int columnIndex, double &value) const = 0;
97 
98     // Get whether the column value is null. Returns OK, NOT_FOUND or NONEXISTENT.
99     DB_API virtual DBStatus IsColumnNull(int columnIndex, bool &isNull) const = 0;
100 
101     // Get the row record. Returns OK, NOT_FOUND or NOT_SUPPORT.
102     DB_API virtual DBStatus GetRow(std::map<std::string, VariantData> &data) const = 0;
103 };
104 } // namespace DistributedDB
105 
106 #endif // KV_STORE_RESULT_SET_H