1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-22 20:57:12 +01:00

Cleanup SQLite code.

This commit is contained in:
Sandu Liviu Catalin 2020-03-22 03:03:05 +02:00
parent 8ea13de743
commit 05990afedf
3 changed files with 39 additions and 40 deletions

View File

@ -21,6 +21,10 @@ SQMODE_DECL_TYPENAME(SQLiteColumnTypename, _SC("SQLiteColumn"))
SQMODE_DECL_TYPENAME(SQLiteStatementTypename, _SC("SQLiteStatement")) SQMODE_DECL_TYPENAME(SQLiteStatementTypename, _SC("SQLiteStatement"))
SQMODE_DECL_TYPENAME(SQLiteTransactionTypename, _SC("SQLiteTransaction")) SQMODE_DECL_TYPENAME(SQLiteTransactionTypename, _SC("SQLiteTransaction"))
// ------------------------------------------------------------------------------------------------
#pragma clang diagnostic push
#pragma ide diagnostic ignored "hicpp-signed-bitwise"
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Helper class that represents an integral enumeration value. Used to reduce compilation times. * Helper class that represents an integral enumeration value. Used to reduce compilation times.
*/ */
@ -367,6 +371,7 @@ static const SEnumElement g_MainEnum[] = {
{_SC("WARNING"), SQLITE_WARNING}, {_SC("WARNING"), SQLITE_WARNING},
{_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX} {_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX}
}; };
#pragma clang diagnostic pop
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
static inline bool IsDigitsOnly(CSStr str) static inline bool IsDigitsOnly(CSStr str)
@ -2864,9 +2869,9 @@ void Register_SQLite(HSQUIRRELVM vm)
{ {
Enumeration e(vm); Enumeration e(vm);
for (Uint32 n = 0; n < (sizeof(g_MainEnum) / sizeof(EnumElement)); ++n) for (auto n : g_MainEnum)
{ {
e.Const(g_MainEnum[n].Name, g_MainEnum[n].Value); e.Const(n.Name, n.Value);
} }
ConstTable(vm).Enum(_SC("SQLiteOpt"), e); ConstTable(vm).Enum(_SC("SQLiteOpt"), e);

View File

@ -12,6 +12,7 @@
#include "Library/Chrono/Timestamp.hpp" #include "Library/Chrono/Timestamp.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include <utility>
#include <vector> #include <vector>
#include <map> #include <map>
@ -86,11 +87,6 @@ Object GetConnectionObj(const ConnRef & conn);
*/ */
Object GetStatementObj(const StmtRef & stmt); Object GetStatementObj(const StmtRef & stmt);
/* ------------------------------------------------------------------------------------------------
* Generate a formatted query.
*/
CSStr QFmtStr(CSStr str, ...);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Tests if a certain query string is empty. * Tests if a certain query string is empty.
*/ */
@ -153,11 +149,11 @@ public:
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef Type* Pointer; // Pointer to the managed type. typedef Type* Pointer; // Pointer to the managed type.
typedef const Type* ConstPtr; // Constant pointer to the managed type. typedef const Type* SQ_UNUSED_TYPEDEF(ConstPtr); // Constant pointer to the managed type.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef Type& Reference; // Reference to the managed type. typedef Type& Reference; // Reference to the managed type.
typedef const Type& ConstRef; // Constant reference to the managed type. typedef const Type& SQ_UNUSED_TYPEDEF(ConstRef); // Constant reference to the managed type.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef std::vector< String > QueryList; // Container used to queue queries. typedef std::vector< String > QueryList; // Container used to queue queries.
@ -268,11 +264,11 @@ public:
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef Type* Pointer; // Pointer to the managed type. typedef Type* Pointer; // Pointer to the managed type.
typedef const Type* ConstPtr; // Constant pointer to the managed type. typedef const Type* SQ_UNUSED_TYPEDEF(ConstPtr); // Constant pointer to the managed type.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef Type& Reference; // Reference to the managed type. typedef Type& Reference; // Reference to the managed type.
typedef const Type& ConstRef; // Constant reference to the managed type. typedef const Type& SQ_UNUSED_TYPEDEF(ConstRef); // Constant reference to the managed type.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
typedef std::map< String, int > Indexes; // Container used to identify column indexes. typedef std::map< String, int > Indexes; // Container used to identify column indexes.
@ -303,7 +299,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
StmtHnd(ConnRef conn); explicit StmtHnd(ConnRef conn);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled) * Copy constructor. (disabled)
@ -947,8 +943,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* No parameter constructor. * No parameter constructor.
*/ */
Parameter(const StmtRef & stmt) explicit Parameter(StmtRef stmt)
: m_Index(0), m_Handle(stmt) : m_Index(0), m_Handle(std::move(stmt))
{ {
/* ... */ /* ... */
} }
@ -956,8 +952,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Index constructor. * Index constructor.
*/ */
Parameter(const StmtRef & stmt, Int32 idx) Parameter(StmtRef stmt, Int32 idx)
: m_Index(idx), m_Handle(stmt) : m_Index(idx), m_Handle(std::move(stmt))
{ {
SQMOD_VALIDATE_PARAM(*this, m_Index); SQMOD_VALIDATE_PARAM(*this, m_Index);
} }
@ -974,8 +970,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Dynamic constructor. * Dynamic constructor.
*/ */
Parameter(const StmtRef & stmt, const Object & param) Parameter(StmtRef stmt, const Object & param)
: m_Index(0), m_Handle(stmt) : m_Index(0), m_Handle(std::move(stmt))
{ {
if (!m_Handle) if (!m_Handle)
{ {
@ -1024,7 +1020,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations. * Implicit conversion to boolean for use in boolean operations.
*/ */
operator bool () const operator bool () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
{ {
return m_Index >= 0; return m_Index >= 0;
} }
@ -1355,8 +1351,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* No column constructor. * No column constructor.
*/ */
Column(const StmtRef & stmt) explicit Column(StmtRef stmt)
: m_Index(-1), m_Handle(stmt) : m_Index(-1), m_Handle(std::move(stmt))
{ {
/* ... */ /* ... */
} }
@ -1364,8 +1360,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Index constructor. * Index constructor.
*/ */
Column(const StmtRef & stmt, Int32 idx) Column(StmtRef stmt, Int32 idx)
: m_Index(idx), m_Handle(stmt) : m_Index(idx), m_Handle(std::move(stmt))
{ {
SQMOD_VALIDATE_COLUMN(*this, m_Index); SQMOD_VALIDATE_COLUMN(*this, m_Index);
} }
@ -1382,8 +1378,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Dynamic constructor. * Dynamic constructor.
*/ */
Column(const StmtRef & stmt, const Object & column) Column(StmtRef stmt, const Object & column)
: m_Index(-1), m_Handle(stmt) : m_Index(-1), m_Handle(std::move(stmt))
{ {
if (!m_Handle) if (!m_Handle)
{ {
@ -1432,7 +1428,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean for use in boolean operations. * Implicit conversion to boolean for use in boolean operations.
*/ */
operator bool () const operator bool () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
{ {
return m_Index >= 0; return m_Index >= 0;
} }
@ -1678,8 +1674,8 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Direct handle constructor. * Direct handle constructor.
*/ */
Statement(const StmtRef & s) explicit Statement(StmtRef s)
: m_Handle(s) : m_Handle(std::move(s))
{ {
/* ... */ /* ... */
} }
@ -1723,7 +1719,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw connection handle. * Implicit conversion to the raw connection handle.
*/ */
operator sqlite3_stmt * () operator sqlite3_stmt * () // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
{ {
return m_Handle ? m_Handle->mPtr : nullptr; return m_Handle ? m_Handle->mPtr : nullptr;
} }
@ -1731,7 +1727,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw connection handle. * Implicit conversion to the raw connection handle.
*/ */
operator sqlite3_stmt * () const operator sqlite3_stmt * () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
{ {
return m_Handle ? m_Handle->mPtr : nullptr; return m_Handle ? m_Handle->mPtr : nullptr;
} }
@ -2441,12 +2437,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Construct by taking the handle from a connection. * Construct by taking the handle from a connection.
*/ */
Transaction(const Connection & db); explicit Transaction(const Connection & db);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Construct using the direct connection handle. * Construct using the direct connection handle.
*/ */
Transaction(ConnRef db); explicit Transaction(ConnRef db);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled) * Copy constructor. (disabled)
@ -2481,14 +2477,6 @@ public:
return m_Handle ? m_Handle->mName : NullString(); return m_Handle ? m_Handle->mName : NullString();
} }
/* --------------------------------------------------------------------------------------------
* Retrieve the associated statement handle.
*/
const ConnRef & GetHandle() const
{
return m_Handle;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* See whether the managed handle is valid. * See whether the managed handle is valid.
*/ */

View File

@ -409,6 +409,12 @@ SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
# define SQ_UNUSED_ARG(x) x # define SQ_UNUSED_ARG(x) x
#endif #endif
#ifdef __GNUC__
# define SQ_UNUSED_TYPEDEF(x) x __attribute__((__unused__))
#else
# define SQ_UNUSED_TYPEDEF(x) x
#endif
#ifdef __cplusplus #ifdef __cplusplus
} /*extern "C"*/ } /*extern "C"*/
#endif #endif