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_RESULT_SET_H 17 #define NATIVE_RDB_RESULT_SET_H 18 19 #include <string> 20 #include <vector> 21 #include <map> 22 #include "remote_result_set.h" 23 #include "value_object.h" 24 #include "rdb_errno.h" 25 namespace OHOS { 26 namespace NativeRdb { 27 struct API_EXPORT RowEntity { 28 public: 29 API_EXPORT void Put(const std::string &name, int32_t index, ValueObject &&value); 30 API_EXPORT ValueObject Get(const std::string &name) const; 31 API_EXPORT ValueObject Get(int index) const; 32 API_EXPORT const std::map<std::string, ValueObject> &Get() const; 33 API_EXPORT std::map<std::string, ValueObject> Steal(); 34 API_EXPORT void Clear(int32_t size); 35 36 private: 37 std::map<std::string, ValueObject> values_; 38 std::vector<decltype(values_)::iterator> indexs_; 39 }; 40 41 /** 42 * The ResultSet class of RDB. 43 * Provides methods for accessing a database result set generated by querying the database. 44 */ 45 class API_EXPORT ResultSet : public RemoteResultSet { 46 public: 47 /** 48 * @brief Destructor. 49 */ ~ResultSet()50 virtual ~ResultSet() {} 51 52 virtual int GetAsset(int32_t col, ValueObject::Asset &value) = 0; 53 virtual int GetAssets(int32_t col, ValueObject::Assets &value) = 0; GetFloat32Array(int32_t index,ValueObject::FloatVector & vecs)54 virtual int GetFloat32Array(int32_t index, ValueObject::FloatVector &vecs) 55 { 56 return E_NOT_SUPPORT; 57 } 58 virtual int Get(int32_t col, ValueObject &value) = 0; 59 /** 60 * @brief Gets the entire row of data for the current row from the result set. 61 */ 62 virtual int GetRow(RowEntity &rowEntity) = 0; 63 64 /** 65 * @brief Get the size of blob or text. 66 * 67 * @param columnIndex Indicates the zero-based index of the target column. 68 */ 69 API_EXPORT virtual int GetSize(int columnIndex, size_t &size) = 0; 70 }; 71 72 } // namespace NativeRdb 73 } // namespace OHOS 74 #endif 75