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 #include "kv_store_result_set_impl.h"
17
18 #include "db_errno.h"
19
20 namespace DistributedDB {
21 const int KvStoreResultSetImpl::INIT_POSITION = -1;
22
KvStoreResultSetImpl(IKvDBResultSet * resultSet)23 KvStoreResultSetImpl::KvStoreResultSetImpl(IKvDBResultSet *resultSet)
24 : resultSet_(resultSet)
25 {
26 }
27
GetCount() const28 int KvStoreResultSetImpl::GetCount() const
29 {
30 if (resultSet_ == nullptr) {
31 return 0;
32 }
33 return resultSet_->GetCount();
34 }
35
GetPosition() const36 int KvStoreResultSetImpl::GetPosition() const
37 {
38 if (resultSet_ == nullptr) {
39 return INIT_POSITION;
40 }
41 return resultSet_->GetPosition();
42 }
43
Move(int offset)44 bool KvStoreResultSetImpl::Move(int offset)
45 {
46 if (resultSet_ == nullptr) {
47 return false;
48 }
49 if (resultSet_->Move(offset) == E_OK) {
50 return true;
51 }
52 return false;
53 }
54
MoveToPosition(int position)55 bool KvStoreResultSetImpl::MoveToPosition(int position)
56 {
57 if (resultSet_ == nullptr) {
58 return false;
59 }
60 if (resultSet_->MoveTo(position) == E_OK) {
61 return true;
62 }
63 return false;
64 }
65
MoveToFirst()66 bool KvStoreResultSetImpl::MoveToFirst()
67 {
68 if (resultSet_ == nullptr) {
69 return false;
70 }
71 if (resultSet_->MoveToFirst() == E_OK) {
72 return true;
73 }
74 return false;
75 }
76
MoveToLast()77 bool KvStoreResultSetImpl::MoveToLast()
78 {
79 if (resultSet_ == nullptr) {
80 return false;
81 }
82 if (resultSet_->MoveToLast() == E_OK) {
83 return true;
84 }
85 return false;
86 }
87
MoveToNext()88 bool KvStoreResultSetImpl::MoveToNext()
89 {
90 // move 1 step forward in this result set
91 return Move(1);
92 }
93
MoveToPrevious()94 bool KvStoreResultSetImpl::MoveToPrevious()
95 {
96 // move 1 step backward in this result set
97 return Move(-1);
98 }
99
IsFirst() const100 bool KvStoreResultSetImpl::IsFirst() const
101 {
102 if (resultSet_ == nullptr) {
103 return false;
104 }
105 return resultSet_->IsFirst();
106 }
107
IsLast() const108 bool KvStoreResultSetImpl::IsLast() const
109 {
110 if (resultSet_ == nullptr) {
111 return false;
112 }
113 return resultSet_->IsLast();
114 }
115
IsBeforeFirst() const116 bool KvStoreResultSetImpl::IsBeforeFirst() const
117 {
118 if (resultSet_ == nullptr) {
119 return false;
120 }
121 return resultSet_->IsBeforeFirst();
122 }
123
IsAfterLast() const124 bool KvStoreResultSetImpl::IsAfterLast() const
125 {
126 if (resultSet_ == nullptr) {
127 return false;
128 }
129 return resultSet_->IsAfterLast();
130 }
131
GetEntry(Entry & entry) const132 DBStatus KvStoreResultSetImpl::GetEntry(Entry &entry) const
133 {
134 if (resultSet_ == nullptr) {
135 return DB_ERROR;
136 }
137
138 if (resultSet_->GetEntry(entry) == E_OK) {
139 return OK;
140 }
141 return NOT_FOUND;
142 }
143
GetResultSet(IKvDBResultSet * & resultSet) const144 void KvStoreResultSetImpl::GetResultSet(IKvDBResultSet *&resultSet) const
145 {
146 resultSet = resultSet_;
147 }
148
IsClosed() const149 bool KvStoreResultSetImpl::IsClosed() const
150 {
151 return false;
152 }
153
Close()154 void KvStoreResultSetImpl::Close()
155 {
156 }
157
GetColumnNames(std::vector<std::string> & columnNames) const158 void KvStoreResultSetImpl::GetColumnNames(std::vector<std::string> &columnNames) const
159 {
160 (void)columnNames;
161 }
162
GetColumnType(int columnIndex,ColumnType & columnType) const163 DBStatus KvStoreResultSetImpl::GetColumnType(int columnIndex, ColumnType &columnType) const
164 {
165 (void)columnIndex;
166 (void)columnType;
167 return NOT_SUPPORT;
168 }
169
GetColumnIndex(const std::string & columnName,int & columnIndex) const170 DBStatus KvStoreResultSetImpl::GetColumnIndex(const std::string &columnName, int &columnIndex) const
171 {
172 (void)columnIndex;
173 (void)columnName;
174 return NOT_SUPPORT;
175 }
176
GetColumnName(int columnIndex,std::string & columnName) const177 DBStatus KvStoreResultSetImpl::GetColumnName(int columnIndex, std::string &columnName) const
178 {
179 (void)columnIndex;
180 (void)columnName;
181 return NOT_SUPPORT;
182 }
183
Get(int columnIndex,std::vector<uint8_t> & value) const184 DBStatus KvStoreResultSetImpl::Get(int columnIndex, std::vector<uint8_t> &value) const
185 {
186 (void)columnIndex;
187 (void)value;
188 return NOT_SUPPORT;
189 }
190
Get(int columnIndex,std::string & value) const191 DBStatus KvStoreResultSetImpl::Get(int columnIndex, std::string &value) const
192 {
193 (void)columnIndex;
194 (void)value;
195 return NOT_SUPPORT;
196 }
197
Get(int columnIndex,int64_t & value) const198 DBStatus KvStoreResultSetImpl::Get(int columnIndex, int64_t &value) const
199 {
200 (void)columnIndex;
201 (void)value;
202 return NOT_SUPPORT;
203 }
204
Get(int columnIndex,double & value) const205 DBStatus KvStoreResultSetImpl::Get(int columnIndex, double &value) const
206 {
207 (void)columnIndex;
208 (void)value;
209 return NOT_SUPPORT;
210 }
211
IsColumnNull(int columnIndex,bool & isNull) const212 DBStatus KvStoreResultSetImpl::IsColumnNull(int columnIndex, bool &isNull) const
213 {
214 (void)columnIndex;
215 (void)isNull;
216 return NOT_SUPPORT;
217 }
218
GetRow(std::map<std::string,VariantData> & data) const219 DBStatus KvStoreResultSetImpl::GetRow(std::map<std::string, VariantData> &data) const
220 {
221 (void)data;
222 return NOT_SUPPORT;
223 }
224 } // namespace DistributedDB
225