Skip to content

Commit feafa8f

Browse files
authored
Merge pull request #537 from aregtech/feature/535-extend-sql-database-object-to-fetch-data
Updates of SQLite wrappers.
2 parents 9a49ca4 + d2abc32 commit feafa8f

File tree

12 files changed

+1102
-6
lines changed

12 files changed

+1102
-6
lines changed

framework/areg/persist/IEDatabaseEngine.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class AREG_API IEDatabaseEngine
8787
**/
8888
virtual bool commit(bool doCommit) = 0;
8989

90+
/**
91+
* \brief Rolls back the database changes and returns true if succeeded.
92+
**/
93+
virtual bool rollback(void) = 0;
94+
9095
//////////////////////////////////////////////////////////////////////////
9196
// Forbidden calls.
9297
//////////////////////////////////////////////////////////////////////////

framework/aregextend.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<ClCompile Include="aregextend\console\private\SystemServiceConsole.cpp" />
4848
<ClCompile Include="aregextend\db\private\LogSqliteDatabase.cpp" />
4949
<ClCompile Include="aregextend\db\private\SqliteDatabase.cpp" />
50+
<ClCompile Include="aregextend\db\private\SqliteRow.cpp" />
51+
<ClCompile Include="aregextend\db\private\SqliteStatement.cpp" />
5052
<ClCompile Include="aregextend\service\private\DataRateHelper.cpp" />
5153
<ClCompile Include="aregextend\service\private\NESystemService.cpp" />
5254
<ClCompile Include="aregextend\service\private\posix\ServiceApplicationBasePosix.cpp" />
@@ -70,6 +72,8 @@
7072
<ClInclude Include="aregextend\console\OptionParser.hpp" />
7173
<ClInclude Include="aregextend\db\SqliteDatabase.hpp" />
7274
<ClInclude Include="aregextend\db\LogSqliteDatabase.hpp" />
75+
<ClInclude Include="aregextend\db\SqliteRow.hpp" />
76+
<ClInclude Include="aregextend\db\SqliteStatement.hpp" />
7377
<ClInclude Include="aregextend\service\DataRateHelper.hpp" />
7478
<ClInclude Include="aregextend\service\NESystemService.hpp" />
7579
<ClInclude Include="aregextend\console\SystemServiceConsole.hpp" />

framework/aregextend.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
<ClCompile Include="aregextend\service\private\win32\ServiceApplicationBaseWin32.cpp">
7373
<Filter>Source Files</Filter>
7474
</ClCompile>
75+
<ClCompile Include="aregextend\db\private\SqliteStatement.cpp">
76+
<Filter>Source Files</Filter>
77+
</ClCompile>
78+
<ClCompile Include="aregextend\db\private\SqliteRow.cpp">
79+
<Filter>Source Files</Filter>
80+
</ClCompile>
7581
</ItemGroup>
7682
<ItemGroup>
7783
<Text Include="aregextend\CMakeLists.txt">
@@ -133,6 +139,12 @@
133139
<ClInclude Include="aregextend\resources\resource.h">
134140
<Filter>Header Files</Filter>
135141
</ClInclude>
142+
<ClInclude Include="aregextend\db\SqliteRow.hpp">
143+
<Filter>Header Files</Filter>
144+
</ClInclude>
145+
<ClInclude Include="aregextend\db\SqliteStatement.hpp">
146+
<Filter>Header Files</Filter>
147+
</ClInclude>
136148
</ItemGroup>
137149
<ItemGroup>
138150
<None Include="aregextend\Readme.md">

framework/aregextend/db/LogSqliteDatabase.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@
2121
#include "areg/logging/IELogDatabaseEngine.hpp"
2222
#include "areg/base/String.hpp"
2323

24+
#if 0
25+
#include <vector>
26+
27+
enum eLogItemType
28+
{
29+
ItemUnknown = 0 //!< Unknown log item type
30+
, ItemInstance //!< Log instance item
31+
, ItemThread //!< Log thread item
32+
, ItemScope //!< Log scope item
33+
, ItemPriority //!< Log priority item
34+
};
35+
36+
struct sLogItem
37+
{
38+
ITEM_ID itemId { 0 }; //<! The ID of the log item
39+
String itemName{ }; //!< The name of the log item
40+
};
41+
42+
struct sLogItemList
43+
{
44+
eLogItemType itemType{ ItemUnknown }; //!< The type of the log item
45+
std::vector<sLogItem> itemList{ }; //!< The list of log items
46+
};
47+
#endif
2448
//////////////////////////////////////////////////////////////////////////
2549
// LogSqliteDatabase class declaration
2650
//////////////////////////////////////////////////////////////////////////
@@ -199,6 +223,39 @@ class LogSqliteDatabase : public IELogDatabaseEngine
199223
**/
200224
virtual bool logScopeDeactivate(const ITEM_ID & cookie, unsigned int scopeId, const DateTime & timestamp) override;
201225

226+
/**
227+
* \brief Rolls back the database changes and returns true if succeeded.
228+
**/
229+
virtual bool rollback(void) override;
230+
231+
//////////////////////////////////////////////////////////////////////////
232+
// Attributes and operations
233+
//////////////////////////////////////////////////////////////////////////
234+
#if 0
235+
std::vector<String> getLogInstanceNames(void) const;
236+
237+
std::vector<ITEM_ID> getLogInstances(void) const;
238+
239+
std::vector<String> getLogThreadNames(void) const;
240+
241+
std::vector<ITEM_ID> getLogThreads(void) const;
242+
243+
std::vector<String> getLogScopeNames(void) const;
244+
245+
std::vector<ITEM_ID> getLogScopes(void) const;
246+
247+
std::vector<String> getPriorityNames(void) const;
248+
249+
std::vector<NELogging::sScopeInfo> getLogInstScopes(ITEM_ID instId) const;
250+
251+
std::vector<SharedBuffer> getLodMessages(void) const;
252+
253+
std::vector<SharedBuffer> getLodInstMessages(ITEM_ID instId) const;
254+
255+
std::vector<SharedBuffer> getLodScopeMessages(ITEM_ID instId, uint32_t scopeId) const;
256+
257+
#endif
258+
202259
//////////////////////////////////////////////////////////////////////////
203260
// Hidden methods
204261
//////////////////////////////////////////////////////////////////////////

framework/aregextend/db/SqliteDatabase.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
**/
3030
class SqliteDatabase : public IEDatabaseEngine
3131
{
32+
friend class SqliteStatement;
3233
//////////////////////////////////////////////////////////////////////////
3334
// Constructors / Destructor
3435
//////////////////////////////////////////////////////////////////////////
@@ -111,6 +112,11 @@ class SqliteDatabase : public IEDatabaseEngine
111112
**/
112113
virtual bool commit(bool doCommit) override;
113114

115+
/**
116+
* \brief Rolls back the database changes and returns true if succeeded.
117+
**/
118+
virtual bool rollback(void) override;
119+
114120
//////////////////////////////////////////////////////////////////////////
115121
// Hidden methods
116122
//////////////////////////////////////////////////////////////////////////
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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

Comments
 (0)