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 #include "result_set_utils.h"
17 
18 namespace OHOS::RdbDataAbilityAdapter {
ResultSetUtils(std::shared_ptr<DSResultSet> dbResultSet)19 ResultSetUtils::ResultSetUtils(std::shared_ptr<DSResultSet> dbResultSet) : resultSet_(std::move(dbResultSet))
20 {
21 }
22 
GetColumnCount(int & count)23 int ResultSetUtils::GetColumnCount(int &count)
24 {
25     return resultSet_->GetColumnCount(count);
26 }
27 
GetColumnType(int columnIndex,NativeRdb::ColumnType & columnType)28 int ResultSetUtils::GetColumnType(int columnIndex, NativeRdb::ColumnType &columnType)
29 {
30     DataShare::DataType dataType;
31     auto ret = resultSet_->GetDataType(columnIndex, dataType);
32     columnType = NativeRdb::ColumnType(int32_t(dataType));
33     return ret;
34 }
35 
GetRowCount(int & count)36 int ResultSetUtils::GetRowCount(int &count)
37 {
38     return resultSet_->GetRowCount(count);
39 }
40 
GetRowIndex(int & position) const41 int ResultSetUtils::GetRowIndex(int &position) const
42 {
43     return resultSet_->GetRowIndex(position);
44 }
45 
GoTo(int offset)46 int ResultSetUtils::GoTo(int offset)
47 {
48     return resultSet_->GoTo(offset);
49 }
50 
GoToRow(int position)51 int ResultSetUtils::GoToRow(int position)
52 {
53     return resultSet_->GoToRow(position);
54 }
55 
GoToFirstRow()56 int ResultSetUtils::GoToFirstRow()
57 {
58     return resultSet_->GoToFirstRow();
59 }
60 
GoToLastRow()61 int ResultSetUtils::GoToLastRow()
62 {
63     return resultSet_->GoToLastRow();
64 }
65 
GoToNextRow()66 int ResultSetUtils::GoToNextRow()
67 {
68     return resultSet_->GoToNextRow();
69 }
70 
GoToPreviousRow()71 int ResultSetUtils::GoToPreviousRow()
72 {
73     return resultSet_->GoToPreviousRow();
74 }
75 
IsEnded(bool & result)76 int ResultSetUtils::IsEnded(bool &result)
77 {
78     return resultSet_->IsEnded(result);
79 }
80 
IsStarted(bool & result) const81 int ResultSetUtils::IsStarted(bool &result) const
82 {
83     return resultSet_->IsStarted(result);
84 }
85 
IsAtFirstRow(bool & result) const86 int ResultSetUtils::IsAtFirstRow(bool &result) const
87 {
88     return resultSet_->IsAtFirstRow(result);
89 }
90 
IsAtLastRow(bool & result)91 int ResultSetUtils::IsAtLastRow(bool &result)
92 {
93     return resultSet_->IsAtLastRow(result);
94 }
95 
Close()96 int ResultSetUtils::Close()
97 {
98     auto status = resultSet_->Close();
99     if (resultSet_->IsClosed()) {
100         AbsResultSet::Close();
101     }
102     return status;
103 }
104 
GetColumnNames()105 std::pair<int, std::vector<std::string>> ResultSetUtils::GetColumnNames()
106 {
107     std::vector<std::string> names;
108     auto errCode = resultSet_->GetAllColumnNames(names);
109     return {errCode, std::move(names)};
110 }
111 }
112