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