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 NATIVE_DATASHARE_COMMON_INCLUDE_RESULT_SET_H 17 #define NATIVE_DATASHARE_COMMON_INCLUDE_RESULT_SET_H 18 19 #include <string> 20 #include <vector> 21 namespace OHOS { 22 namespace DataShare { 23 /* Value returned by getDataType(int) */ 24 enum class DataType { 25 TYPE_NULL = 0, 26 TYPE_INTEGER, 27 TYPE_FLOAT, 28 TYPE_STRING, 29 TYPE_BLOB, 30 }; 31 32 class ResultSet { 33 public: ~ResultSet()34 virtual ~ResultSet() {} 35 36 /** 37 * Returns a string array holding the names of all of the columns in the 38 * result set. 39 * 40 * return the names of the columns contains in this query result. 41 */ 42 virtual int GetAllColumnNames(std::vector<std::string> &columnNames) = 0; 43 44 /** 45 * Return the total number of columns 46 * 47 * return the number of columns 48 */ 49 virtual int GetColumnCount(int &count) = 0; 50 51 /** 52 * Returns data type of the given column's value. 53 * 54 * param columnIndex the zero-based index of the target column. 55 * return column value type. 56 */ 57 virtual int GetDataType(int columnIndex, DataType &dataType) = 0; 58 59 /** 60 * Returns the zero-based index for the given column name. 61 * 62 * param columnName the name of the column. 63 * return the column index for the given column, or -1 if 64 * the column does not exist. 65 */ 66 virtual int GetColumnIndex(const std::string &columnName, int &columnIndex) = 0; 67 68 /** 69 * Returns the column name at the given column index. 70 * 71 * param columnIndex the zero-based index. 72 * return the column name for the given index. 73 */ 74 virtual int GetColumnName(int columnIndex, std::string &columnName) = 0; 75 76 /** 77 * return the numbers of rows in the result set. 78 */ 79 virtual int GetRowCount(int &count) = 0; 80 81 /** 82 * Returns the current position of the cursor in the result set. 83 * The value is zero-based. When the result set is first returned the cursor 84 * will be at position -1, which is before the first row. 85 * After the last row is returned another call to next() will leave the cursor past 86 * the last entry, at a position of count(). 87 * 88 * return the current cursor position. 89 */ 90 virtual int GetRowIndex(int &position) const = 0; 91 92 /** 93 * Move the cursor a relative amount from current position. Positive offset move forward, 94 * negative offset move backward. 95 * 96 * param offset the offset to be applied from the current position. 97 * return whether the requested move succeeded. 98 */ 99 virtual int GoTo(int offset) = 0; 100 101 /** 102 * Move the cursor to an absolute position. 103 * 104 * param position the zero-based position to move to. 105 * return whether the requested move succeeded. 106 */ 107 virtual int GoToRow(int position) = 0; 108 109 /** 110 * Move the cursor to the first row. 111 * 112 * return whether the requested move succeeded. 113 */ 114 virtual int GoToFirstRow() = 0; 115 116 /** 117 * Move the cursor to the last row. 118 * 119 * return whether the requested move succeeded. 120 */ 121 virtual int GoToLastRow() = 0; 122 123 /** 124 * Move the cursor to the next row. 125 * 126 * return whether the requested move succeeded. 127 */ 128 virtual int GoToNextRow() = 0; 129 130 /** 131 * Move the cursor to the previous row. 132 * 133 * return whether the requested move succeeded. 134 */ 135 virtual int GoToPreviousRow() = 0; 136 137 /** 138 * Returns whether the cursor is pointing to the position after the last 139 * row. 140 * 141 * return whether the cursor is before the first row. 142 */ 143 virtual int IsEnded(bool &result) = 0; 144 145 /** 146 * Returns whether the cursor is pointing to the position before the first 147 * row. 148 * 149 * return whether the cursor is before the first row. 150 */ 151 virtual int IsStarted(bool &result) const = 0; 152 153 /** 154 * Returns whether the cursor is pointing to the first row. 155 * 156 * return whether the cursor is pointing at the first entry. 157 */ 158 virtual int IsAtFirstRow(bool &result) const = 0; 159 160 /** 161 * Returns whether the cursor is pointing to the last row. 162 * 163 * return whether the cursor is pointing at the last entry. 164 */ 165 virtual int IsAtLastRow(bool &result) = 0; 166 167 /** 168 * Returns the value of the requested column as a byte array. 169 * 170 * param columnIndex the zero-based index of the target column. 171 * return the value of the requested column as a byte array. 172 */ 173 virtual int GetBlob(int columnIndex, std::vector<uint8_t> &blob) = 0; 174 175 /** 176 * Returns the value of the requested column as a String. 177 * 178 * param columnIndex the zero-based index of the target column. 179 * return the value of the requested column as a String. 180 */ 181 virtual int GetString(int columnIndex, std::string &value) = 0; 182 183 /** 184 * Returns the value of the requested column as a int. 185 * 186 * param columnIndex the zero-based index of the target column. 187 * return the value of the requested column as a int. 188 */ 189 virtual int GetInt(int columnIndex, int &value) = 0; 190 191 /** 192 * Returns the value of the requested column as a long. 193 * 194 * param columnIndex the zero-based index of the target column. 195 * return the value of the requested column as a long. 196 */ 197 virtual int GetLong(int columnIndex, int64_t &value) = 0; 198 199 /** 200 * Returns the value of the requested column as a double. 201 * 202 * param columnIndex the zero-based index of the target column. 203 * return the value of the requested column as a double. 204 */ 205 virtual int GetDouble(int columnIndex, double &value) = 0; 206 207 /** 208 * Whether the value of the requested column is null. 209 * 210 * param columnIndex the zero-based index of the target column. 211 * return whether the column value is null. 212 */ 213 virtual int IsColumnNull(int columnIndex, bool &isNull) = 0; 214 215 /** 216 * Return true if the result set is closed. 217 * 218 * return true if the result set is closed. 219 */ 220 virtual bool IsClosed() const = 0; 221 222 /** 223 * Closes the result set, releasing all of its resources and making it 224 * completely invalid. 225 */ 226 virtual int Close() = 0; 227 }; 228 } // namespace DataShare 229 } // namespace OHOS 230 #endif 231