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 #ifndef DATASHARE_RESULT_SET_BRIDGE_H 17 #define DATASHARE_RESULT_SET_BRIDGE_H 18 19 #include <memory> 20 #include <string> 21 namespace OHOS { 22 namespace DataShare { 23 // build the bridge between the database's ResultSet and DataShare's ResultSet 24 class ResultSetBridge { 25 public: 26 class Writer { 27 public: 28 /** 29 * Allocate a row unit and its directory. 30 */ 31 virtual int AllocRow() = 0; 32 33 /** 34 * Write Null data to the shared block. 35 */ 36 virtual int Write(uint32_t column) = 0; 37 38 /** 39 * Write long data to the shared block. 40 */ 41 virtual int Write(uint32_t column, int64_t value) = 0; 42 43 /** 44 * Write Double data to the shared block. 45 */ 46 virtual int Write(uint32_t column, double value) = 0; 47 48 /** 49 * Write blob data to the shared block. 50 */ 51 virtual int Write(uint32_t column, const uint8_t *value, size_t size) = 0; 52 53 /** 54 * Write string data to the shared block. 55 */ 56 virtual int Write(uint32_t column, const char *value, size_t size) = 0; 57 }; 58 ~ResultSetBridge()59 virtual ~ResultSetBridge() {} 60 61 /** 62 * Return a string array holding the names of all of the columns in the 63 * result set. 64 * 65 * return the names of the columns contains in this query result. 66 */ 67 virtual int GetAllColumnNames(std::vector<std::string> &columnNames) = 0; 68 69 /** 70 * Return the numbers of rows in the result set. 71 */ 72 virtual int GetRowCount(int32_t &count) = 0; 73 74 /** 75 * Called when the position of the result set changes 76 */ 77 virtual int OnGo(int32_t startRowIndex, int32_t targetRowIndex, Writer &writer) = 0; 78 }; 79 } // namespace DataShare 80 } // namespace OHOS 81 #endif 82