mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Untested implementation of the SQLite database library.
This commit is contained in:
parent
4b5718a6ae
commit
92a75e70a0
@ -25,6 +25,7 @@
|
||||
<Add option="-static" />
|
||||
<Add library="common-d" />
|
||||
<Add library="squirrel-d" />
|
||||
<Add library="sqlite-d" />
|
||||
<Add library="Ws2_32" />
|
||||
<Add directory="../lib/mingw32" />
|
||||
</Linker>
|
||||
@ -49,6 +50,7 @@
|
||||
<Add option="-static" />
|
||||
<Add library="common" />
|
||||
<Add library="squirrel" />
|
||||
<Add library="sqlite" />
|
||||
<Add library="Ws2_32" />
|
||||
<Add directory="../lib/mingw32" />
|
||||
</Linker>
|
||||
@ -74,6 +76,7 @@
|
||||
<Add option="-static" />
|
||||
<Add library="common-d" />
|
||||
<Add library="squirrel-d" />
|
||||
<Add library="sqlite-d" />
|
||||
<Add library="Ws2_32" />
|
||||
<Add directory="../lib/mingw64" />
|
||||
</Linker>
|
||||
@ -100,6 +103,7 @@
|
||||
<Add option="-static" />
|
||||
<Add library="common" />
|
||||
<Add library="squirrel" />
|
||||
<Add library="sqlite" />
|
||||
<Add library="Ws2_32" />
|
||||
<Add directory="../lib/mingw64" />
|
||||
</Linker>
|
||||
@ -204,16 +208,12 @@
|
||||
<Unit filename="../source/Library/Math.hpp" />
|
||||
<Unit filename="../source/Library/Numeric.cpp" />
|
||||
<Unit filename="../source/Library/Numeric.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Common.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Common.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Connection.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Connection.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Result.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Result.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Shared.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Shared.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Statement.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Statement.hpp" />
|
||||
<Unit filename="../source/Library/SQLite/Transaction.cpp" />
|
||||
<Unit filename="../source/Library/SQLite/Transaction.hpp" />
|
||||
<Unit filename="../source/Library/Shared.cpp" />
|
||||
<Unit filename="../source/Library/Shared.hpp" />
|
||||
<Unit filename="../source/Library/String.cpp" />
|
||||
|
@ -1,115 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_COMMON_HPP_
|
||||
#define _LIBRARY_SQLITE_COMMON_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
class ConnectionHandle
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
ConnectionHandle(const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
ConnectionHandle(ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
ConnectionHandle & operator = (const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
ConnectionHandle & operator = (ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
class StatementHandle
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
StatementHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
StatementHandle(const StatementHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
StatementHandle(StatementHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~StatementHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
StatementHandle & operator = (const StatementHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
StatementHandle & operator = (StatementHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_COMMON_HPP_
|
@ -0,0 +1,831 @@
|
||||
#include "Library/SQLite/Connection.hpp"
|
||||
#include "Library/SQLite/Statement.hpp"
|
||||
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection()
|
||||
: m_Handle()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path)
|
||||
: Connection(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path, SQInt32 flags)
|
||||
: Connection(path, flags, NULL)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs)
|
||||
: m_Handle(path, flags, vfs)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection::Connection(const Handle & hnd)
|
||||
: m_Handle(hnd)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Connection::Cmp(const Connection & o) const
|
||||
{
|
||||
if (m_Handle == o.m_Handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Handle && (m_Handle->Ptr > o.m_Handle->Ptr))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::ToString() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Path.c_str();
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetGlobalTag() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Tag.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection tag> using an invalid reference");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
void Connection::SetGlobalTag(const SQChar * tag) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Tag.assign(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set connection tag> using an invalid reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SqObj & Connection::GetGlobalData() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection data> using an invalid reference");
|
||||
}
|
||||
|
||||
return NullData();
|
||||
}
|
||||
|
||||
void Connection::SetGlobalData(SqObj & data) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Data = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set connection data> using an invalid reference");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetLocalTag() const
|
||||
{
|
||||
return m_Tag.c_str();
|
||||
}
|
||||
|
||||
void Connection::SetLocalTag(const SQChar * tag)
|
||||
{
|
||||
m_Tag = tag;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SqObj & Connection::GetLocalData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
void Connection::SetLocalData(SqObj & data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetStatus() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Status;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection status> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetFlags() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection flags> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetPath() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Path.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection file path> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetVFS() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->VFS.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection vfs string> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetErrStr() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle.ErrStr();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection error string> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const SQChar * Connection::GetErrMsg() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle.ErrMsg();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get connection error message> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::Exec(const SQChar * str)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
if ((m_Handle->Status = sqlite3_exec(m_Handle, static_cast< const char * >(str), NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <execute database query> because: %s", m_Handle.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
return sqlite3_changes(m_Handle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <execute database query> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::Queue(const SQChar * str)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
m_Handle->Queue.emplace(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <queue database query> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::TableExists(const SQChar * name) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
// Create the statement which counts the tables with the specified name
|
||||
Statement stmt(*this, "SELECT count(*) FROM [sqlite_master] WHERE [type]='table' AND [name]=?");
|
||||
// See if the statement could be created
|
||||
if (stmt.IsValid())
|
||||
{
|
||||
// Bind the table name
|
||||
stmt.IndexBindS(1, name);
|
||||
// Attempt to step the statement
|
||||
if (stmt.Step())
|
||||
{
|
||||
LogErr("Unable to <see if table exists> because : the statement could not be stepped");
|
||||
// Return the requested information
|
||||
return (sqlite3_column_int(stmt, 0) == 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogErr("Unable to <see if table exists> because : the statement could not be created");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if table exists> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::IsReadOnly() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
const int result = sqlite3_db_readonly(m_Handle, "main");
|
||||
// Verify the result
|
||||
if(result == -1)
|
||||
{
|
||||
LogErr("Unable to <see if database is read only> because : 'main' is not the name of a database on connection");
|
||||
}
|
||||
// Return the result
|
||||
else
|
||||
{
|
||||
return (result != 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database is read only> using an invalid connection: null");
|
||||
}
|
||||
// It's invalid so at least fall-back to read-only
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetAutoCommit() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_get_autocommit(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <see if database has autocommit activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt Connection::GetLastInsertRowID() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_last_insert_rowid(m_Handle)));
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SLongInt(static_cast< SLongInt::Type >(SQMOD_UNKNOWN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetChanges() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_changes(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetTotalChanges() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_total_changes(m_Handle);
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <get database total changes> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetErrorCode() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_errcode(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database error code> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetExtendedErrorCode() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return sqlite3_extended_errcode(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database extended error code> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetTracing() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Trace;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database has tracing activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetTracing(bool toggle) const
|
||||
{
|
||||
if (m_Handle && m_Handle->Trace != toggle)
|
||||
{
|
||||
if (m_Handle->Trace)
|
||||
{
|
||||
sqlite3_trace(m_Handle, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_trace(m_Handle, &Connection::TraceOutput, NULL);
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <activate database tracing> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Connection::GetProfiling() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
return m_Handle->Profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <see if database has profiling activated> using an invalid connection: null");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetProfiling(bool toggle) const
|
||||
{
|
||||
if (m_Handle && m_Handle->Profile != toggle)
|
||||
{
|
||||
if (m_Handle->Profile)
|
||||
{
|
||||
sqlite3_profile(m_Handle, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_profile(m_Handle, &Connection::ProfileOutput, NULL);
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <activate database profiling> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::SetBusyTimeout(SQInteger millis) const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
if ((m_Handle->Status = sqlite3_busy_timeout(m_Handle, millis)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <set database busy timeout> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <set database busy timeout> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::InterruptOperation() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
sqlite3_interrupt(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <interrupt database operation> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::ReleaseMemory() const
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
sqlite3_db_release_memory(m_Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <release database memory> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfCheckedOutLookasideMemorySlots() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapMemoryUsedByPagerCaches() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapMemoryUsedToStoreSchemas() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_SCHEMA_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_STMT_USED);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetPagerCacheHitCount() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_HIT);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetPagerCacheMissCount() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_MISS);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfDirtyCacheEntries() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_CACHE_WRITE);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetNumberOfUnresolvedForeignKeys() const
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_DEFERRED_FKS);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_USED, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryHitCount(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_HIT, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetLookasideMemoryMissCountDueToFullMemory(bool reset)
|
||||
{
|
||||
return GetInfo(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, true, reset);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection Connection::CopyToMemory()
|
||||
{
|
||||
if (m_Handle && !m_Handle->Memory)
|
||||
{
|
||||
// Attempt to open an in-memory database
|
||||
Handle db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
// See if the database could be opened
|
||||
if (!db)
|
||||
{
|
||||
LogErr("Unable to <open in-memory database> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Begin a transaction to replicate the schema of origin database
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "BEGIN", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <begin database schema replication> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to replicate the schema of origin database to the in-memory one
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle,
|
||||
"SELECT [sql] FROM [sqlite_master] WHERE [sql] NOT NULL AND [tbl_name] != 'sqlite_sequence'",
|
||||
&Connection::ProcessDDLRow, db, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <replicate database schema> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database schema replication
|
||||
else if ((m_Handle->Status = sqlite3_exec(m_Handle, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit database schema replication> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to attach the origin database to the in-memory one
|
||||
else if ((db->Status = sqlite3_exec(db, ToStringF("ATTACH DATABASE '%s' as origin",
|
||||
m_Handle->Path.c_str()), NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <attach database origin> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Begin a transaction to replicate the data of origin database
|
||||
else if ((db->Status = sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK))
|
||||
{
|
||||
LogErr("Unable to <begin database data replication> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Attempt to replicate the data of origin database to the in-memory one
|
||||
else if ((db->Status = sqlite3_exec(db, "SELECT [name] FROM [origin.sqlite_master] WHERE [type]='table'",
|
||||
&Connection::ProcessDMLRow, db, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <replicate database data> because : %s", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database data replication
|
||||
else if ((db->Status = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit database data replication> because : %s", db.ErrMsg());
|
||||
// Attempt to rollback changes from the data copy operation
|
||||
if ((db->Status = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <rollback database data replication> because : %s", db.ErrMsg());
|
||||
}
|
||||
// Attempt to detach the disk origin from in-memory database
|
||||
else if ((db->Status = sqlite3_exec(db, "DETACH DATABASE origin", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <detach database origin> because : %s", db.ErrMsg());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return the new in-memory database
|
||||
return db;
|
||||
}
|
||||
}
|
||||
else if (!m_Handle)
|
||||
{
|
||||
LogWrn("Attempting to <copy database to memory> using an invalid connection: null");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <copy database to memory> for a database which is already in memory");
|
||||
}
|
||||
// Fall-back to an invalid connection
|
||||
return Connection();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Connection Connection::CopyToDatabase(const SQChar * path)
|
||||
{
|
||||
if (m_Handle)
|
||||
{
|
||||
// See if the specified name is valid
|
||||
if (strlen(path) <= 0)
|
||||
{
|
||||
LogWrn("Attempting to <replicate database> using an invalid path: null");
|
||||
}
|
||||
// Attempt to open the specified database
|
||||
Handle db(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
// See if the database could be opened
|
||||
if (!db)
|
||||
{
|
||||
LogErr("Unable to <open the specified database> because : %s", db.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Attempt to take snapshot of the database
|
||||
TakeSnapshot(db);
|
||||
// Return the database clone
|
||||
return db;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <replicate database> using an invalid connection: null");
|
||||
}
|
||||
// Fall-back to an invalid connection
|
||||
return Connection();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::TraceOutput(void * ptr, const char * sql)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(ptr);
|
||||
LogInf("SQLite Trace: %s", sql);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(ptr);
|
||||
LogInf("SQLite profile (time: %llu): %s", time, sql);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Connection::ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(columns);
|
||||
|
||||
if(columns_count != 1)
|
||||
{
|
||||
LogErr("Error occurred during DDL: columns != 1");
|
||||
// Operation failed
|
||||
return -1;
|
||||
}
|
||||
// Execute the sql statement in values[0] in the received database connection
|
||||
if(sqlite3_exec(static_cast< sqlite3 * >(db), values[0], NULL, NULL, NULL) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Error occurred during DDL execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
|
||||
}
|
||||
// Operation succeeded
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Connection::ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns)
|
||||
{
|
||||
SQMOD_UNUSED_VAR(columns);
|
||||
|
||||
if(columns_count != 1)
|
||||
{
|
||||
LogErr("Error occurred during DML: columns != 1");
|
||||
// Operation failed
|
||||
return -1;
|
||||
}
|
||||
// Generate the query string with the received values
|
||||
char * sql = sqlite3_mprintf("INSERT INTO main.%q SELECT * FROM origin.%q", values[0], values[0]);
|
||||
// Attempt to execute the generated query string to the received database connection
|
||||
if(sqlite3_exec(static_cast< sqlite3 * >(db), sql, NULL, NULL, NULL) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Error occurred during DML execution: %s", sqlite3_errmsg(static_cast< sqlite3 * >(db)));
|
||||
}
|
||||
// Free the generated query string
|
||||
sqlite3_free(sql);
|
||||
// Operation succeeded
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Connection::TakeSnapshot(Handle & destination)
|
||||
{
|
||||
// Don't even bother to continue if there's no valid connection handle
|
||||
if (m_Handle && destination)
|
||||
{
|
||||
// Attempt to initialize a backup structure
|
||||
sqlite3_backup * backup = sqlite3_backup_init(destination, "main", m_Handle, "main");
|
||||
// See if the backup structure could be created
|
||||
if(backup)
|
||||
{
|
||||
// -1 to copy the entire source database to the destination
|
||||
if((m_Handle->Status = sqlite3_backup_step(backup, -1)) != SQLITE_DONE)
|
||||
{
|
||||
LogErr("Unable to <copy database source> because: %s", sqlite3_errmsg(destination));
|
||||
}
|
||||
// clean up resources allocated by sqlite3_backup_init()
|
||||
if((m_Handle->Status = sqlite3_backup_finish(backup)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <finalize database backup> because: %s", sqlite3_errmsg(destination));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!destination)
|
||||
{
|
||||
LogWrn("Attempting to <take database snapshot> using an invalid destination: null");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <take database snapshot> using an invalid connection: null");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 Connection::GetInfo(int operation, bool highwater, bool reset) const
|
||||
{
|
||||
// Don't even bother to continue if there's no valid connection handle
|
||||
if (m_Handle)
|
||||
{
|
||||
int cur_value;
|
||||
int hiwtr_value;
|
||||
// Attempt to retrieve the specified information
|
||||
if((m_Handle->Status = sqlite3_db_status(m_Handle, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <get database runtime status information> because: %s", sqlite3_errmsg(m_Handle));
|
||||
}
|
||||
// Return what was requested
|
||||
return highwater ? hiwtr_value : cur_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <get database runtime status information> using an invalid connection: null");
|
||||
}
|
||||
return SQMOD_UNKNOWN;
|
||||
}
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
@ -1,60 +1,434 @@
|
||||
#ifndef _LIBRARY_SQLITE_CONNECTION_HPP_
|
||||
#define _LIBRARY_SQLITE_CONNECTION_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Class used to manage a conenction to an SQLite database.
|
||||
*/
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* The type of SQLite resource handle that this class uses.
|
||||
*/
|
||||
typedef ConnectionHandle Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
Connection();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Open a connection to a database using the specified path.
|
||||
*/
|
||||
Connection(const Connection & o);
|
||||
Connection(const SQChar * path);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Open a connection to a database using the specified path and flags.
|
||||
*/
|
||||
Connection(Connection && o);
|
||||
Connection(const SQChar * path, SQInt32 flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Open a connection to a database using the specified path, flags and vfs.
|
||||
*/
|
||||
~Connection();
|
||||
Connection(const SQChar * path, SQInt32 flags, const SQChar * vfs);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Construct and reference an existing connection.
|
||||
*/
|
||||
Connection & operator = (const Connection & o);
|
||||
Connection(const Handle & hnd);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Copy constructor.
|
||||
*/
|
||||
Connection & operator = (Connection && o);
|
||||
Connection(const Connection & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Move constructor.
|
||||
*/
|
||||
Connection(Connection && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Connection() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Connection & operator = (const Connection & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Connection & operator = (Connection && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a handle reference.
|
||||
*/
|
||||
operator const Handle & () const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * ()
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const Connection & o) const
|
||||
{
|
||||
return (m_Handle == o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const Connection & o) const
|
||||
{
|
||||
return (m_Handle != o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script to compare two instances of this type.
|
||||
*/
|
||||
SQInt32 Cmp(const Connection & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Convert this type to a string.
|
||||
*/
|
||||
const SQChar * ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the global tag.
|
||||
*/
|
||||
const SQChar * GetGlobalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the global tag.
|
||||
*/
|
||||
void SetGlobalTag(const SQChar * tag) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the global data.
|
||||
*/
|
||||
SqObj & GetGlobalData() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the global data.
|
||||
*/
|
||||
void SetGlobalData(SqObj & data) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local tag.
|
||||
*/
|
||||
const SQChar * GetLocalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local tag.
|
||||
*/
|
||||
void SetLocalTag(const SQChar * tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local data.
|
||||
*/
|
||||
SqObj & GetLocalData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local data.
|
||||
*/
|
||||
void SetLocalData(SqObj & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the handle reference.
|
||||
*/
|
||||
const Handle & GetHandle() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of active references to this handle.
|
||||
*/
|
||||
SQUint32 GetRefs() const
|
||||
{
|
||||
return m_Handle ? m_Handle.Count() : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the handle reference.
|
||||
*/
|
||||
void Release()
|
||||
{
|
||||
m_Handle.Release();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query.
|
||||
*/
|
||||
bool IsValid() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last received error code.
|
||||
*/
|
||||
SQInt32 GetStatus() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the flags used to create this database connection.
|
||||
*/
|
||||
SQInt32 GetFlags() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the path used to create this database connection.
|
||||
*/
|
||||
const SQChar * GetPath() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the virtual file system used to create this database connection.
|
||||
*/
|
||||
const SQChar * GetVFS() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the message of the last received error code.
|
||||
*/
|
||||
const SQChar * GetErrStr() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the last error message associated with this database connection.
|
||||
*/
|
||||
const SQChar * GetErrMsg() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query.
|
||||
*/
|
||||
SQInt32 Exec(const SQChar * str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to queue the specified query.
|
||||
*/
|
||||
void Queue(const SQChar * str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Shortcut to test if a table exists.
|
||||
*/
|
||||
bool TableExists(const SQChar * name) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the database connection was opened in read-only mode.
|
||||
*/
|
||||
bool IsReadOnly() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the database connection is or is not in autocommit mode.
|
||||
*/
|
||||
bool GetAutoCommit() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the rowid of the most recent successful INSERT into the database from the current connection.
|
||||
*/
|
||||
SLongInt GetLastInsertRowID() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of database rows that were changed, inserted or deleted
|
||||
* by the most recently completed SQL statement.
|
||||
*/
|
||||
SQInt32 GetChanges() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the total number of row changes caused by INSERT, UPDATE or DELETE statements
|
||||
* since the database connection was opened.
|
||||
*/
|
||||
SQInt32 GetTotalChanges() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the extended numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetExtendedErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if this database connection has tracing enabled.
|
||||
*/
|
||||
bool GetTracing() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Activate or deactivate tracing on this database connection.
|
||||
*/
|
||||
void SetTracing(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if this database connection has profiling enabled.
|
||||
*/
|
||||
bool GetProfiling() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Activate or deactivate profiling on this database connection.
|
||||
*/
|
||||
void SetProfiling(bool toggle) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set a busy handler that sleeps for a specified amount of time when a table is locked.
|
||||
*/
|
||||
void SetBusyTimeout(SQInteger millis) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Causes any pending database operation to abort and return at its earliest opportunity.
|
||||
*/
|
||||
void InterruptOperation() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempts to free as much heap memory as possible from the database connection.
|
||||
*/
|
||||
void ReleaseMemory() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of lookaside memory slots currently checked out.
|
||||
*/
|
||||
SQInt32 GetNumberOfCheckedOutLookasideMemorySlots() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap memory used by all pager caches.
|
||||
*/
|
||||
SQInt32 GetHeapMemoryUsedByPagerCaches() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap memory used to store the schema for
|
||||
* all databases associated with the connection - main, temp, and any ATTACH-ed databases.
|
||||
*/
|
||||
SQInt32 GetHeapMemoryUsedToStoreSchemas() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the approximate number of bytes of heap and lookaside memory used by all
|
||||
* prepared statements associated with the database connection.
|
||||
*/
|
||||
SQInt32 GetHeapAndLookasideMemoryUsedByPreparedStatements() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of pager cache hits that have occurred.
|
||||
*/
|
||||
SQInt32 GetPagerCacheHitCount() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of pager cache misses that have occurred.
|
||||
*/
|
||||
SQInt32 GetPagerCacheMissCount() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number of dirty cache entries that have been written to disk.
|
||||
*/
|
||||
SQInt32 GetNumberOfDirtyCacheEntries() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns zero if all foreign key constraints (deferred or immediate) have been resolved.
|
||||
*/
|
||||
SQInt32 GetNumberOfUnresolvedForeignKeys() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the highest number of lookaside memory slots that has been checked out.
|
||||
*/
|
||||
SQInt32 GetHighestNumberOfCheckedOutLookasideMemorySlots(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that were satisfied using lookaside memory.
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryHitCount(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that might have been satisfied using lookaside memory.
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryMissCountDueToSmallSlotSize(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the number malloc attempts that might have been satisfied using lookaside memory
|
||||
*/
|
||||
SQInt32 GetLookasideMemoryMissCountDueToFullMemory(bool reset);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move the whole database into memory.
|
||||
*/
|
||||
Connection CopyToMemory();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Takes a snapshot of a database which is located in memory and saves it to a database file.
|
||||
*/
|
||||
Connection CopyToDatabase(const SQChar * path);
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Callback function for ActivateTracing()
|
||||
*/
|
||||
static void TraceOutput(void * ptr, const char * sql);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Callback function for ActivateProfiling()
|
||||
*/
|
||||
static void ProfileOutput(void * ptr, const char * sql, sqlite3_uint64 time);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build and modify the structure of tables and other objects in the memory database.
|
||||
*/
|
||||
static int ProcessDDLRow(void * db, int columns_count, char ** values, char ** columns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Insert all data from the origin database into the memory database.
|
||||
*/
|
||||
static int ProcessDMLRow(void * db, int columns_count, char ** values, char ** columns);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Takes and saves a snapshot of the memory database in a file.
|
||||
*/
|
||||
void TakeSnapshot(Handle & destination);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns internal runtime status information associated with the current database connection.
|
||||
*/
|
||||
SQInt32 GetInfo(int operation, bool highwater = false, bool reset = false) const;
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reference to the managed SQLite connection handle.
|
||||
*/
|
||||
Handle m_Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local tag associated with this instance.
|
||||
*/
|
||||
SqTag m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local data associated with this instance.
|
||||
*/
|
||||
SqObj m_Data;
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
|
@ -1,63 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_RESULT_HPP_
|
||||
#define _LIBRARY_SQLITE_RESULT_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Result();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Result(const Result & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Result(Result && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~Result();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Result & operator = (const Result & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Result & operator = (Result && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_RESULT_HPP_
|
673
source/Library/SQLite/Shared.cpp
Normal file
673
source/Library/SQLite/Shared.cpp
Normal file
@ -0,0 +1,673 @@
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
#include "Library/SQLite/Connection.hpp"
|
||||
#include "Library/SQLite/Statement.hpp"
|
||||
#include "Register.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle()
|
||||
: Hnd(nullptr)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs)
|
||||
: Hnd(new Handle(path, flags, vfs != NULL ? vfs : _SC("")))
|
||||
{
|
||||
// See if a handle could be created
|
||||
if (!Hnd)
|
||||
{
|
||||
LogErr("Attempting to <open database connection> without a valid handle");
|
||||
Drop();
|
||||
}
|
||||
// At least the path must be valid
|
||||
else if (Hnd->Path.empty())
|
||||
{
|
||||
LogErr("Attempting to <open database connection> without a valid path");
|
||||
Drop();
|
||||
}
|
||||
// Attempt to open a connection
|
||||
else if ((Hnd->Status = sqlite3_open_v2(path, &(*Hnd).Ptr, flags, vfs)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <open database> because : %d", sqlite3_errmsg(Hnd->Ptr));
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(const ConnectionHandle & o)
|
||||
: Hnd(o.Hnd)
|
||||
{
|
||||
// Grab a reference to the new handle
|
||||
Grab();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::ConnectionHandle(ConnectionHandle && o)
|
||||
: Hnd(o.Hnd)
|
||||
{
|
||||
// Prevent the other instance from releasing the stolen reference
|
||||
o.Hnd = nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle::~ConnectionHandle()
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle & ConnectionHandle::operator = (const ConnectionHandle & o)
|
||||
{
|
||||
// Make sure it's not the same handle instance in both
|
||||
if (Hnd != o.Hnd)
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
// Assign the specified handle
|
||||
Hnd = o.Hnd;
|
||||
// Grab a reference to the new handle
|
||||
Grab();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ConnectionHandle & ConnectionHandle::operator = (ConnectionHandle && o)
|
||||
{
|
||||
// Make sure it's not the same handle instance in both
|
||||
if (Hnd != o.Hnd)
|
||||
{
|
||||
// Drop the current handle reference if any
|
||||
Drop();
|
||||
// Steal the handle reference from the other instance
|
||||
Hnd = o.Hnd;
|
||||
// Prevent the other instance from releasing the stolen reference
|
||||
o.Hnd = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Transaction::Transaction(const Connection & db)
|
||||
: m_Connection(db), m_Commited(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Transaction::~Transaction()
|
||||
{
|
||||
if (!m_Commited && m_Connection)
|
||||
{
|
||||
if ((m_Connection->Status = sqlite3_exec(m_Connection, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <rollback transaction> because: %s", m_Connection.ErrMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Transaction::Commit()
|
||||
{
|
||||
if (!m_Commited && m_Connection)
|
||||
{
|
||||
if ((m_Connection->Status = sqlite3_exec(m_Connection, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <commit transaction> because: %s", m_Connection.ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Commited = true;
|
||||
}
|
||||
}
|
||||
else if (m_Commited)
|
||||
{
|
||||
LogWrn("Attempting to <commit transaction> which was already committed");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogWrn("Attempting to <commit transaction> using an invalid connection");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SetSoftHeapLimit(SQInt32 limit)
|
||||
{
|
||||
sqlite3_soft_heap_limit(limit);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInt32 ReleaseMemory(SQInt32 bytes)
|
||||
{
|
||||
return sqlite3_release_memory(bytes);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt GetMemoryUsage()
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_used()));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SLongInt GetMemoryHighwaterMark(bool reset)
|
||||
{
|
||||
return SLongInt(static_cast< SLongInt::Type >(sqlite3_memory_highwater(reset)));
|
||||
}
|
||||
|
||||
} // Namespace:: SQLite
|
||||
|
||||
// ================================================================================================
|
||||
bool Register_SQLite(HSQUIRRELVM vm)
|
||||
{
|
||||
using namespace SQLite;
|
||||
|
||||
// Attempt to create the SQLite namespace
|
||||
Sqrat::Table sqlns(vm);
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Connection> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Connection"), Sqrat::Class< Connection >(vm, _SC("Connection"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< const SQChar * >()
|
||||
.Ctor< const SQChar *, SQInt32 >()
|
||||
.Ctor< const SQChar *, SQInt32, const SQChar * >()
|
||||
/* Metamethods */
|
||||
.Func(_SC("_cmp"), &Connection::Cmp)
|
||||
.Func(_SC("_tostring"), &Connection::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("gtag"), &Connection::GetGlobalTag, &Connection::SetGlobalTag)
|
||||
.Prop(_SC("gdata"), &Connection::GetGlobalData, &Connection::SetGlobalData)
|
||||
.Prop(_SC("ltag"), &Connection::GetLocalTag, &Connection::SetLocalTag)
|
||||
.Prop(_SC("ldata"), &Connection::GetLocalData, &Connection::SetLocalData)
|
||||
.Prop(_SC("refs"), &Connection::GetRefs)
|
||||
.Prop(_SC("valid"), &Connection::IsValid)
|
||||
.Prop(_SC("connected"), &Connection::IsValid)
|
||||
.Prop(_SC("status"), &Connection::GetStatus)
|
||||
.Prop(_SC("flags"), &Connection::GetFlags)
|
||||
.Prop(_SC("path"), &Connection::GetPath)
|
||||
.Prop(_SC("vfs"), &Connection::GetVFS)
|
||||
.Prop(_SC("err_str"), &Connection::GetErrStr)
|
||||
.Prop(_SC("err_msg"), &Connection::GetErrMsg)
|
||||
.Prop(_SC("read_only"), &Connection::IsReadOnly)
|
||||
.Prop(_SC("auto_commit"), &Connection::GetAutoCommit)
|
||||
.Prop(_SC("last_insert_row_id"), &Connection::GetLastInsertRowID)
|
||||
.Prop(_SC("changes"), &Connection::GetChanges)
|
||||
.Prop(_SC("total_changes"), &Connection::GetTotalChanges)
|
||||
.Prop(_SC("err_code"), &Connection::GetErrorCode)
|
||||
.Prop(_SC("extended_err_code"), &Connection::GetExtendedErrorCode)
|
||||
.Prop(_SC("trace"), &Connection::GetTracing, &Connection::SetTracing)
|
||||
.Prop(_SC("profile"), &Connection::GetProfiling, &Connection::SetProfiling)
|
||||
.Prop(_SC("busy_timeout"), &Connection::SetBusyTimeout)
|
||||
.Prop(_SC("number_of_checked_out_lookaside_memory_slots"), &Connection::GetNumberOfCheckedOutLookasideMemorySlots)
|
||||
.Prop(_SC("heap_memory_used_by_pager_caches"), &Connection::GetHeapMemoryUsedByPagerCaches)
|
||||
.Prop(_SC("heap_memory_used_to_store_schemas"), &Connection::GetHeapMemoryUsedToStoreSchemas)
|
||||
.Prop(_SC("heap_and_lookaside_memory_used_by_prepared_statements"), &Connection::GetHeapAndLookasideMemoryUsedByPreparedStatements)
|
||||
.Prop(_SC("pagercache_hit_count"), &Connection::GetPagerCacheHitCount)
|
||||
.Prop(_SC("pagercache_miss_count"), &Connection::GetPagerCacheMissCount)
|
||||
.Prop(_SC("number_of_dirty_cache_entries"), &Connection::GetNumberOfDirtyCacheEntries)
|
||||
.Prop(_SC("number_of_unresolved_foreign_keys"), &Connection::GetNumberOfUnresolvedForeignKeys)
|
||||
.Prop(_SC("highest_number_of_checked_out_lookaside_memory_slots"), &Connection::GetHighestNumberOfCheckedOutLookasideMemorySlots)
|
||||
.Prop(_SC("lookaside_memory_hit_count"), &Connection::GetLookasideMemoryHitCount)
|
||||
.Prop(_SC("lookaside_memory_miss_count_due_to_small_slot_size"), &Connection::GetLookasideMemoryMissCountDueToSmallSlotSize)
|
||||
.Prop(_SC("lookaside_memory_miss_count_due_to_full_memory"), &Connection::GetLookasideMemoryMissCountDueToFullMemory)
|
||||
/* Functions */
|
||||
.Func(_SC("release"), &Connection::Release)
|
||||
.Func(_SC("exec"), &Connection::Exec)
|
||||
.Func(_SC("queue"), &Connection::Queue)
|
||||
.Func(_SC("table_exists"), &Connection::TableExists)
|
||||
.Func(_SC("interrupt_operation"), &Connection::InterruptOperation)
|
||||
.Func(_SC("release_memory"), &Connection::ReleaseMemory)
|
||||
.Func(_SC("copy_to_memory"), &Connection::CopyToMemory)
|
||||
.Func(_SC("copy_to_database"), &Connection::CopyToDatabase)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Connection> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Statement> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Statement"), Sqrat::Class< Statement, NoCopy< Statement > >(vm, _SC("Statement"))
|
||||
/* Constructors */
|
||||
.Ctor()
|
||||
.Ctor< const Connection &, const SQChar * >()
|
||||
/* Metamethods */
|
||||
.Func(_SC("_cmp"), &Statement::Cmp)
|
||||
.Func(_SC("_tostring"), &Statement::ToString)
|
||||
/* Properties */
|
||||
.Prop(_SC("ltag"), &Statement::GetLocalTag, &Statement::SetLocalTag)
|
||||
.Prop(_SC("ldata"), &Statement::GetLocalData, &Statement::SetLocalData)
|
||||
.Prop(_SC("valid"), &Statement::IsValid)
|
||||
.Prop(_SC("status"), &Statement::GetStatus)
|
||||
.Prop(_SC("columns"), &Statement::GetColumns)
|
||||
.Prop(_SC("query"), &Statement::GetQuery)
|
||||
.Prop(_SC("err_str"), &Statement::GetErrStr)
|
||||
.Prop(_SC("err_msg"), &Statement::GetErrMsg)
|
||||
.Prop(_SC("connection"), &Statement::GetConnection)
|
||||
.Prop(_SC("good"), &Statement::GetGood)
|
||||
.Prop(_SC("done"), &Statement::GetDone)
|
||||
.Prop(_SC("err_code"), &Statement::GetErrorCode)
|
||||
.Prop(_SC("extended_err_code"), &Statement::GetExtendedErrorCode)
|
||||
/* Functions */
|
||||
.Func(_SC("reset"), &Statement::Reset)
|
||||
.Func(_SC("clear"), &Statement::Clear)
|
||||
.Func(_SC("exec"), &Statement::Exec)
|
||||
.Func(_SC("step"), &Statement::Step)
|
||||
.Func(_SC("ibind_a"), &Statement::IndexBindA)
|
||||
.Func(_SC("ibind_t"), &Statement::IndexBindT)
|
||||
.Func(_SC("ibind_i"), &Statement::IndexBindI)
|
||||
.Func(_SC("ibind_l"), &Statement::IndexBindL)
|
||||
.Func(_SC("ibind_v"), &Statement::IndexBindV)
|
||||
.Func(_SC("ibind_f"), &Statement::IndexBindF)
|
||||
.Func(_SC("ibind_s"), &Statement::IndexBindS)
|
||||
.Func(_SC("ibind_b"), &Statement::IndexBindB)
|
||||
.Func(_SC("ibind_n"), &Statement::IndexBindN)
|
||||
.Func(_SC("nbind_t"), &Statement::NameBindT)
|
||||
.Func(_SC("nbind_i"), &Statement::NameBindI)
|
||||
.Func(_SC("nbind_l"), &Statement::NameBindL)
|
||||
.Func(_SC("nbind_v"), &Statement::NameBindV)
|
||||
.Func(_SC("nbind_f"), &Statement::NameBindF)
|
||||
.Func(_SC("nbind_s"), &Statement::NameBindS)
|
||||
.Func(_SC("nbind_b"), &Statement::NameBindB)
|
||||
.Func(_SC("nbind_n"), &Statement::NameBindN)
|
||||
.Func(_SC("ibind"), &Statement::IndexBind)
|
||||
.Func(_SC("nbind"), &Statement::NameBind)
|
||||
.Func(_SC("fetchi"), &Statement::FetchColumnIndex)
|
||||
.Func(_SC("fetchn"), &Statement::FetchColumnName)
|
||||
.Func(_SC("fetcha"), &Statement::FetchArray)
|
||||
.Func(_SC("fetcht"), &Statement::FetchTable)
|
||||
.Func(_SC("is_column_null"), &Statement::IsColumnNull)
|
||||
.Func(_SC("column_name"), &Statement::GetColumnName)
|
||||
.Func(_SC("column_origin_name"), &Statement::GetColumnOriginName)
|
||||
.Func(_SC("column_type"), &Statement::GetColumnType)
|
||||
.Func(_SC("column_bytes"), &Statement::GetColumnBytes)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Statement> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Transaction> type");
|
||||
// Attempt to register the specified type
|
||||
sqlns.Bind(_SC("Transaction"), Sqrat::Class< Transaction, NoCopy< Transaction > >(vm, _SC("Transaction"))
|
||||
/* Constructors */
|
||||
.Ctor< const Connection & >()
|
||||
/* Properties */
|
||||
.Prop(_SC("committed"), &Transaction::Commited)
|
||||
/* Functions */
|
||||
.Func(_SC("commit"), &Transaction::Commit)
|
||||
);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Transaction> type was successful");
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite functions> type");
|
||||
// Attempt to register the specified functions
|
||||
sqlns.Func(_SC("set_soft_heap_limit"), &SetSoftHeapLimit);
|
||||
sqlns.Func(_SC("release_memory"), &ReleaseMemory);
|
||||
sqlns.Func(_SC("memory_usage"), &GetMemoryUsage);
|
||||
sqlns.Func(_SC("memory_highwater_mark"), &GetMemoryHighwaterMark);
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite functions> type was successful");
|
||||
|
||||
// Attempt to bind the namespace to the root table
|
||||
Sqrat::RootTable(vm).Bind(_SC("SQLite"), sqlns);
|
||||
|
||||
// Output debugging information
|
||||
LogDbg("Beginning registration of <SQLite Constants> type");
|
||||
/*
|
||||
// Attempt to register the SQLite constants enumeration
|
||||
Sqrat::ConstTable(vm).Enum(_SC("ESQLITE"), Sqrat::Enumeration(vm)
|
||||
.Const(_SC("ABORT"), SQLITE_ABORT)
|
||||
.Const(_SC("ABORT_ROLLBACK"), SQLITE_ABORT_ROLLBACK)
|
||||
.Const(_SC("ACCESS_EXISTS"), SQLITE_ACCESS_EXISTS)
|
||||
.Const(_SC("ACCESS_READ"), SQLITE_ACCESS_READ)
|
||||
.Const(_SC("ACCESS_READWRITE"), SQLITE_ACCESS_READWRITE)
|
||||
.Const(_SC("ALTER_TABLE"), SQLITE_ALTER_TABLE)
|
||||
.Const(_SC("ANALYZE"), SQLITE_ANALYZE)
|
||||
.Const(_SC("ANY"), SQLITE_ANY)
|
||||
.Const(_SC("ATTACH"), SQLITE_ATTACH)
|
||||
.Const(_SC("AUTH"), SQLITE_AUTH)
|
||||
.Const(_SC("AUTH_USER"), SQLITE_AUTH_USER)
|
||||
.Const(_SC("BLOB"), SQLITE_BLOB)
|
||||
.Const(_SC("BUSY"), SQLITE_BUSY)
|
||||
.Const(_SC("BUSY_RECOVERY"), SQLITE_BUSY_RECOVERY)
|
||||
.Const(_SC("BUSY_SNAPSHOT"), SQLITE_BUSY_SNAPSHOT)
|
||||
.Const(_SC("CANTOPEN"), SQLITE_CANTOPEN)
|
||||
.Const(_SC("CANTOPEN_CONVPATH"), SQLITE_CANTOPEN_CONVPATH)
|
||||
.Const(_SC("CANTOPEN_FULLPATH"), SQLITE_CANTOPEN_FULLPATH)
|
||||
.Const(_SC("CANTOPEN_ISDIR"), SQLITE_CANTOPEN_ISDIR)
|
||||
.Const(_SC("CANTOPEN_NOTEMPDIR"), SQLITE_CANTOPEN_NOTEMPDIR)
|
||||
.Const(_SC("CHECKPOINT_FULL"), SQLITE_CHECKPOINT_FULL)
|
||||
.Const(_SC("CHECKPOINT_PASSIVE"), SQLITE_CHECKPOINT_PASSIVE)
|
||||
.Const(_SC("CHECKPOINT_RESTART"), SQLITE_CHECKPOINT_RESTART)
|
||||
.Const(_SC("CHECKPOINT_TRUNCATE"), SQLITE_CHECKPOINT_TRUNCATE)
|
||||
.Const(_SC("CONFIG_COVERING_INDEX_SCAN"), SQLITE_CONFIG_COVERING_INDEX_SCAN)
|
||||
.Const(_SC("CONFIG_GETMALLOC"), SQLITE_CONFIG_GETMALLOC)
|
||||
.Const(_SC("CONFIG_GETMUTEX"), SQLITE_CONFIG_GETMUTEX)
|
||||
.Const(_SC("CONFIG_GETPCACHE"), SQLITE_CONFIG_GETPCACHE)
|
||||
.Const(_SC("CONFIG_GETPCACHE2"), SQLITE_CONFIG_GETPCACHE2)
|
||||
.Const(_SC("CONFIG_HEAP"), SQLITE_CONFIG_HEAP)
|
||||
.Const(_SC("CONFIG_LOG"), SQLITE_CONFIG_LOG)
|
||||
.Const(_SC("CONFIG_LOOKASIDE"), SQLITE_CONFIG_LOOKASIDE)
|
||||
.Const(_SC("CONFIG_MALLOC"), SQLITE_CONFIG_MALLOC)
|
||||
.Const(_SC("CONFIG_MEMSTATUS"), SQLITE_CONFIG_MEMSTATUS)
|
||||
.Const(_SC("CONFIG_MMAP_SIZE"), SQLITE_CONFIG_MMAP_SIZE)
|
||||
.Const(_SC("CONFIG_MULTITHREAD"), SQLITE_CONFIG_MULTITHREAD)
|
||||
.Const(_SC("CONFIG_MUTEX"), SQLITE_CONFIG_MUTEX)
|
||||
.Const(_SC("CONFIG_PAGECACHE"), SQLITE_CONFIG_PAGECACHE)
|
||||
.Const(_SC("CONFIG_PCACHE"), SQLITE_CONFIG_PCACHE)
|
||||
.Const(_SC("CONFIG_PCACHE2"), SQLITE_CONFIG_PCACHE2)
|
||||
.Const(_SC("CONFIG_PCACHE_HDRSZ"), SQLITE_CONFIG_PCACHE_HDRSZ)
|
||||
.Const(_SC("CONFIG_PMASZ"), SQLITE_CONFIG_PMASZ)
|
||||
.Const(_SC("CONFIG_SCRATCH"), SQLITE_CONFIG_SCRATCH)
|
||||
.Const(_SC("CONFIG_SERIALIZED"), SQLITE_CONFIG_SERIALIZED)
|
||||
.Const(_SC("CONFIG_SINGLETHREAD"), SQLITE_CONFIG_SINGLETHREAD)
|
||||
.Const(_SC("CONFIG_SQLLOG"), SQLITE_CONFIG_SQLLOG)
|
||||
.Const(_SC("CONFIG_URI"), SQLITE_CONFIG_URI)
|
||||
.Const(_SC("CONFIG_WIN32_HEAPSIZE"), SQLITE_CONFIG_WIN32_HEAPSIZE)
|
||||
.Const(_SC("CONSTRAINT"), SQLITE_CONSTRAINT)
|
||||
.Const(_SC("CONSTRAINT_CHECK"), SQLITE_CONSTRAINT_CHECK)
|
||||
.Const(_SC("CONSTRAINT_COMMITHOOK"), SQLITE_CONSTRAINT_COMMITHOOK)
|
||||
.Const(_SC("CONSTRAINT_FOREIGNKEY"), SQLITE_CONSTRAINT_FOREIGNKEY)
|
||||
.Const(_SC("CONSTRAINT_FUNCTION"), SQLITE_CONSTRAINT_FUNCTION)
|
||||
.Const(_SC("CONSTRAINT_NOTNULL"), SQLITE_CONSTRAINT_NOTNULL)
|
||||
.Const(_SC("CONSTRAINT_PRIMARYKEY"), SQLITE_CONSTRAINT_PRIMARYKEY)
|
||||
.Const(_SC("CONSTRAINT_ROWID"), SQLITE_CONSTRAINT_ROWID)
|
||||
.Const(_SC("CONSTRAINT_TRIGGER"), SQLITE_CONSTRAINT_TRIGGER)
|
||||
.Const(_SC("CONSTRAINT_UNIQUE"), SQLITE_CONSTRAINT_UNIQUE)
|
||||
.Const(_SC("CONSTRAINT_VTAB"), SQLITE_CONSTRAINT_VTAB)
|
||||
.Const(_SC("COPY"), SQLITE_COPY)
|
||||
.Const(_SC("CORRUPT"), SQLITE_CORRUPT)
|
||||
.Const(_SC("CORRUPT_VTAB"), SQLITE_CORRUPT_VTAB)
|
||||
.Const(_SC("CREATE_INDEX"), SQLITE_CREATE_INDEX)
|
||||
.Const(_SC("CREATE_TABLE"), SQLITE_CREATE_TABLE)
|
||||
.Const(_SC("CREATE_TEMP_INDEX"), SQLITE_CREATE_TEMP_INDEX)
|
||||
.Const(_SC("CREATE_TEMP_TABLE"), SQLITE_CREATE_TEMP_TABLE)
|
||||
.Const(_SC("CREATE_TEMP_TRIGGER"), SQLITE_CREATE_TEMP_TRIGGER)
|
||||
.Const(_SC("CREATE_TEMP_VIEW"), SQLITE_CREATE_TEMP_VIEW)
|
||||
.Const(_SC("CREATE_TRIGGER"), SQLITE_CREATE_TRIGGER)
|
||||
.Const(_SC("CREATE_VIEW"), SQLITE_CREATE_VIEW)
|
||||
.Const(_SC("CREATE_VTABLE"), SQLITE_CREATE_VTABLE)
|
||||
.Const(_SC("DBCONFIG_ENABLE_FKEY"), SQLITE_DBCONFIG_ENABLE_FKEY)
|
||||
.Const(_SC("DBCONFIG_ENABLE_TRIGGER"), SQLITE_DBCONFIG_ENABLE_TRIGGER)
|
||||
.Const(_SC("DBCONFIG_LOOKASIDE"), SQLITE_DBCONFIG_LOOKASIDE)
|
||||
.Const(_SC("DBSTATUS_CACHE_HIT"), SQLITE_DBSTATUS_CACHE_HIT)
|
||||
.Const(_SC("DBSTATUS_CACHE_MISS"), SQLITE_DBSTATUS_CACHE_MISS)
|
||||
.Const(_SC("DBSTATUS_CACHE_USED"), SQLITE_DBSTATUS_CACHE_USED)
|
||||
.Const(_SC("DBSTATUS_CACHE_WRITE"), SQLITE_DBSTATUS_CACHE_WRITE)
|
||||
.Const(_SC("DBSTATUS_DEFERRED_FKS"), SQLITE_DBSTATUS_DEFERRED_FKS)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_HIT"), SQLITE_DBSTATUS_LOOKASIDE_HIT)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_FULL"), SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_MISS_SIZE"), SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE)
|
||||
.Const(_SC("DBSTATUS_LOOKASIDE_USED"), SQLITE_DBSTATUS_LOOKASIDE_USED)
|
||||
.Const(_SC("DBSTATUS_MAX"), SQLITE_DBSTATUS_MAX)
|
||||
.Const(_SC("DBSTATUS_SCHEMA_USED"), SQLITE_DBSTATUS_SCHEMA_USED)
|
||||
.Const(_SC("DBSTATUS_STMT_USED"), SQLITE_DBSTATUS_STMT_USED)
|
||||
.Const(_SC("DELETE"), SQLITE_DELETE)
|
||||
.Const(_SC("DENY"), SQLITE_DENY)
|
||||
.Const(_SC("DETACH"), SQLITE_DETACH)
|
||||
.Const(_SC("DETERMINISTIC"), SQLITE_DETERMINISTIC)
|
||||
.Const(_SC("DONE"), SQLITE_DONE)
|
||||
.Const(_SC("DROP_INDEX"), SQLITE_DROP_INDEX)
|
||||
.Const(_SC("DROP_TABLE"), SQLITE_DROP_TABLE)
|
||||
.Const(_SC("DROP_TEMP_INDEX"), SQLITE_DROP_TEMP_INDEX)
|
||||
.Const(_SC("DROP_TEMP_TABLE"), SQLITE_DROP_TEMP_TABLE)
|
||||
.Const(_SC("DROP_TEMP_TRIGGER"), SQLITE_DROP_TEMP_TRIGGER)
|
||||
.Const(_SC("DROP_TEMP_VIEW"), SQLITE_DROP_TEMP_VIEW)
|
||||
.Const(_SC("DROP_TRIGGER"), SQLITE_DROP_TRIGGER)
|
||||
.Const(_SC("DROP_VIEW"), SQLITE_DROP_VIEW)
|
||||
.Const(_SC("DROP_VTABLE"), SQLITE_DROP_VTABLE)
|
||||
.Const(_SC("EMPTY"), SQLITE_EMPTY)
|
||||
.Const(_SC("ERROR"), SQLITE_ERROR)
|
||||
.Const(_SC("FAIL"), SQLITE_FAIL)
|
||||
.Const(_SC("FCNTL_BUSYHANDLER"), SQLITE_FCNTL_BUSYHANDLER)
|
||||
.Const(_SC("FCNTL_CHUNK_SIZE"), SQLITE_FCNTL_CHUNK_SIZE)
|
||||
.Const(_SC("FCNTL_COMMIT_PHASETWO"), SQLITE_FCNTL_COMMIT_PHASETWO)
|
||||
.Const(_SC("FCNTL_FILE_POINTER"), SQLITE_FCNTL_FILE_POINTER)
|
||||
.Const(_SC("FCNTL_GET_LOCKPROXYFILE"), SQLITE_FCNTL_GET_LOCKPROXYFILE)
|
||||
.Const(_SC("FCNTL_HAS_MOVED"), SQLITE_FCNTL_HAS_MOVED)
|
||||
.Const(_SC("FCNTL_LAST_ERRNO"), SQLITE_FCNTL_LAST_ERRNO)
|
||||
.Const(_SC("FCNTL_LOCKSTATE"), SQLITE_FCNTL_LOCKSTATE)
|
||||
.Const(_SC("FCNTL_MMAP_SIZE"), SQLITE_FCNTL_MMAP_SIZE)
|
||||
.Const(_SC("FCNTL_OVERWRITE"), SQLITE_FCNTL_OVERWRITE)
|
||||
.Const(_SC("FCNTL_PERSIST_WAL"), SQLITE_FCNTL_PERSIST_WAL)
|
||||
.Const(_SC("FCNTL_POWERSAFE_OVERWRITE"), SQLITE_FCNTL_POWERSAFE_OVERWRITE)
|
||||
.Const(_SC("FCNTL_PRAGMA"), SQLITE_FCNTL_PRAGMA)
|
||||
.Const(_SC("FCNTL_RBU"), SQLITE_FCNTL_RBU)
|
||||
.Const(_SC("FCNTL_SET_LOCKPROXYFILE"), SQLITE_FCNTL_SET_LOCKPROXYFILE)
|
||||
.Const(_SC("FCNTL_SIZE_HINT"), SQLITE_FCNTL_SIZE_HINT)
|
||||
.Const(_SC("FCNTL_SYNC"), SQLITE_FCNTL_SYNC)
|
||||
.Const(_SC("FCNTL_SYNC_OMITTED"), SQLITE_FCNTL_SYNC_OMITTED)
|
||||
.Const(_SC("FCNTL_TEMPFILENAME"), SQLITE_FCNTL_TEMPFILENAME)
|
||||
.Const(_SC("FCNTL_TRACE"), SQLITE_FCNTL_TRACE)
|
||||
.Const(_SC("FCNTL_VFSNAME"), SQLITE_FCNTL_VFSNAME)
|
||||
.Const(_SC("FCNTL_WAL_BLOCK"), SQLITE_FCNTL_WAL_BLOCK)
|
||||
.Const(_SC("FCNTL_WIN32_AV_RETRY"), SQLITE_FCNTL_WIN32_AV_RETRY)
|
||||
.Const(_SC("FCNTL_WIN32_SET_HANDLE"), SQLITE_FCNTL_WIN32_SET_HANDLE)
|
||||
.Const(_SC("FCNTL_ZIPVFS"), SQLITE_FCNTL_ZIPVFS)
|
||||
.Const(_SC("FLOAT"), SQLITE_FLOAT)
|
||||
.Const(_SC("FORMAT"), SQLITE_FORMAT)
|
||||
.Const(_SC("FULL"), SQLITE_FULL)
|
||||
.Const(_SC("FUNCTION"), SQLITE_FUNCTION)
|
||||
.Const(_SC("IGNORE"), SQLITE_IGNORE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_EQ"), SQLITE_INDEX_CONSTRAINT_EQ)
|
||||
.Const(_SC("INDEX_CONSTRAINT_GE"), SQLITE_INDEX_CONSTRAINT_GE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_GT"), SQLITE_INDEX_CONSTRAINT_GT)
|
||||
.Const(_SC("INDEX_CONSTRAINT_LE"), SQLITE_INDEX_CONSTRAINT_LE)
|
||||
.Const(_SC("INDEX_CONSTRAINT_LT"), SQLITE_INDEX_CONSTRAINT_LT)
|
||||
.Const(_SC("INDEX_CONSTRAINT_MATCH"), SQLITE_INDEX_CONSTRAINT_MATCH)
|
||||
.Const(_SC("INDEX_SCAN_UNIQUE"), SQLITE_INDEX_SCAN_UNIQUE)
|
||||
.Const(_SC("INSERT"), SQLITE_INSERT)
|
||||
.Const(_SC("INTEGER"), SQLITE_INTEGER)
|
||||
.Const(_SC("INTERNAL"), SQLITE_INTERNAL)
|
||||
.Const(_SC("INTERRUPT"), SQLITE_INTERRUPT)
|
||||
.Const(_SC("IOCAP_ATOMIC"), SQLITE_IOCAP_ATOMIC)
|
||||
.Const(_SC("IOCAP_ATOMIC16K"), SQLITE_IOCAP_ATOMIC16K)
|
||||
.Const(_SC("IOCAP_ATOMIC1K"), SQLITE_IOCAP_ATOMIC1K)
|
||||
.Const(_SC("IOCAP_ATOMIC2K"), SQLITE_IOCAP_ATOMIC2K)
|
||||
.Const(_SC("IOCAP_ATOMIC32K"), SQLITE_IOCAP_ATOMIC32K)
|
||||
.Const(_SC("IOCAP_ATOMIC4K"), SQLITE_IOCAP_ATOMIC4K)
|
||||
.Const(_SC("IOCAP_ATOMIC512"), SQLITE_IOCAP_ATOMIC512)
|
||||
.Const(_SC("IOCAP_ATOMIC64K"), SQLITE_IOCAP_ATOMIC64K)
|
||||
.Const(_SC("IOCAP_ATOMIC8K"), SQLITE_IOCAP_ATOMIC8K)
|
||||
.Const(_SC("IOCAP_IMMUTABLE"), SQLITE_IOCAP_IMMUTABLE)
|
||||
.Const(_SC("IOCAP_POWERSAFE_OVERWRITE"), SQLITE_IOCAP_POWERSAFE_OVERWRITE)
|
||||
.Const(_SC("IOCAP_SAFE_APPEND"), SQLITE_IOCAP_SAFE_APPEND)
|
||||
.Const(_SC("IOCAP_SEQUENTIAL"), SQLITE_IOCAP_SEQUENTIAL)
|
||||
.Const(_SC("IOCAP_UNDELETABLE_WHEN_OPEN"), SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
|
||||
.Const(_SC("IOERR"), SQLITE_IOERR)
|
||||
.Const(_SC("IOERR_ACCESS"), SQLITE_IOERR_ACCESS)
|
||||
.Const(_SC("IOERR_BLOCKED"), SQLITE_IOERR_BLOCKED)
|
||||
.Const(_SC("IOERR_CHECKRESERVEDLOCK"), SQLITE_IOERR_CHECKRESERVEDLOCK)
|
||||
.Const(_SC("IOERR_CLOSE"), SQLITE_IOERR_CLOSE)
|
||||
.Const(_SC("IOERR_CONVPATH"), SQLITE_IOERR_CONVPATH)
|
||||
.Const(_SC("IOERR_DELETE"), SQLITE_IOERR_DELETE)
|
||||
.Const(_SC("IOERR_DELETE_NOENT"), SQLITE_IOERR_DELETE_NOENT)
|
||||
.Const(_SC("IOERR_DIR_CLOSE"), SQLITE_IOERR_DIR_CLOSE)
|
||||
.Const(_SC("IOERR_DIR_FSYNC"), SQLITE_IOERR_DIR_FSYNC)
|
||||
.Const(_SC("IOERR_FSTAT"), SQLITE_IOERR_FSTAT)
|
||||
.Const(_SC("IOERR_FSYNC"), SQLITE_IOERR_FSYNC)
|
||||
.Const(_SC("IOERR_GETTEMPPATH"), SQLITE_IOERR_GETTEMPPATH)
|
||||
.Const(_SC("IOERR_LOCK"), SQLITE_IOERR_LOCK)
|
||||
.Const(_SC("IOERR_MMAP"), SQLITE_IOERR_MMAP)
|
||||
.Const(_SC("IOERR_NOMEM"), SQLITE_IOERR_NOMEM)
|
||||
.Const(_SC("IOERR_RDLOCK"), SQLITE_IOERR_RDLOCK)
|
||||
.Const(_SC("IOERR_READ"), SQLITE_IOERR_READ)
|
||||
.Const(_SC("IOERR_SEEK"), SQLITE_IOERR_SEEK)
|
||||
.Const(_SC("IOERR_SHMLOCK"), SQLITE_IOERR_SHMLOCK)
|
||||
.Const(_SC("IOERR_SHMMAP"), SQLITE_IOERR_SHMMAP)
|
||||
.Const(_SC("IOERR_SHMOPEN"), SQLITE_IOERR_SHMOPEN)
|
||||
.Const(_SC("IOERR_SHMSIZE"), SQLITE_IOERR_SHMSIZE)
|
||||
.Const(_SC("IOERR_SHORT_READ"), SQLITE_IOERR_SHORT_READ)
|
||||
.Const(_SC("IOERR_TRUNCATE"), SQLITE_IOERR_TRUNCATE)
|
||||
.Const(_SC("IOERR_UNLOCK"), SQLITE_IOERR_UNLOCK)
|
||||
.Const(_SC("IOERR_VNODE"), SQLITE_IOERR_VNODE)
|
||||
.Const(_SC("IOERR_WRITE"), SQLITE_IOERR_WRITE)
|
||||
.Const(_SC("LIMIT_ATTACHED"), SQLITE_LIMIT_ATTACHED)
|
||||
.Const(_SC("LIMIT_COLUMN"), SQLITE_LIMIT_COLUMN)
|
||||
.Const(_SC("LIMIT_COMPOUND_SELECT"), SQLITE_LIMIT_COMPOUND_SELECT)
|
||||
.Const(_SC("LIMIT_EXPR_DEPTH"), SQLITE_LIMIT_EXPR_DEPTH)
|
||||
.Const(_SC("LIMIT_FUNCTION_ARG"), SQLITE_LIMIT_FUNCTION_ARG)
|
||||
.Const(_SC("LIMIT_LENGTH"), SQLITE_LIMIT_LENGTH)
|
||||
.Const(_SC("LIMIT_LIKE_PATTERN_LENGTH"), SQLITE_LIMIT_LIKE_PATTERN_LENGTH)
|
||||
.Const(_SC("LIMIT_SQL_LENGTH"), SQLITE_LIMIT_SQL_LENGTH)
|
||||
.Const(_SC("LIMIT_TRIGGER_DEPTH"), SQLITE_LIMIT_TRIGGER_DEPTH)
|
||||
.Const(_SC("LIMIT_VARIABLE_NUMBER"), SQLITE_LIMIT_VARIABLE_NUMBER)
|
||||
.Const(_SC("LIMIT_VDBE_OP"), SQLITE_LIMIT_VDBE_OP)
|
||||
.Const(_SC("LIMIT_WORKER_THREADS"), SQLITE_LIMIT_WORKER_THREADS)
|
||||
.Const(_SC("LOCKED"), SQLITE_LOCKED)
|
||||
.Const(_SC("LOCKED_SHAREDCACHE"), SQLITE_LOCKED_SHAREDCACHE)
|
||||
.Const(_SC("LOCK_EXCLUSIVE"), SQLITE_LOCK_EXCLUSIVE)
|
||||
.Const(_SC("LOCK_NONE"), SQLITE_LOCK_NONE)
|
||||
.Const(_SC("LOCK_PENDING"), SQLITE_LOCK_PENDING)
|
||||
.Const(_SC("LOCK_RESERVED"), SQLITE_LOCK_RESERVED)
|
||||
.Const(_SC("LOCK_SHARED"), SQLITE_LOCK_SHARED)
|
||||
.Const(_SC("MISMATCH"), SQLITE_MISMATCH)
|
||||
.Const(_SC("MISUSE"), SQLITE_MISUSE)
|
||||
.Const(_SC("MUTEX_FAST"), SQLITE_MUTEX_FAST)
|
||||
.Const(_SC("MUTEX_RECURSIVE"), SQLITE_MUTEX_RECURSIVE)
|
||||
.Const(_SC("MUTEX_STATIC_APP1"), SQLITE_MUTEX_STATIC_APP1)
|
||||
.Const(_SC("MUTEX_STATIC_APP2"), SQLITE_MUTEX_STATIC_APP2)
|
||||
.Const(_SC("MUTEX_STATIC_APP3"), SQLITE_MUTEX_STATIC_APP3)
|
||||
.Const(_SC("MUTEX_STATIC_LRU"), SQLITE_MUTEX_STATIC_LRU)
|
||||
.Const(_SC("MUTEX_STATIC_LRU2"), SQLITE_MUTEX_STATIC_LRU2)
|
||||
.Const(_SC("MUTEX_STATIC_MASTER"), SQLITE_MUTEX_STATIC_MASTER)
|
||||
.Const(_SC("MUTEX_STATIC_MEM"), SQLITE_MUTEX_STATIC_MEM)
|
||||
.Const(_SC("MUTEX_STATIC_MEM2"), SQLITE_MUTEX_STATIC_MEM2)
|
||||
.Const(_SC("MUTEX_STATIC_OPEN"), SQLITE_MUTEX_STATIC_OPEN)
|
||||
.Const(_SC("MUTEX_STATIC_PMEM"), SQLITE_MUTEX_STATIC_PMEM)
|
||||
.Const(_SC("MUTEX_STATIC_PRNG"), SQLITE_MUTEX_STATIC_PRNG)
|
||||
.Const(_SC("MUTEX_STATIC_VFS1"), SQLITE_MUTEX_STATIC_VFS1)
|
||||
.Const(_SC("MUTEX_STATIC_VFS2"), SQLITE_MUTEX_STATIC_VFS2)
|
||||
.Const(_SC("MUTEX_STATIC_VFS3"), SQLITE_MUTEX_STATIC_VFS3)
|
||||
.Const(_SC("NOLFS"), SQLITE_NOLFS)
|
||||
.Const(_SC("NOMEM"), SQLITE_NOMEM)
|
||||
.Const(_SC("NOTADB"), SQLITE_NOTADB)
|
||||
.Const(_SC("NOTFOUND"), SQLITE_NOTFOUND)
|
||||
.Const(_SC("NOTICE"), SQLITE_NOTICE)
|
||||
.Const(_SC("NOTICE_RECOVER_ROLLBACK"), SQLITE_NOTICE_RECOVER_ROLLBACK)
|
||||
.Const(_SC("NOTICE_RECOVER_WAL"), SQLITE_NOTICE_RECOVER_WAL)
|
||||
.Const(_SC("NULL"), SQLITE_NULL)
|
||||
.Const(_SC("OK"), SQLITE_OK)
|
||||
.Const(_SC("OPEN_AUTOPROXY"), SQLITE_OPEN_AUTOPROXY)
|
||||
.Const(_SC("OPEN_CREATE"), SQLITE_OPEN_CREATE)
|
||||
.Const(_SC("OPEN_DELETEONCLOSE"), SQLITE_OPEN_DELETEONCLOSE)
|
||||
.Const(_SC("OPEN_EXCLUSIVE"), SQLITE_OPEN_EXCLUSIVE)
|
||||
.Const(_SC("OPEN_FULLMUTEX"), SQLITE_OPEN_FULLMUTEX)
|
||||
.Const(_SC("OPEN_MAIN_DB"), SQLITE_OPEN_MAIN_DB)
|
||||
.Const(_SC("OPEN_MAIN_JOURNAL"), SQLITE_OPEN_MAIN_JOURNAL)
|
||||
.Const(_SC("OPEN_MASTER_JOURNAL"), SQLITE_OPEN_MASTER_JOURNAL)
|
||||
.Const(_SC("OPEN_MEMORY"), SQLITE_OPEN_MEMORY)
|
||||
.Const(_SC("OPEN_NOMUTEX"), SQLITE_OPEN_NOMUTEX)
|
||||
.Const(_SC("OPEN_PRIVATECACHE"), SQLITE_OPEN_PRIVATECACHE)
|
||||
.Const(_SC("OPEN_READONLY"), SQLITE_OPEN_READONLY)
|
||||
.Const(_SC("OPEN_READWRITE"), SQLITE_OPEN_READWRITE)
|
||||
.Const(_SC("OPEN_SHAREDCACHE"), SQLITE_OPEN_SHAREDCACHE)
|
||||
.Const(_SC("OPEN_SUBJOURNAL"), SQLITE_OPEN_SUBJOURNAL)
|
||||
.Const(_SC("OPEN_TEMP_DB"), SQLITE_OPEN_TEMP_DB)
|
||||
.Const(_SC("OPEN_TEMP_JOURNAL"), SQLITE_OPEN_TEMP_JOURNAL)
|
||||
.Const(_SC("OPEN_TRANSIENT_DB"), SQLITE_OPEN_TRANSIENT_DB)
|
||||
.Const(_SC("OPEN_URI"), SQLITE_OPEN_URI)
|
||||
.Const(_SC("OPEN_WAL"), SQLITE_OPEN_WAL)
|
||||
.Const(_SC("PERM"), SQLITE_PERM)
|
||||
.Const(_SC("PRAGMA"), SQLITE_PRAGMA)
|
||||
.Const(_SC("PROTOCOL"), SQLITE_PROTOCOL)
|
||||
.Const(_SC("RANGE"), SQLITE_RANGE)
|
||||
.Const(_SC("READ"), SQLITE_READ)
|
||||
.Const(_SC("READONLY"), SQLITE_READONLY)
|
||||
.Const(_SC("READONLY_CANTLOCK"), SQLITE_READONLY_CANTLOCK)
|
||||
.Const(_SC("READONLY_DBMOVED"), SQLITE_READONLY_DBMOVED)
|
||||
.Const(_SC("READONLY_RECOVERY"), SQLITE_READONLY_RECOVERY)
|
||||
.Const(_SC("READONLY_ROLLBACK"), SQLITE_READONLY_ROLLBACK)
|
||||
.Const(_SC("RECURSIVE"), SQLITE_RECURSIVE)
|
||||
.Const(_SC("REINDEX"), SQLITE_REINDEX)
|
||||
.Const(_SC("REPLACE"), SQLITE_REPLACE)
|
||||
.Const(_SC("ROLLBACK"), SQLITE_ROLLBACK)
|
||||
.Const(_SC("ROW"), SQLITE_ROW)
|
||||
.Const(_SC("SAVEPOINT"), SQLITE_SAVEPOINT)
|
||||
.Const(_SC("SCANSTAT_EST"), SQLITE_SCANSTAT_EST)
|
||||
.Const(_SC("SCANSTAT_EXPLAIN"), SQLITE_SCANSTAT_EXPLAIN)
|
||||
.Const(_SC("SCANSTAT_NAME"), SQLITE_SCANSTAT_NAME)
|
||||
.Const(_SC("SCANSTAT_NLOOP"), SQLITE_SCANSTAT_NLOOP)
|
||||
.Const(_SC("SCANSTAT_NVISIT"), SQLITE_SCANSTAT_NVISIT)
|
||||
.Const(_SC("SCANSTAT_SELECTID"), SQLITE_SCANSTAT_SELECTID)
|
||||
.Const(_SC("SCHEMA"), SQLITE_SCHEMA)
|
||||
.Const(_SC("SELECT"), SQLITE_SELECT)
|
||||
.Const(_SC("SHM_EXCLUSIVE"), SQLITE_SHM_EXCLUSIVE)
|
||||
.Const(_SC("SHM_LOCK"), SQLITE_SHM_LOCK)
|
||||
.Const(_SC("SHM_NLOCK"), SQLITE_SHM_NLOCK)
|
||||
.Const(_SC("SHM_SHARED"), SQLITE_SHM_SHARED)
|
||||
.Const(_SC("SHM_UNLOCK"), SQLITE_SHM_UNLOCK)
|
||||
.Const(_SC("SOURCE_ID"), SQLITE_SOURCE_ID)
|
||||
.Const(_SC("STATUS_MALLOC_COUNT"), SQLITE_STATUS_MALLOC_COUNT)
|
||||
.Const(_SC("STATUS_MALLOC_SIZE"), SQLITE_STATUS_MALLOC_SIZE)
|
||||
.Const(_SC("STATUS_MEMORY_USED"), SQLITE_STATUS_MEMORY_USED)
|
||||
.Const(_SC("STATUS_PAGECACHE_OVERFLOW"), SQLITE_STATUS_PAGECACHE_OVERFLOW)
|
||||
.Const(_SC("STATUS_PAGECACHE_SIZE"), SQLITE_STATUS_PAGECACHE_SIZE)
|
||||
.Const(_SC("STATUS_PAGECACHE_USED"), SQLITE_STATUS_PAGECACHE_USED)
|
||||
.Const(_SC("STATUS_PARSER_STACK"), SQLITE_STATUS_PARSER_STACK)
|
||||
.Const(_SC("STATUS_SCRATCH_OVERFLOW"), SQLITE_STATUS_SCRATCH_OVERFLOW)
|
||||
.Const(_SC("STATUS_SCRATCH_SIZE"), SQLITE_STATUS_SCRATCH_SIZE)
|
||||
.Const(_SC("STATUS_SCRATCH_USED"), SQLITE_STATUS_SCRATCH_USED)
|
||||
.Const(_SC("STMTSTATUS_AUTOINDEX"), SQLITE_STMTSTATUS_AUTOINDEX)
|
||||
.Const(_SC("STMTSTATUS_FULLSCAN_STEP"), SQLITE_STMTSTATUS_FULLSCAN_STEP)
|
||||
.Const(_SC("STMTSTATUS_SORT"), SQLITE_STMTSTATUS_SORT)
|
||||
.Const(_SC("STMTSTATUS_VM_STEP"), SQLITE_STMTSTATUS_VM_STEP)
|
||||
.Const(_SC("SYNC_DATAONLY"), SQLITE_SYNC_DATAONLY)
|
||||
.Const(_SC("SYNC_FULL"), SQLITE_SYNC_FULL)
|
||||
.Const(_SC("SYNC_NORMAL"), SQLITE_SYNC_NORMAL)
|
||||
.Const(_SC("TESTCTRL_ALWAYS"), SQLITE_TESTCTRL_ALWAYS)
|
||||
.Const(_SC("TESTCTRL_ASSERT"), SQLITE_TESTCTRL_ASSERT)
|
||||
.Const(_SC("TESTCTRL_BENIGN_MALLOC_HOOKS"), SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS)
|
||||
.Const(_SC("TESTCTRL_BITVEC_TEST"), SQLITE_TESTCTRL_BITVEC_TEST)
|
||||
.Const(_SC("TESTCTRL_BYTEORDER"), SQLITE_TESTCTRL_BYTEORDER)
|
||||
.Const(_SC("TESTCTRL_EXPLAIN_STMT"), SQLITE_TESTCTRL_EXPLAIN_STMT)
|
||||
.Const(_SC("TESTCTRL_FAULT_INSTALL"), SQLITE_TESTCTRL_FAULT_INSTALL)
|
||||
.Const(_SC("TESTCTRL_FIRST"), SQLITE_TESTCTRL_FIRST)
|
||||
.Const(_SC("TESTCTRL_IMPOSTER"), SQLITE_TESTCTRL_IMPOSTER)
|
||||
.Const(_SC("TESTCTRL_ISINIT"), SQLITE_TESTCTRL_ISINIT)
|
||||
.Const(_SC("TESTCTRL_ISKEYWORD"), SQLITE_TESTCTRL_ISKEYWORD)
|
||||
.Const(_SC("TESTCTRL_LAST"), SQLITE_TESTCTRL_LAST)
|
||||
.Const(_SC("TESTCTRL_LOCALTIME_FAULT"), SQLITE_TESTCTRL_LOCALTIME_FAULT)
|
||||
.Const(_SC("TESTCTRL_NEVER_CORRUPT"), SQLITE_TESTCTRL_NEVER_CORRUPT)
|
||||
.Const(_SC("TESTCTRL_OPTIMIZATIONS"), SQLITE_TESTCTRL_OPTIMIZATIONS)
|
||||
.Const(_SC("TESTCTRL_PENDING_BYTE"), SQLITE_TESTCTRL_PENDING_BYTE)
|
||||
.Const(_SC("TESTCTRL_PRNG_RESET"), SQLITE_TESTCTRL_PRNG_RESET)
|
||||
.Const(_SC("TESTCTRL_PRNG_RESTORE"), SQLITE_TESTCTRL_PRNG_RESTORE)
|
||||
.Const(_SC("TESTCTRL_PRNG_SAVE"), SQLITE_TESTCTRL_PRNG_SAVE)
|
||||
.Const(_SC("TESTCTRL_RESERVE"), SQLITE_TESTCTRL_RESERVE)
|
||||
.Const(_SC("TESTCTRL_SCRATCHMALLOC"), SQLITE_TESTCTRL_SCRATCHMALLOC)
|
||||
.Const(_SC("TESTCTRL_SORTER_MMAP"), SQLITE_TESTCTRL_SORTER_MMAP)
|
||||
.Const(_SC("TESTCTRL_VDBE_COVERAGE"), SQLITE_TESTCTRL_VDBE_COVERAGE)
|
||||
.Const(_SC("TEXT"), SQLITE_TEXT)
|
||||
.Const(_SC("TOOBIG"), SQLITE_TOOBIG)
|
||||
.Const(_SC("TRANSACTION"), SQLITE_TRANSACTION)
|
||||
.Const(_SC("UPDATE"), SQLITE_UPDATE)
|
||||
.Const(_SC("UTF16"), SQLITE_UTF16)
|
||||
.Const(_SC("UTF16BE"), SQLITE_UTF16BE)
|
||||
.Const(_SC("UTF16LE"), SQLITE_UTF16LE)
|
||||
.Const(_SC("UTF16_ALIGNED"), SQLITE_UTF16_ALIGNED)
|
||||
.Const(_SC("UTF8"), SQLITE_UTF8)
|
||||
.Const(_SC("VERSION"), SQLITE_VERSION)
|
||||
.Const(_SC("VERSION_NUMBER"), SQLITE_VERSION_NUMBER)
|
||||
.Const(_SC("VTAB_CONSTRAINT_SUPPORT"), SQLITE_VTAB_CONSTRAINT_SUPPORT)
|
||||
.Const(_SC("WARNING"), SQLITE_WARNING)
|
||||
.Const(_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX)
|
||||
);
|
||||
*/
|
||||
// Output debugging information
|
||||
LogDbg("Registration of <SQLite Constants> type was successful");
|
||||
// Registration succeeded
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
415
source/Library/SQLite/Shared.hpp
Normal file
415
source/Library/SQLite/Shared.hpp
Normal file
@ -0,0 +1,415 @@
|
||||
#ifndef _LIBRARY_SQLITE_SHARED_HPP_
|
||||
#define _LIBRARY_SQLITE_SHARED_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Common.hpp"
|
||||
#include "Library/LongInt.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqlite3.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <queue>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class Connection;
|
||||
class Statement;
|
||||
class Result;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* A managed handle to a shared SQLite connection.
|
||||
*/
|
||||
class ConnectionHandle
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
friend class Connection;
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Helper class responsible for managing the handle to an SQLite connection resource.
|
||||
*/
|
||||
struct Handle
|
||||
{
|
||||
friend class ConnectionHandle;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The type of container used to queue queries for group execution.
|
||||
*/
|
||||
typedef std::queue< String > QueryList;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The amount of references to this handle instance.
|
||||
*/
|
||||
mutable SQUint32 Ref;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The handle to the managed SQLite connection resource.
|
||||
*/
|
||||
sqlite3* Ptr;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The flags used to create the SQLite connection handle.
|
||||
*/
|
||||
SQInt32 Flags;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The specified path to be used as the database file.
|
||||
*/
|
||||
String Path;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The specified virtual file system.
|
||||
*/
|
||||
String VFS;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The last status code of this connection handle.
|
||||
*/
|
||||
SQInt32 Status;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* A queue of queries to be executed in groups in order to reduce lag.
|
||||
*/
|
||||
QueryList Queue;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The global tag associated with this resource.
|
||||
*/
|
||||
SqTag Tag;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* The global data associated with this resource.
|
||||
*/
|
||||
SqObj Data;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether the database exists in memory and not disk.
|
||||
*/
|
||||
bool Memory;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether tracing was activated on the database.
|
||||
*/
|
||||
bool Trace;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Whether profiling was activated on the database.
|
||||
*/
|
||||
bool Profile;
|
||||
|
||||
private:
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Handle constructor.
|
||||
*/
|
||||
Handle(const String & path, SQInt32 flags, const String & vfs)
|
||||
: Ref(1), Ptr(NULL), Flags(flags), Path(path), VFS(vfs)
|
||||
, Status(SQLITE_OK), Queue(), Tag(), Data()
|
||||
, Memory(path == ":memory:"), Trace(false), Profile(false)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled)
|
||||
*/
|
||||
Handle(const Handle &) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled)
|
||||
*/
|
||||
Handle(Handle &&) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Handle destructor.
|
||||
*/
|
||||
~Handle()
|
||||
{
|
||||
// If a valid handle exists then attempt to release it
|
||||
if (Ptr != NULL && (Status = sqlite3_close(Ptr)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to <close database connection> because : %s", sqlite3_errmsg(Ptr));
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled)
|
||||
*/
|
||||
Handle & operator = (const Handle &) = delete;
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
* Move assignment operator (disabled)
|
||||
*/
|
||||
Handle & operator = (Handle &&) = delete;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Acquire a strong reference to the resource handle.
|
||||
*/
|
||||
void Grab()
|
||||
{
|
||||
// If a valid handle exists then grab a reference to it
|
||||
if (Hnd != nullptr)
|
||||
{
|
||||
++(Hnd->Ref);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release the handle reference and therefore the handle it self if no more references exist.
|
||||
*/
|
||||
void Drop()
|
||||
{
|
||||
// If a valid handle exists then delete it if this is the last released reference
|
||||
if (Hnd != nullptr && --(Hnd->Ref) == 0)
|
||||
{
|
||||
delete Hnd;
|
||||
}
|
||||
// Explicitly make sure the handle is null
|
||||
Hnd = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The handle instance that manages the SQLite resource.
|
||||
*/
|
||||
Handle * Hnd;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Open a connection to a database using the specified path, flags and vfs.
|
||||
*/
|
||||
ConnectionHandle(const SQChar * path, SQInt32 flags, const SQChar * vfs);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
ConnectionHandle(const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
ConnectionHandle(ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~ConnectionHandle();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
ConnectionHandle & operator = (const ConnectionHandle & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
ConnectionHandle & operator = (ConnectionHandle && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return (Hnd != nullptr) && (Hnd->Ptr != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Negation operator.
|
||||
*/
|
||||
operator ! () const
|
||||
{
|
||||
return (Hnd == nullptr) || (Hnd->Ptr == NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Ptr : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to integer status code.
|
||||
*/
|
||||
operator SQInt32 () const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Status : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Member of pointer operator.
|
||||
*/
|
||||
Handle * operator -> () const
|
||||
{
|
||||
return Hnd;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Indirection operator.
|
||||
*/
|
||||
Handle & operator * () const
|
||||
{
|
||||
return *Hnd;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const ConnectionHandle & o) const
|
||||
{
|
||||
return (Hnd == o.Hnd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const ConnectionHandle & o) const
|
||||
{
|
||||
return (Hnd != o.Hnd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Reset this handle and release the internal reference.
|
||||
*/
|
||||
void Release()
|
||||
{
|
||||
Drop();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of active references to this handle.
|
||||
*/
|
||||
SQUint32 Count() const
|
||||
{
|
||||
return (Hnd != nullptr) ? Hnd->Ref : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error message associated with the value in status.
|
||||
*/
|
||||
const SQChar * ErrStr() const
|
||||
{
|
||||
return sqlite3_errstr(Hnd->Status);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error message associated with the connection.
|
||||
*/
|
||||
const SQChar * ErrMsg() const
|
||||
{
|
||||
return sqlite3_errmsg(Hnd->Ptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the error code associated with the connection.
|
||||
*/
|
||||
SQInt32 ErrNo() const
|
||||
{
|
||||
return sqlite3_errcode(Hnd->Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII encapsulation of a SQLite Transaction.
|
||||
*/
|
||||
class Transaction
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Transaction(const Connection & db);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
Transaction(const Transaction & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled).
|
||||
*/
|
||||
Transaction(Transaction && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Transaction();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
Transaction & operator = (const Transaction & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator (disabled).
|
||||
*/
|
||||
Transaction & operator = (Transaction && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Commit the transaction.
|
||||
*/
|
||||
void Commit();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the transaction was committed.
|
||||
*/
|
||||
bool Commited() const
|
||||
{
|
||||
return m_Commited;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The SQLite connection associated with this transaction.
|
||||
*/
|
||||
ConnectionHandle m_Connection;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the changes were committed.
|
||||
*/
|
||||
bool m_Commited;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Places a "soft" limit on the amount of heap memory that may be allocated by SQLite.
|
||||
*/
|
||||
void SetSoftHeapLimit(SQInt32 limit);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempts to free N bytes of heap memory by deallocating non-essential memory allocations
|
||||
* held by the database library.
|
||||
*/
|
||||
SQInt32 ReleaseMemory(SQInt32 bytes);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Returns the number of bytes of memory currently outstanding (malloced but not freed).
|
||||
*/
|
||||
SLongInt GetMemoryUsage();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Returns the maximum value of used bytes since the high-water mark was last reset.
|
||||
*/
|
||||
SLongInt GetMemoryHighwaterMark(bool reset);
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_SHARED_HPP_
|
File diff suppressed because it is too large
Load Diff
@ -1,60 +1,433 @@
|
||||
#ifndef _LIBRARY_SQLITE_STATEMENT_HPP_
|
||||
#define _LIBRARY_SQLITE_STATEMENT_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/SQLite/Shared.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <unordered_map>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Class used to manage a connection to an SQLite statement.
|
||||
*/
|
||||
class Statement
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Default constructor (invalid).
|
||||
*/
|
||||
Statement();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Create a statement on the specified connection and use the specified query.
|
||||
*/
|
||||
Statement(const Statement & o);
|
||||
Statement(const Connection & db, const SQChar * query);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Copy constructor.
|
||||
*/
|
||||
Statement(Statement && o);
|
||||
Statement(const Statement &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Move constructor.
|
||||
*/
|
||||
Statement(Statement &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~Statement();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
Statement & operator = (const Statement & o);
|
||||
Statement & operator = (const Statement &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Statement & operator = (Statement &&) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite statement handle.
|
||||
*/
|
||||
operator sqlite3_stmt * () const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to a raw SQLite connection handle.
|
||||
*/
|
||||
operator sqlite3 * () const
|
||||
{
|
||||
return static_cast< sqlite3 * >(m_Connection);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to boolean.
|
||||
*/
|
||||
operator bool () const
|
||||
{
|
||||
return (m_Handle != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Negation operator.
|
||||
*/
|
||||
operator ! () const
|
||||
{
|
||||
return (m_Handle == NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality operator.
|
||||
*/
|
||||
bool operator == (const Statement & o) const
|
||||
{
|
||||
return (m_Handle == o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Inequality operator.
|
||||
*/
|
||||
bool operator != (const Statement & o) const
|
||||
{
|
||||
return (m_Handle != o.m_Handle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script to compare two instances of this type.
|
||||
*/
|
||||
SQInt32 Cmp(const Statement & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Convert this type to a string.
|
||||
*/
|
||||
const SQChar * ToString() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local tag.
|
||||
*/
|
||||
const SQChar * GetLocalTag() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local tag.
|
||||
*/
|
||||
void SetLocalTag(const SQChar * tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the local data.
|
||||
*/
|
||||
SqObj & GetLocalData();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the local data.
|
||||
*/
|
||||
void SetLocalData(SqObj & data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Statement & operator = (Statement && o);
|
||||
bool IsValid()
|
||||
{
|
||||
return (m_Handle != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetStatus() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetColumns() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetQuery() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetErrStr() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetErrMsg() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Connection GetConnection() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool GetGood() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool GetDone() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return the extended numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQInt32 GetExtendedErrorCode() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 Exec();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool Step();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindA(const Array & arr);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindT(const Table & tbl);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindI(SQInt32 idx, SQInt32 value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindL(SQInt32 idx, const SLongInt & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindV(SQInt32 idx, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindF(SQInt32 idx, SQFloat value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindS(SQInt32 idx, const SQChar * value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindB(SQInt32 idx, bool value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBindN(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindT(const Table & tbl);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindI(const SQChar * name, SQInt32 value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindL(const SQChar * name, const SLongInt & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindV(const SQChar * name, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindF(const SQChar * name, SQFloat value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindS(const SQChar * name, const SQChar * value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindB(const SQChar * name, bool value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBindN(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void IndexBind(SQInt32 idx, SqObj & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
void NameBind(const SQChar * name, SqObj & value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SqObj FetchColumnIndex(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SqObj FetchColumnName(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Array FetchArray();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Table FetchTable();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool CheckIndex(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
bool IsColumnNull(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInt32 GetColumnIndex(const SQChar * name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetColumnName(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
const SQChar * GetColumnOriginName(SQInt32 idx);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger GetColumnType(SQInt32 idx) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
SQInteger GetColumnBytes(SQInt32 idx) const;
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
typedef std::unordered_map< String, SQInt32 > ColumnIndex;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
template < typename... Args > void Status(const SQChar * msg, Args&&... args) const
|
||||
{
|
||||
if (m_Status != SQLITE_OK)
|
||||
{
|
||||
LogErr(msg, std::forward< Args >(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The handle to the managed SQLite statement resource.
|
||||
*/
|
||||
sqlite3_stmt* m_Handle;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The SQLite connection associated with this statement.
|
||||
*/
|
||||
ConnectionHandle m_Connection;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The query string used to create this statement.
|
||||
*/
|
||||
String m_Query;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The last status code of this connection handle.
|
||||
*/
|
||||
SQInt32 m_Status;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The amount of columns available in this statement.
|
||||
*/
|
||||
SQInt32 m_Columns;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when a row has been fetched with step.
|
||||
*/
|
||||
ColumnIndex m_ColIdx;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when a row has been fetched with step.
|
||||
*/
|
||||
bool m_Good;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* True when the last step had no more rows to fetch.
|
||||
*/
|
||||
bool m_Done;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local tag associated with this instance.
|
||||
*/
|
||||
SqTag m_Tag;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The local data associated with this instance.
|
||||
*/
|
||||
SqObj m_Data;
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
|
@ -1,63 +0,0 @@
|
||||
#ifndef _LIBRARY_SQLITE_TRANSACTION_HPP_
|
||||
#define _LIBRARY_SQLITE_TRANSACTION_HPP_
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
namespace SQLite {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
class Transaction
|
||||
{
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Transaction();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Transaction(const Transaction & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Transaction(Transaction && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
~Transaction();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Transaction & operator = (const Transaction & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
Transaction & operator = (Transaction && o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ...
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SQLite
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _LIBRARY_SQLITE_TRANSACTION_HPP_
|
@ -50,6 +50,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
_Log->cFtl(!Register_LongInt(vm), "Unable to register: LongInt") || \
|
||||
_Log->cFtl(!Register_Math(vm), "Unable to register: Math") || \
|
||||
_Log->cFtl(!Register_Numeric(vm), "Unable to register: Numeric") || \
|
||||
_Log->cFtl(!Register_SQLite(vm), "Unable to register: SQLite") || \
|
||||
_Log->cFtl(!Register_String(vm), "Unable to register: String") || \
|
||||
_Log->cFtl(!Register_SysPath(vm), "Unable to register: SysPath") || \
|
||||
_Log->cFtl(!Register_System(vm), "Unable to register: System") || \
|
||||
|
@ -51,6 +51,7 @@ bool Register_JSON(HSQUIRRELVM vm);
|
||||
bool Register_LongInt(HSQUIRRELVM vm);
|
||||
bool Register_Math(HSQUIRRELVM vm);
|
||||
bool Register_Numeric(HSQUIRRELVM vm);
|
||||
bool Register_SQLite(HSQUIRRELVM vm);
|
||||
bool Register_String(HSQUIRRELVM vm);
|
||||
bool Register_SysPath(HSQUIRRELVM vm);
|
||||
bool Register_System(HSQUIRRELVM vm);
|
||||
|
Loading…
Reference in New Issue
Block a user