1 /*
2  * Copyright (C) 2024 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 #include "opkey_version_result_set_bridge.h"
16 
17 #include "data_storage_log_wrapper.h"
18 #include "rdb_errno.h"
19 
20 namespace OHOS {
21 namespace Telephony {
OpkeyVersionResultSetBridge(const std::string & info)22 OpkeyVersionResultSetBridge::OpkeyVersionResultSetBridge(const std::string &info) : opkeyInfo_(info) {}
23 
GetRowCount(int32_t & count)24 int OpkeyVersionResultSetBridge::GetRowCount(int32_t &count)
25 {
26     count = ROW_COUNT;
27     return NativeRdb::E_OK;
28 }
29 
GetAllColumnNames(std::vector<std::string> & columnsName)30 int OpkeyVersionResultSetBridge::GetAllColumnNames(std::vector<std::string> &columnsName)
31 {
32     columnsName = {"key", "value"};
33     return NativeRdb::E_OK;
34 }
35 
FillBlock(DataShare::ResultSetBridge::Writer & writer)36 bool OpkeyVersionResultSetBridge::FillBlock(DataShare::ResultSetBridge::Writer &writer)
37 {
38     int statusAlloc = writer.AllocRow();
39     if (statusAlloc != NativeRdb::E_OK) {
40         return false;
41     }
42     int keyStatus = writer.Write(KEY_COLUMN, INFO_KEY.c_str(), INFO_KEY.size() + 1);
43     if (keyStatus != NativeRdb::E_OK) {
44         return false;
45     }
46     int valueStatus = writer.Write(VALUE_COLUMN, opkeyInfo_.c_str(), opkeyInfo_.size() + 1);
47     if (valueStatus != NativeRdb::E_OK) {
48         return false;
49     }
50     return true;
51 }
52 
OnGo(int32_t start,int32_t target,DataShare::ResultSetBridge::Writer & writer)53 int OpkeyVersionResultSetBridge::OnGo(int32_t start, int32_t target, DataShare::ResultSetBridge::Writer &writer)
54 {
55     DATA_STORAGE_LOGD("start");
56     if ((start < 0) || (target < 0) || (start > target)) {
57         return INVALID_POSITION;
58     }
59     return FillBlock(writer);
60 }
61 
62 } // Telephony
63 } // OHOS