|
| 1 | +#ifndef AREG_AREGEXTEND_DB_SQLITEROW_HPP |
| 2 | +#define AREG_AREGEXTEND_DB_SQLITEROW_HPP |
| 3 | +/************************************************************************ |
| 4 | + * This file is part of the AREG SDK core engine. |
| 5 | + * AREG SDK is dual-licensed under Free open source (Apache version 2.0 |
| 6 | + * License) and Commercial (with various pricing models) licenses, depending |
| 7 | + * on the nature of the project (commercial, research, academic or free). |
| 8 | + * You should have received a copy of the AREG SDK license description in LICENSE.txt. |
| 9 | + * If not, please contact to info[at]aregtech.com |
| 10 | + * |
| 11 | + * \copyright (c) 2017-2023 Aregtech UG. All rights reserved. |
| 12 | + * \file aregextend/db/SqliteRow.hpp |
| 13 | + * \author Artak Avetyan |
| 14 | + * \ingroup AREG platform, extended library, SQLite row object to get results. |
| 15 | + ************************************************************************/ |
| 16 | + |
| 17 | +/************************************************************************ |
| 18 | + * Include files. |
| 19 | + ************************************************************************/ |
| 20 | +#include "areg/base/GEGlobal.h" |
| 21 | +#include "areg/base/String.hpp" |
| 22 | + |
| 23 | +/************************************************************************ |
| 24 | + * Dependencies |
| 25 | + ************************************************************************/ |
| 26 | +class SqliteStatement; |
| 27 | + |
| 28 | +////////////////////////////////////////////////////////////////////////// |
| 29 | +// SqliteRow class declaration |
| 30 | +////////////////////////////////////////////////////////////////////////// |
| 31 | +/** |
| 32 | + * \brief Represents a single row of results from a SQLite query. |
| 33 | + * Provides access to column values and metadata for the current row. |
| 34 | + **/ |
| 35 | +class SqliteRow |
| 36 | +{ |
| 37 | +////////////////////////////////////////////////////////////////////////// |
| 38 | +// Constructors / operators. |
| 39 | +////////////////////////////////////////////////////////////////////////// |
| 40 | +public: |
| 41 | + /** |
| 42 | + * \brief Default constructor. Initializes an invalid row. |
| 43 | + */ |
| 44 | + SqliteRow(void); |
| 45 | + |
| 46 | + /** |
| 47 | + * \brief Constructs a SqliteRow from a SqliteStatement. |
| 48 | + * \param statement Reference to the SqliteStatement object. |
| 49 | + */ |
| 50 | + SqliteRow(SqliteStatement& statement); |
| 51 | + |
| 52 | + /** |
| 53 | + * \brief Constructs a SqliteRow from a raw statement pointer. |
| 54 | + * \param statement Pointer to the underlying SQLite statement. |
| 55 | + */ |
| 56 | + SqliteRow(void* statement); |
| 57 | + |
| 58 | + /** |
| 59 | + * \brief Copy constructor. |
| 60 | + * \param src The source SqliteRow to copy from. |
| 61 | + */ |
| 62 | + SqliteRow(const SqliteRow& src); |
| 63 | + |
| 64 | + /** |
| 65 | + * \brief Move constructor. |
| 66 | + * \param src The source SqliteRow to move from. |
| 67 | + */ |
| 68 | + SqliteRow(SqliteRow&& src); |
| 69 | + |
| 70 | + /** |
| 71 | + * \brief Destructor. Defaulted. |
| 72 | + */ |
| 73 | + ~SqliteRow(void) = default; |
| 74 | + |
| 75 | + /** |
| 76 | + * \brief Copy assignment operator. |
| 77 | + * \param src The source SqliteRow to copy from. |
| 78 | + * \return Reference to this object. |
| 79 | + */ |
| 80 | + SqliteRow& operator = (const SqliteRow& src); |
| 81 | + |
| 82 | + /** |
| 83 | + * \brief Move assignment operator. |
| 84 | + * \param src The source SqliteRow to move from. |
| 85 | + * \return Reference to this object. |
| 86 | + */ |
| 87 | + SqliteRow& operator = (SqliteRow&& src); |
| 88 | + |
| 89 | +////////////////////////////////////////////////////////////////////////// |
| 90 | +// Attributes and operations |
| 91 | +////////////////////////////////////////////////////////////////////////// |
| 92 | +public: |
| 93 | + /** |
| 94 | + * \brief Checks if the row is valid (i.e., associated with a statement). |
| 95 | + * \return True if valid, false otherwise. |
| 96 | + */ |
| 97 | + inline bool isValid(void) const; |
| 98 | + |
| 99 | + /** |
| 100 | + * \brief Retrieves the integer value of the specified column. |
| 101 | + * \param column The 0-based column index. |
| 102 | + * \return The integer value of the column. |
| 103 | + */ |
| 104 | + int getInt(int column) const; |
| 105 | + |
| 106 | + /** |
| 107 | + * \brief Retrieves the 64-bit integer value of the specified column. |
| 108 | + * \param column The 0-based column index. |
| 109 | + * \return The 64-bit integer value of the column. |
| 110 | + */ |
| 111 | + int64_t getInt64(int column) const; |
| 112 | + |
| 113 | + /** |
| 114 | + * \brief Retrieves the double value of the specified column. |
| 115 | + * \param column The 0-based column index. |
| 116 | + * \return The double value of the column. |
| 117 | + */ |
| 118 | + double getDouble(int column) const; |
| 119 | + |
| 120 | + /** |
| 121 | + * \brief Retrieves the text value of the specified column. |
| 122 | + * \param column The 0-based column index. |
| 123 | + * \return The string value of the column. |
| 124 | + */ |
| 125 | + String getText(int column) const; |
| 126 | + |
| 127 | + /** |
| 128 | + * \brief Checks if the specified column is NULL. |
| 129 | + * \param column The 0-based column index. |
| 130 | + * \return True if the column is NULL, false otherwise. |
| 131 | + */ |
| 132 | + bool isNull(int column) const; |
| 133 | + |
| 134 | + /** |
| 135 | + * \brief Checks if the specified column index is valid. |
| 136 | + * \param column The 0-based column index. |
| 137 | + * \return True if the column index is valid, false otherwise. |
| 138 | + */ |
| 139 | + bool isColumnValid(int column) const; |
| 140 | + |
| 141 | + /** |
| 142 | + * \brief Checks if the specified column contains a string value. |
| 143 | + * \param column The 0-based column index. |
| 144 | + * \return True if the column is a string, false otherwise. |
| 145 | + */ |
| 146 | + bool isString(int column) const; |
| 147 | + |
| 148 | + /** |
| 149 | + * \brief Checks if the specified column contains a 32-bit integer value. |
| 150 | + * \param column The 0-based column index. |
| 151 | + * \return True if the column is a 32-bit integer, false otherwise. |
| 152 | + */ |
| 153 | + bool isInteger(int column) const; |
| 154 | + |
| 155 | + /** |
| 156 | + * \brief Checks if the specified column contains a 64-bit integer value. |
| 157 | + * \param column The 0-based column index. |
| 158 | + * \return True if the column is a 64-bit integer, false otherwise. |
| 159 | + */ |
| 160 | + bool isInteger64(int column) const; |
| 161 | + |
| 162 | + /** |
| 163 | + * \brief Checks if the specified column contains a double value. |
| 164 | + * \param column The 0-based column index. |
| 165 | + * \return True if the column is a double, false otherwise. |
| 166 | + */ |
| 167 | + bool isDouble(int column) const; |
| 168 | + |
| 169 | + /** |
| 170 | + * \brief Returns the number of columns in the row. |
| 171 | + * \return The number of columns. |
| 172 | + */ |
| 173 | + int getColumnCount(void) const; |
| 174 | + |
| 175 | + /** |
| 176 | + * \brief Returns the name of the specified column. |
| 177 | + * \param column The 0-based column index. |
| 178 | + * \return The name of the column. |
| 179 | + */ |
| 180 | + String getColumnName(int column) const; |
| 181 | + |
| 182 | + /** |
| 183 | + * \brief Returns the index of the column with the specified name. |
| 184 | + * \param columnName The name of the column. |
| 185 | + * \return The 0-based index of the column, or -1 if not found. |
| 186 | + */ |
| 187 | + int getColumnIndex(const String& columnName) const; |
| 188 | + |
| 189 | +////////////////////////////////////////////////////////////////////////// |
| 190 | +// Member variables |
| 191 | +////////////////////////////////////////////////////////////////////////// |
| 192 | +protected: |
| 193 | + /** |
| 194 | + * \brief Pointer to the underlying SQLite statement. |
| 195 | + */ |
| 196 | + void* mStatement; |
| 197 | +}; |
| 198 | + |
| 199 | +inline bool SqliteRow::isValid(void) const |
| 200 | +{ |
| 201 | + return (mStatement != nullptr); |
| 202 | +} |
| 203 | + |
| 204 | +#endif // AREG_AREGEXTEND_DB_SQLITEROW_HPP |
0 commit comments