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