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