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