mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Updated the SQLite module to include the location for C++ exceptions in source code for debug builds.
This commit is contained in:
parent
933f96fbc5
commit
1398e5a93d
@ -23,10 +23,10 @@ void Column::Validate() const
|
||||
{
|
||||
// Are we pointing to a valid index?
|
||||
if (m_Index < 0)
|
||||
SqThrowF("Invalid column index");
|
||||
STHROWF("Invalid column index");
|
||||
// Do we belong to a valid statement?
|
||||
else if (!m_Stmt)
|
||||
SqThrowF("Invalid SQLite statement reference");
|
||||
STHROWF("Invalid SQLite statement reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -34,13 +34,13 @@ void Column::ValidateRow() const
|
||||
{
|
||||
// Are we pointing to a valid index?
|
||||
if (m_Index < 0)
|
||||
SqThrowF("Invalid column index");
|
||||
STHROWF("Invalid column index");
|
||||
// Do we belong to a valid statement?
|
||||
else if (!m_Stmt)
|
||||
SqThrowF("Invalid SQLite statement reference");
|
||||
STHROWF("Invalid SQLite statement reference");
|
||||
// Do we have any rows available?
|
||||
else if (!m_Stmt->mGood)
|
||||
SqThrowF("No row available");
|
||||
STHROWF("No row available");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -143,7 +143,7 @@ Object Column::GetBlob() const
|
||||
const void * b = sqlite3_column_blob(m_Stmt, m_Index);
|
||||
// Could the memory blob be allocated?
|
||||
if (!p)
|
||||
SqThrowF("Unable to allocate space for column blob value");
|
||||
STHROWF("Unable to allocate space for column blob value");
|
||||
// Is there any data to read?
|
||||
else if (!b)
|
||||
{
|
||||
@ -195,7 +195,7 @@ CSStr Column::GetOriginName() const
|
||||
// Return the requested information
|
||||
return sqlite3_column_origin_name(m_Stmt, m_Index);
|
||||
#else
|
||||
SqThrowF("The module was compiled without this feature");
|
||||
STHROWF("The module was compiled without this feature");
|
||||
#endif
|
||||
// Request failed
|
||||
return _SC("");
|
||||
|
@ -131,10 +131,10 @@ void ConnHnd::Handle::Create(CSStr name, Int32 flags, CSStr vfs)
|
||||
{
|
||||
// Make sure a previous connection doesn't exist
|
||||
if (mPtr)
|
||||
SqThrowF("Unable to connect to database. Database already connected");
|
||||
STHROWF("Unable to connect to database. Database already connected");
|
||||
// Make sure the name is valid
|
||||
else if (!name || strlen(name) <= 0)
|
||||
SqThrowF("Unable to connect to database. The name is invalid");
|
||||
STHROWF("Unable to connect to database. The name is invalid");
|
||||
// Attempt to create the database connection
|
||||
else if ((mStatus = sqlite3_open_v2(name, &mPtr, flags, vfs)) != SQLITE_OK)
|
||||
{
|
||||
@ -143,7 +143,7 @@ void ConnHnd::Handle::Create(CSStr name, Int32 flags, CSStr vfs)
|
||||
// Explicitly make sure it's null
|
||||
mPtr = NULL;
|
||||
// Now its safe to throw the error
|
||||
SqThrowF("Unable to connect to database [%s]", sqlite3_errstr(mStatus));
|
||||
STHROWF("Unable to connect to database [%s]", sqlite3_errstr(mStatus));
|
||||
}
|
||||
// Let's save the specified information
|
||||
mName.assign(name);
|
||||
@ -179,7 +179,7 @@ Int32 ConnHnd::Handle::Flush(Uint32 num, Object & env, Function & func)
|
||||
// Attempt to begin the flush transaction
|
||||
if ((mStatus = sqlite3_exec(mPtr, "BEGIN", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
SqThrowF("Unable to begin flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
STHROWF("Unable to begin flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
}
|
||||
// Process all queries within range of selection
|
||||
for (; itr != end; ++itr)
|
||||
@ -233,12 +233,12 @@ Int32 ConnHnd::Handle::Flush(Uint32 num, Object & env, Function & func)
|
||||
// Attempt to roll back erroneous changes
|
||||
else if ((mStatus = sqlite3_exec(mPtr, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
SqThrowF("Unable to rollback flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
STHROWF("Unable to rollback flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
}
|
||||
// The transaction failed somehow but we managed to rollback
|
||||
else
|
||||
{
|
||||
SqThrowF("Unable to commit flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
STHROWF("Unable to commit flush transaction [%s]", sqlite3_errmsg(mPtr));
|
||||
}
|
||||
// Operation failed
|
||||
return -1;
|
||||
@ -267,15 +267,15 @@ void StmtHnd::Handle::Create(CSStr query)
|
||||
{
|
||||
// Make sure a previous statement doesn't exist
|
||||
if (mPtr)
|
||||
SqThrowF("Unable to prepare statement. Statement already prepared");
|
||||
STHROWF("Unable to prepare statement. Statement already prepared");
|
||||
// Is the specified database connection is valid?
|
||||
else if (!mConn)
|
||||
SqThrowF("Unable to prepare statement. Invalid connection handle");
|
||||
STHROWF("Unable to prepare statement. Invalid connection handle");
|
||||
// Save the query string and therefore multiple strlen(...) calls
|
||||
mQuery.assign(query ? query : _SC(""));
|
||||
// Is the specified query string we just saved, valid?
|
||||
if (mQuery.empty())
|
||||
SqThrowF("Unable to prepare statement. Invalid query string");
|
||||
STHROWF("Unable to prepare statement. Invalid query string");
|
||||
// Attempt to prepare a statement with the specified query string
|
||||
else if ((mStatus = sqlite3_prepare_v2(mConn, mQuery.c_str(), (Int32)mQuery.size(),
|
||||
&mPtr, NULL)) != SQLITE_OK)
|
||||
@ -285,7 +285,7 @@ void StmtHnd::Handle::Create(CSStr query)
|
||||
// Explicitly make sure the handle is null
|
||||
mPtr = NULL;
|
||||
// Now it's safe to throw the error
|
||||
SqThrowF("Unable to prepare statement [%s]", mConn.ErrMsg());
|
||||
STHROWF("Unable to prepare statement [%s]", mConn.ErrMsg());
|
||||
}
|
||||
else
|
||||
// Obtain the number of available columns
|
||||
@ -297,7 +297,7 @@ Int32 StmtHnd::Handle::GetColumnIndex(CSStr name)
|
||||
{
|
||||
// Validate the handle
|
||||
if (!mPtr)
|
||||
SqThrowF("Invalid SQLite statement");
|
||||
STHROWF("Invalid SQLite statement");
|
||||
// Are the names cached?
|
||||
else if (mIndexes.empty())
|
||||
{
|
||||
@ -307,7 +307,7 @@ Int32 StmtHnd::Handle::GetColumnIndex(CSStr name)
|
||||
CSStr name = (CSStr)sqlite3_column_name(mPtr, i);
|
||||
// Validate the name
|
||||
if (!name)
|
||||
SqThrowF("Unable to retrieve column name for index (%d)", i);
|
||||
STHROWF("Unable to retrieve column name for index (%d)", i);
|
||||
// Save it to guarantee the same lifetime as this instance
|
||||
else
|
||||
mIndexes[name] = i;
|
||||
@ -382,7 +382,7 @@ CCStr EscapeStringEx(SQChar spec, CCStr str)
|
||||
// Validate the specified format specifier
|
||||
if (spec != 'q' && spec != 'Q' && spec != 'w' && spec != 's')
|
||||
{
|
||||
SqThrowF("Unknown format specifier: %c", spec);
|
||||
STHROWF("Unknown format specifier: %c", spec);
|
||||
// Default to empty string
|
||||
return _SC("");
|
||||
}
|
||||
@ -418,7 +418,7 @@ CCStr ArrayToQueryColumns(Array & arr)
|
||||
{
|
||||
// Is the name valid?
|
||||
if (itr->empty())
|
||||
SqThrowF("Invalid column name");
|
||||
STHROWF("Invalid column name");
|
||||
// Attempt to append the column name to the buffer
|
||||
sqlite3_snprintf(sizeof(g_Buffer) - offset, g_Buffer + offset, "[%q], ", itr->c_str());
|
||||
// Add the column name size to the offset
|
||||
@ -451,7 +451,7 @@ CCStr TableToQueryColumns(Table & tbl)
|
||||
name.assign(itr.getName());
|
||||
// Is the name valid?
|
||||
if (name.empty())
|
||||
SqThrowF("Invalid or empty column name");
|
||||
STHROWF("Invalid or empty column name");
|
||||
// Attempt to append the column name to the buffer
|
||||
sqlite3_snprintf(sizeof(g_Buffer) - offset, g_Buffer + offset, "[%q], ", name.c_str());
|
||||
// Add the column name size to the offset
|
||||
|
@ -22,7 +22,7 @@ void Connection::Validate() const
|
||||
{
|
||||
// Is the handle valid?
|
||||
if (!m_Handle)
|
||||
SqThrowF("Invalid SQLite connection reference");
|
||||
STHROWF("Invalid SQLite connection reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -63,7 +63,7 @@ Int32 Connection::Exec(CSStr str)
|
||||
Validate();
|
||||
// Attempt to execute the specified query
|
||||
if ((m_Handle = sqlite3_exec(m_Handle, str, NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to execute query [%s]", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to execute query [%s]", m_Handle.ErrMsg());
|
||||
// Return rows affected by this query
|
||||
return sqlite3_changes(m_Handle);
|
||||
}
|
||||
@ -84,7 +84,7 @@ void Connection::Queue(CSStr str)
|
||||
Validate();
|
||||
// Is there a query to commit?
|
||||
if (IsQueryEmpty(str))
|
||||
SqThrowF("No query string to queue");
|
||||
STHROWF("No query string to queue");
|
||||
// Add the specified string to the queue
|
||||
m_Handle->mQueue.push_back(str);
|
||||
}
|
||||
@ -98,7 +98,7 @@ bool Connection::IsReadOnly() const
|
||||
const int result = sqlite3_db_readonly(m_Handle, "main");
|
||||
// Verify the result
|
||||
if (result == -1)
|
||||
SqThrowF("'main' is not the name of a database on connection");
|
||||
STHROWF("'main' is not the name of a database on connection");
|
||||
// Return the requested information
|
||||
return (result != 1);
|
||||
}
|
||||
@ -143,7 +143,7 @@ void Connection::SetBusyTimeout(Int32 millis)
|
||||
Validate();
|
||||
// Apply requested timeout
|
||||
if ((m_Handle = sqlite3_busy_timeout(m_Handle, millis)) != SQLITE_OK)
|
||||
SqThrowF("Unable to set busy timeout [%s]", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to set busy timeout [%s]", m_Handle.ErrMsg());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -156,7 +156,7 @@ Int32 Connection::GetInfo(Int32 operation, bool highwater, bool reset)
|
||||
Int32 hiwtr_value;
|
||||
// Attempt to retrieve the specified information
|
||||
if ((m_Handle = sqlite3_db_status(m_Handle, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
|
||||
SqThrowF("Unable to get runtime status information", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to get runtime status information", m_Handle.ErrMsg());
|
||||
// Return the high-water value if requested
|
||||
else if (highwater)
|
||||
return hiwtr_value;
|
||||
@ -171,7 +171,7 @@ Connection Connection::CopyToMemory()
|
||||
Validate();
|
||||
// Is the database already in memory?
|
||||
if (m_Handle->mMemory)
|
||||
SqThrowF("The database is already in memory");
|
||||
STHROWF("The database is already in memory");
|
||||
// Destination database
|
||||
ConnHnd db(_SC(""));
|
||||
// Attempt to open the in-memory database
|
||||
@ -180,7 +180,7 @@ Connection Connection::CopyToMemory()
|
||||
GetTempBuff()[0] = 0;
|
||||
// Begin a transaction to replicate the schema of origin database
|
||||
if ((m_Handle = sqlite3_exec(m_Handle, "BEGIN", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to begin schema replication [%s]", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to begin schema replication [%s]", m_Handle.ErrMsg());
|
||||
// Attempt to replicate the schema of origin database to the in-memory one
|
||||
else if ((m_Handle = sqlite3_exec(m_Handle,
|
||||
"SELECT [sql] FROM [sqlite_master] WHERE [sql] NOT NULL AND [tbl_name] != 'sqlite_sequence'",
|
||||
@ -189,21 +189,21 @@ Connection Connection::CopyToMemory()
|
||||
// Did the error occurred from the DDL process function?
|
||||
if (GetTempBuff()[0] != 0)
|
||||
// Throw the resulted message but also include the point where it failed
|
||||
SqThrowF("Unable to replicate schema [%s]", GetTempBuff());
|
||||
STHROWF("Unable to replicate schema [%s]", GetTempBuff());
|
||||
// Obtain the message from the connection handle if possible
|
||||
else
|
||||
SqThrowF("Unable to replicate schema [%s]", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to replicate schema [%s]", m_Handle.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database schema replication
|
||||
else if ((m_Handle = sqlite3_exec(m_Handle, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to commit schema replication [%s]", m_Handle.ErrMsg());
|
||||
STHROWF("Unable to commit schema replication [%s]", m_Handle.ErrMsg());
|
||||
// Attempt to attach the origin database to the in-memory one
|
||||
else if ((db = sqlite3_exec(db, QFmtStr("ATTACH DATABASE '%q' as origin", m_Handle->mName.c_str()),
|
||||
NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to attach origin [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to attach origin [%s]", db.ErrMsg());
|
||||
// Begin a transaction to replicate the data of origin database
|
||||
else if ((db = sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK))
|
||||
SqThrowF("Unable to begin data replication [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to begin data replication [%s]", db.ErrMsg());
|
||||
// Attempt to replicate the data of origin database to the in-memory one
|
||||
else if ((db = sqlite3_exec(db, "SELECT [name] FROM [origin.sqlite_master] WHERE [type]='table'",
|
||||
&Connection::ProcessDMLRow, db->mPtr, NULL)) != SQLITE_OK)
|
||||
@ -212,23 +212,23 @@ Connection Connection::CopyToMemory()
|
||||
if (GetTempBuff()[0] != 0)
|
||||
{
|
||||
// Throw the resulted message but also include the point where it failed
|
||||
SqThrowF("Unable to replicate data [%s]", GetTempBuff());
|
||||
STHROWF("Unable to replicate data [%s]", GetTempBuff());
|
||||
}
|
||||
// Obtain the message from the connection handle if possible
|
||||
else
|
||||
SqThrowF("Unable to replicate data [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to replicate data [%s]", db.ErrMsg());
|
||||
}
|
||||
// Attempt to commit the changes to the database data replication
|
||||
else if ((db = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
{
|
||||
// Attempt to rollback changes from the data copy operation
|
||||
if ((db = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to rollback data replication [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to rollback data replication [%s]", db.ErrMsg());
|
||||
// Attempt to detach the disk origin from in-memory database
|
||||
else if ((db = sqlite3_exec(db, "DETACH DATABASE origin", NULL, NULL, NULL)) != SQLITE_OK)
|
||||
SqThrowF("Unable to detach origin [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to detach origin [%s]", db.ErrMsg());
|
||||
// Operation failed
|
||||
SqThrowF("Unable to commit data replication [%s]", db.ErrMsg());
|
||||
STHROWF("Unable to commit data replication [%s]", db.ErrMsg());
|
||||
}
|
||||
// At this point everything went fine and the database instance should be returned
|
||||
return Connection(db);
|
||||
@ -326,18 +326,18 @@ void Connection::TakeSnapshot(const ConnHnd & destination)
|
||||
sqlite3_backup * backup = sqlite3_backup_init(destination, "main", m_Handle, "main");
|
||||
// See if the backup structure could be created
|
||||
if (!backup)
|
||||
SqThrowF("Unable to initialize the backup structure [%s]", destination.ErrMsg());
|
||||
STHROWF("Unable to initialize the backup structure [%s]", destination.ErrMsg());
|
||||
// -1 to copy the entire source database to the destination
|
||||
if ((m_Handle = sqlite3_backup_step(backup, -1)) != SQLITE_DONE)
|
||||
{
|
||||
// Finalize the backup structure first
|
||||
sqlite3_backup_finish(backup);
|
||||
// Now it's safe to throw the error
|
||||
SqThrowF("Unable to copy source [%s]", m_Handle.ErrStr());
|
||||
STHROWF("Unable to copy source [%s]", m_Handle.ErrStr());
|
||||
}
|
||||
// Clean up resources allocated by sqlite3_backup_init()
|
||||
if ((m_Handle = sqlite3_backup_finish(backup)) != SQLITE_OK)
|
||||
SqThrowF("Unable to finalize backup [%s]", m_Handle.ErrStr());
|
||||
STHROWF("Unable to finalize backup [%s]", m_Handle.ErrStr());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -11,8 +11,10 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr Statement::s_BadParamI = "Unable to bind [%s] parameter at (%d) because [%s]";
|
||||
CSStr Statement::s_BadParamS = "Unable to bind [%s] parameter at (%s:%d) because [%s]";
|
||||
// Error message when failed to bind value to parameter index.
|
||||
#define SQMOD_BADPARAMI "Unable to bind [%s] parameter at (%d) because [%s]"
|
||||
// Error message when failed to bind value to parameter name.
|
||||
#define SQMOD_BADPARAMS "Unable to bind [%s] parameter at (%s:%d) because [%s]"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger Statement::Typename(HSQUIRRELVM vm)
|
||||
@ -28,7 +30,7 @@ void Statement::Validate() const
|
||||
// Is the handle valid?
|
||||
if (!m_Handle)
|
||||
{
|
||||
SqThrowF("Invalid SQLite statement reference");
|
||||
STHROWF("Invalid SQLite statement reference");
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,12 +40,12 @@ void Statement::ValidateIndex(Int32 idx) const
|
||||
// Is the handle valid?
|
||||
if (!m_Handle)
|
||||
{
|
||||
SqThrowF("Invalid SQLite statement reference");
|
||||
STHROWF("Invalid SQLite statement reference");
|
||||
}
|
||||
// Is the specified index in range?
|
||||
else if (!m_Handle->CheckIndex(idx))
|
||||
{
|
||||
SqThrowF("Column index is out of range: %d", idx);
|
||||
STHROWF("Column index is out of range: %d", idx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,12 +55,12 @@ void Statement::ValidateRow() const
|
||||
// Is the handle valid?
|
||||
if (!m_Handle)
|
||||
{
|
||||
SqThrowF("Invalid SQLite statement reference");
|
||||
STHROWF("Invalid SQLite statement reference");
|
||||
}
|
||||
// Do we have any rows available?
|
||||
else if (!m_Handle->mGood)
|
||||
{
|
||||
SqThrowF("No row available");
|
||||
STHROWF("No row available");
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +83,7 @@ Statement::Statement(const ConnHnd & connection, CSStr query)
|
||||
// We just failed to obtain a valid handle
|
||||
else
|
||||
{
|
||||
SqThrowF("Unable to create the statement reference");
|
||||
STHROWF("Unable to create the statement reference");
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +99,7 @@ Statement::Statement(const Connection & connection, CSStr query)
|
||||
// We just failed to obtain a valid handle
|
||||
else
|
||||
{
|
||||
SqThrowF("Unable to create the statement reference");
|
||||
STHROWF("Unable to create the statement reference");
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +125,7 @@ void Statement::Reset()
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF("Unable to reset statement [%s]", m_Handle.ErrStr());
|
||||
STHROWF("Unable to reset statement [%s]", m_Handle.ErrStr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +142,7 @@ void Statement::Clear()
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF("Unable to clear statement [%s]", m_Handle.ErrStr());
|
||||
STHROWF("Unable to clear statement [%s]", m_Handle.ErrStr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +154,7 @@ Int32 Statement::Exec()
|
||||
// Did we reset first?
|
||||
if (m_Handle->mDone)
|
||||
{
|
||||
SqThrowF("Executed without resetting first");
|
||||
STHROWF("Executed without resetting first");
|
||||
}
|
||||
// Attempt to step the statement
|
||||
m_Handle = sqlite3_step(m_Handle);
|
||||
@ -172,11 +174,11 @@ Int32 Statement::Exec()
|
||||
switch (m_Handle->mStatus)
|
||||
{
|
||||
// We don't expect any rows to be returned in this case!
|
||||
case SQLITE_ROW: SqThrowF("Results were found");
|
||||
case SQLITE_BUSY: SqThrowF("Database was busy");
|
||||
case SQLITE_ERROR: SqThrowF("Runtime error occurred");
|
||||
case SQLITE_MISUSE: SqThrowF("Statement misuse");
|
||||
default: SqThrowF("Unknown failure");
|
||||
case SQLITE_ROW: STHROWF("Results were found");
|
||||
case SQLITE_BUSY: STHROWF("Database was busy");
|
||||
case SQLITE_ERROR: STHROWF("Runtime error occurred");
|
||||
case SQLITE_MISUSE: STHROWF("Statement misuse");
|
||||
default: STHROWF("Unknown failure");
|
||||
}
|
||||
// Operation failed (shouldn't reach this point!)
|
||||
return -1;
|
||||
@ -190,7 +192,7 @@ bool Statement::Step()
|
||||
// Did we reset first?
|
||||
if (m_Handle->mDone)
|
||||
{
|
||||
SqThrowF("Stepped without resetting first");
|
||||
STHROWF("Stepped without resetting first");
|
||||
}
|
||||
// Attempt to step the statement
|
||||
m_Handle = sqlite3_step(m_Handle);
|
||||
@ -214,10 +216,10 @@ bool Statement::Step()
|
||||
// Inspect the result
|
||||
switch (m_Handle->mStatus)
|
||||
{
|
||||
case SQLITE_BUSY: SqThrowF("Database was busy");
|
||||
case SQLITE_ERROR: SqThrowF("Runtime error occurred");
|
||||
case SQLITE_MISUSE: SqThrowF("Statement misuse");
|
||||
default: SqThrowF("Unknown failure");
|
||||
case SQLITE_BUSY: STHROWF("Database was busy");
|
||||
case SQLITE_ERROR: STHROWF("Runtime error occurred");
|
||||
case SQLITE_MISUSE: STHROWF("Statement misuse");
|
||||
default: STHROWF("Unknown failure");
|
||||
}
|
||||
// Operation failed (shouldn't reach this point!)
|
||||
return false;
|
||||
@ -233,7 +235,7 @@ void Statement::IndexBindA(Int32 idx, const Array & arr)
|
||||
// Make sure that we are at least in bounds
|
||||
if (idx >= max)
|
||||
{
|
||||
SqThrowF("Parameter index out of range: %d >= %d", idx, max);
|
||||
STHROWF("Parameter index out of range: %d >= %d", idx, max);
|
||||
}
|
||||
// Should we clear onward parameters?
|
||||
else if (arr.Length() <= 0)
|
||||
@ -271,7 +273,7 @@ void Statement::IndexBindI(Int32 idx, Int32 value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "int", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "int", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,14 +291,14 @@ void Statement::IndexBindL(Int32 idx, const Object & value)
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
||||
{
|
||||
SqThrowF("Invalid long integer specified");
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_int(m_Handle, idx, longint);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "long", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "long", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,7 +316,7 @@ void Statement::IndexBindV(Int32 idx, SQInteger value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "value", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "value", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +330,7 @@ void Statement::IndexBindF(Int32 idx, SQFloat value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "float", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "float", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,7 +344,7 @@ void Statement::IndexBindS(Int32 idx, CSStr value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "string", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "string", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,7 +358,7 @@ void Statement::IndexBindB(Int32 idx, bool value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "boolean", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "boolean", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,7 +372,7 @@ void Statement::IndexBindN(Int32 idx)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "null", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "null", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,14 +414,14 @@ void Statement::NameBindI(CSStr name, Int32 value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "int", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "int", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,7 +435,7 @@ void Statement::NameBindL(CSStr name, const Object & value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
@ -444,14 +446,14 @@ void Statement::NameBindL(CSStr name, const Object & value)
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(DefaultVM::Get(), -1, &longint)))
|
||||
{
|
||||
SqThrowF("Invalid long integer specified");
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_int(m_Handle, idx, longint);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "long", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "long", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,7 +467,7 @@ void Statement::NameBindV(CSStr name, SQInteger value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
#ifdef _SQ64
|
||||
@ -476,7 +478,7 @@ void Statement::NameBindV(CSStr name, SQInteger value)
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "value", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "value", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,14 +492,14 @@ void Statement::NameBindF(CSStr name, SQFloat value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_double(m_Handle, idx, value);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "float", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "float", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -511,14 +513,14 @@ void Statement::NameBindS(CSStr name, CSStr value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_text(m_Handle, idx, value, -1, SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "string", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "string", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,14 +534,14 @@ void Statement::NameBindB(CSStr name, bool value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "boolean", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "boolean", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -553,14 +555,14 @@ void Statement::NameBindN(CSStr name)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle = sqlite3_bind_null(m_Handle, idx);
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "null", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "null", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -612,19 +614,19 @@ void Statement::IndexBind(Int32 idx, const Object & value)
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
||||
{
|
||||
SqThrowF("Invalid long integer specified (%d)", idx);
|
||||
STHROWF("Invalid long integer specified (%d)", idx);
|
||||
}
|
||||
// Now bind the resulted long integer
|
||||
m_Handle = sqlite3_bind_int64(m_Handle, idx, longint);
|
||||
} break;
|
||||
// We don't recognize this kind of value!
|
||||
default:
|
||||
SqThrowF("Attempting to bind unknown value type (%d)", idx);
|
||||
STHROWF("Attempting to bind unknown value type (%d)", idx);
|
||||
}
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamI, "auto", idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMI, "auto", idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,7 +640,7 @@ void Statement::NameBind(CSStr name, const Object & value)
|
||||
// Validate the obtained index
|
||||
if (!idx)
|
||||
{
|
||||
SqThrowF("Unknown parameter named (%s)", name);
|
||||
STHROWF("Unknown parameter named (%s)", name);
|
||||
}
|
||||
// Attempt to identify the specified type
|
||||
switch (value.GetType())
|
||||
@ -683,19 +685,19 @@ void Statement::NameBind(CSStr name, const Object & value)
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
||||
{
|
||||
SqThrowF("Invalid long integer specified (%s:%d)", name, idx);
|
||||
STHROWF("Invalid long integer specified (%s:%d)", name, idx);
|
||||
}
|
||||
// Now bind the resulted long integer
|
||||
m_Handle = sqlite3_bind_int64(m_Handle, idx, longint);
|
||||
} break;
|
||||
// We don't recognize this kind of value!
|
||||
default:
|
||||
SqThrowF("Attempting to bind unknown value type (%s:%d)", name, idx);
|
||||
STHROWF("Attempting to bind unknown value type (%s:%d)", name, idx);
|
||||
}
|
||||
// Validate the result
|
||||
if (m_Handle != SQLITE_OK)
|
||||
{
|
||||
SqThrowF(s_BadParamS, "auto", name, idx, m_Handle.ErrMsg());
|
||||
STHROWF(SQMOD_BADPARAMS, "auto", name, idx, m_Handle.ErrMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -715,7 +717,7 @@ void Statement::Bind(const Object & param, const Object & value)
|
||||
// We don't recognize this kind of value!
|
||||
else
|
||||
{
|
||||
SqThrowF("Unknown parameter index type");
|
||||
STHROWF("Unknown parameter index type");
|
||||
}
|
||||
}
|
||||
|
||||
@ -726,7 +728,7 @@ Object Statement::FetchColumnIndex(Int32 idx) const
|
||||
ValidateRow();
|
||||
// Is the specified index valid?
|
||||
if (!m_Handle->CheckIndex(idx))
|
||||
SqThrowF("Column index is out of range: %d", idx);
|
||||
STHROWF("Column index is out of range: %d", idx);
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Identify which type of value must be pushed on the stack
|
||||
@ -764,7 +766,7 @@ Object Statement::FetchColumnIndex(Int32 idx) const
|
||||
const void * b = sqlite3_column_blob(m_Handle, idx);
|
||||
// Could the memory blob be allocated?
|
||||
if (!p)
|
||||
SqThrowF("Unable to allocate space for column blob value");
|
||||
STHROWF("Unable to allocate space for column blob value");
|
||||
// Is there any data to read?
|
||||
else if (!b)
|
||||
{
|
||||
@ -779,7 +781,7 @@ Object Statement::FetchColumnIndex(Int32 idx) const
|
||||
} break;
|
||||
// Unknown type
|
||||
default:
|
||||
SqThrowF("Unknown value to fetch at index: %d", idx);
|
||||
STHROWF("Unknown value to fetch at index: %d", idx);
|
||||
}
|
||||
// Obtain the object with the value from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
@ -808,7 +810,7 @@ Object Statement::FetchColumn(const Object & column) const
|
||||
return FetchColumnIndex(column.Cast< SQInteger >());
|
||||
}
|
||||
// We don't recognize this kind of value!
|
||||
SqThrowF("Unknown column identifier type");
|
||||
STHROWF("Unknown column identifier type");
|
||||
// We have to return something!
|
||||
return Object();
|
||||
}
|
||||
@ -844,17 +846,17 @@ Array Statement::FetchArray(Int32 min, Int32 max) const
|
||||
// Is the minimum actually the minimum?
|
||||
else if (min > max)
|
||||
{
|
||||
SqThrowF("Minimum is higher than maximum");
|
||||
STHROWF("Minimum is higher than maximum");
|
||||
}
|
||||
// Is the minimum in range>
|
||||
else if (!m_Handle->CheckIndex(min))
|
||||
{
|
||||
SqThrowF("Minimum is out of range");
|
||||
STHROWF("Minimum is out of range");
|
||||
}
|
||||
// Is the maximum in range?
|
||||
else if (!m_Handle->CheckIndex(max))
|
||||
{
|
||||
SqThrowF("Maximum is out of range");
|
||||
STHROWF("Maximum is out of range");
|
||||
}
|
||||
// Allocate an array large enough to hold the values from selected columns
|
||||
Array arr(DefaultVM::Get(), max-min);
|
||||
@ -898,7 +900,7 @@ Array Statement::FetchArray(Int32 min, Int32 max) const
|
||||
// Could the memory blob be allocated?
|
||||
if (!p)
|
||||
{
|
||||
SqThrowF("Unable to allocate space for column blob value");
|
||||
STHROWF("Unable to allocate space for column blob value");
|
||||
}
|
||||
// Is there any data to read?
|
||||
else if (!b)
|
||||
@ -920,7 +922,7 @@ Array Statement::FetchArray(Int32 min, Int32 max) const
|
||||
} break;
|
||||
// Unknown type
|
||||
default:
|
||||
SqThrowF("Unknown value to fetch at index: %d", idx);
|
||||
STHROWF("Unknown value to fetch at index: %d", idx);
|
||||
}
|
||||
}
|
||||
// Return the resulted array
|
||||
@ -958,17 +960,17 @@ Table Statement::FetchTable(Int32 min, Int32 max) const
|
||||
// Is the minimum actually the minimum?
|
||||
else if (min > max)
|
||||
{
|
||||
SqThrowF("Minimum is higher than maximum");
|
||||
STHROWF("Minimum is higher than maximum");
|
||||
}
|
||||
// Is the minimum in range>
|
||||
else if (!m_Handle->CheckIndex(min))
|
||||
{
|
||||
SqThrowF("Minimum is out of range");
|
||||
STHROWF("Minimum is out of range");
|
||||
}
|
||||
// Is the maximum in range?
|
||||
else if (!m_Handle->CheckIndex(max))
|
||||
{
|
||||
SqThrowF("Maximum is out of range");
|
||||
STHROWF("Maximum is out of range");
|
||||
}
|
||||
// Create a table to hold the selected column values
|
||||
Table tbl(DefaultVM::Get());
|
||||
@ -981,7 +983,7 @@ Table Statement::FetchTable(Int32 min, Int32 max) const
|
||||
CSStr name = sqlite3_column_name(m_Handle, idx);
|
||||
// Validate the obtained name
|
||||
if (!name)
|
||||
SqThrowF("Unable to retrieve name of column (%d)", idx);
|
||||
STHROWF("Unable to retrieve name of column (%d)", idx);
|
||||
// Identify the type of value that must be assigned
|
||||
switch (sqlite3_column_type(m_Handle, idx))
|
||||
{
|
||||
@ -1023,7 +1025,7 @@ Table Statement::FetchTable(Int32 min, Int32 max) const
|
||||
// Could the memory blob be allocated?
|
||||
if (!p)
|
||||
{
|
||||
SqThrowF("Unable to allocate space for column blob value");
|
||||
STHROWF("Unable to allocate space for column blob value");
|
||||
}
|
||||
// Is there any data to read?
|
||||
else if (!b)
|
||||
@ -1045,7 +1047,7 @@ Table Statement::FetchTable(Int32 min, Int32 max) const
|
||||
} break;
|
||||
// Unknown type
|
||||
default:
|
||||
SqThrowF("Unknown value to fetch at index: %d", idx);
|
||||
STHROWF("Unknown value to fetch at index: %d", idx);
|
||||
}
|
||||
}
|
||||
// Return the resulted table
|
||||
@ -1100,7 +1102,7 @@ CSStr Statement::GetColumnOriginName(Int32 idx) const
|
||||
// The compiler moans when extra warnings are enabled
|
||||
SQMOD_UNUSED_VAR(idx);
|
||||
// Stop the execution here!
|
||||
SqThrowF("The module was compiled without this feature");
|
||||
STHROWF("The module was compiled without this feature");
|
||||
// We have to return something
|
||||
return _SC("");
|
||||
#endif
|
||||
@ -1143,7 +1145,7 @@ Object Statement::GetColumnByName(CSStr name) const
|
||||
// Validate the obtained index
|
||||
if (idx < 0)
|
||||
{
|
||||
SqThrowF("Unknown column named (%s)", name);
|
||||
STHROWF("Unknown column named (%s)", name);
|
||||
}
|
||||
// Return the requested column
|
||||
return Object(new Column(m_Handle, idx));
|
||||
@ -1163,7 +1165,7 @@ Object Statement::GetColumn(const Object & column) const
|
||||
return GetColumnByIndex(column.Cast< SQInteger >());
|
||||
}
|
||||
// We don't recognize this kind of value!
|
||||
SqThrowF("Unknown column identifier type");
|
||||
STHROWF("Unknown column identifier type");
|
||||
// We have to return something!
|
||||
return Object();
|
||||
}
|
||||
|
@ -18,10 +18,6 @@ private:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
StmtHnd m_Handle; /* The handle to the managed database statement resource. */
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static CSStr s_BadParamI; /* Error message when failed to bind value to parameter index. */
|
||||
static CSStr s_BadParamS; /* Error message when failed to bind value to parameter name. */
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user