1 /* 2 * Copyright (c) 2023 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 RELATIONAL_CURSOR_IMPL_H 17 #define RELATIONAL_CURSOR_IMPL_H 18 19 #include <memory> 20 21 #include "oh_cursor.h" 22 #include "result_set.h" 23 #include <memory> 24 25 namespace OHOS { 26 namespace RdbNdk { 27 constexpr int RDB_CURSOR_CID = 1234563; // The class id used to uniquely identify the OH_Cursor class. 28 class RelationalCursor : public OH_Cursor { 29 public: 30 explicit RelationalCursor(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet); 31 virtual ~RelationalCursor() = default; 32 33 protected: 34 virtual int GetColumnCount(int *count); 35 virtual int GetColumnType(int32_t columnIndex, OH_ColumnType *columnType); 36 virtual int GetColumnIndex(const char *name, int *columnIndex); 37 virtual int GetColumnName(int32_t columnIndex, char *name, int length); 38 virtual int GetRowCount(int *count); 39 virtual int GoToNextRow(); 40 virtual int GetSize(int32_t columnIndex, size_t *size); 41 virtual int GetText(int32_t columnIndex, char *value, int length); 42 virtual int GetInt64(int32_t columnIndex, int64_t *value); 43 virtual int GetReal(int32_t columnIndex, double *value); 44 virtual int GetBlob(int32_t columnIndex, unsigned char *value, int length); 45 virtual int GetAsset(int32_t columnIndex, Data_Asset *value); 46 virtual int GetAssets(int32_t columnIndex, Data_Asset **value, uint32_t *length); 47 virtual int GetAssetsCount(int32_t columnIndex, uint32_t *count); 48 virtual int IsNull(int32_t columnIndex, bool *isNull); 49 virtual int Destroy(); 50 51 private: 52 static int GetColumnCount(OH_Cursor *cursor, int *count); 53 static int GetColumnType(OH_Cursor *cursor, int32_t columnIndex, OH_ColumnType *columnType); 54 static int GetColumnIndex(OH_Cursor *cursor, const char *name, int *columnIndex); 55 static int GetColumnName(OH_Cursor *cursor, int32_t columnIndex, char *name, int length); 56 static int GetRowCount(OH_Cursor *cursor, int *count); 57 static int GoToNextRow(OH_Cursor *cursor); 58 static int GetSize(OH_Cursor *cursor, int32_t columnIndex, size_t *size); 59 static int GetText(OH_Cursor *cursor, int32_t columnIndex, char *value, int length); 60 static int GetInt64(OH_Cursor *cursor, int32_t columnIndex, int64_t *value); 61 static int GetReal(OH_Cursor *cursor, int32_t columnIndex, double *value); 62 static int GetBlob(OH_Cursor *cursor, int32_t columnIndex, unsigned char *value, int length); 63 static int GetAsset(OH_Cursor *cursor, int32_t columnIndex, Data_Asset *value); 64 static int GetAssets(OH_Cursor *cursor, int32_t columnIndex, Data_Asset **value, uint32_t *length); 65 static int IsNull(OH_Cursor *cursor, int32_t columnIndex, bool *isNull); 66 static int GetAssetsCount(OH_Cursor *cursor, int32_t columnIndex, uint32_t *count); 67 static int Destroy(OH_Cursor *cursor); 68 static RelationalCursor *GetSelf(OH_Cursor *cursor); 69 std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet_; 70 }; 71 } // namespace RdbNdk 72 } // namespace OHOS 73 #endif // RELATIONAL_CURSOR_IMPL_H 74