2016-02-27 10:57:29 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Statement.hpp"
|
|
|
|
#include "Connection.hpp"
|
|
|
|
#include "Column.hpp"
|
|
|
|
#include "Module.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <sqrat.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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]";
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQInteger Statement::Typename(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
static SQChar name[] = _SC("SqSQLiteStatement");
|
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 16:53:12 +01:00
|
|
|
void Statement::Validate() const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Is the handle valid?
|
|
|
|
if (!m_Handle)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Invalid SQLite statement reference");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 16:53:12 +01:00
|
|
|
void Statement::ValidateIndex(Int32 idx) const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Is the handle valid?
|
2016-02-27 10:57:29 +01:00
|
|
|
if (!m_Handle)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Invalid SQLite statement reference");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the specified index in range?
|
|
|
|
else if (!m_Handle->CheckIndex(idx))
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Column index is out of range: %d", idx);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 16:53:12 +01:00
|
|
|
void Statement::ValidateRow() const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Is the handle valid?
|
2016-02-27 10:57:29 +01:00
|
|
|
if (!m_Handle)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Invalid SQLite statement reference");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Do we have any rows available?
|
|
|
|
else if (!m_Handle->mGood)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("No row available");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Statement::Statement()
|
|
|
|
: m_Handle()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Statement::Statement(const ConnHnd & connection, CSStr query)
|
|
|
|
: m_Handle(connection)
|
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Validate the statement handle
|
2016-02-27 12:51:14 +01:00
|
|
|
if (m_Handle.m_Hnd)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
m_Handle->Create(query);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// We just failed to obtain a valid handle
|
2016-02-27 10:57:29 +01:00
|
|
|
else
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to create the statement reference");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Statement::Statement(const Connection & connection, CSStr query)
|
|
|
|
: m_Handle(connection.GetHandle())
|
|
|
|
{
|
2016-02-27 12:51:14 +01:00
|
|
|
// Validate the statement handle
|
|
|
|
if (m_Handle.m_Hnd)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
m_Handle->Create(query);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// We just failed to obtain a valid handle
|
2016-02-27 10:57:29 +01:00
|
|
|
else
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to create the statement reference");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 12:51:14 +01:00
|
|
|
Object Statement::GetConnection() const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return Object(new Connection(m_Handle->mConn));
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::Reset()
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Specify that we don't have a row available and we haven't finished stepping
|
|
|
|
m_Handle->mGood = false;
|
|
|
|
m_Handle->mDone = false;
|
|
|
|
// Attempt to reset the statement to it's initial state
|
|
|
|
m_Handle = sqlite3_reset(m_Handle);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to reset statement [%s]", m_Handle.ErrStr());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::Clear()
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Specify that we don't have a row available and we haven't finished stepping
|
|
|
|
m_Handle->mGood = false;
|
|
|
|
m_Handle->mDone = false;
|
|
|
|
// Attempt to clear the statement
|
|
|
|
m_Handle = sqlite3_clear_bindings(m_Handle);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to clear statement [%s]", m_Handle.ErrStr());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Statement::Exec()
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Did we reset first?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (m_Handle->mDone)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Executed without resetting first");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to step the statement
|
|
|
|
m_Handle = sqlite3_step(m_Handle);
|
|
|
|
// Have we finished stepping?
|
|
|
|
if (m_Handle == SQLITE_DONE)
|
|
|
|
{
|
|
|
|
// Specify that we don't have row available and we finished stepping
|
|
|
|
m_Handle->mGood = false;
|
|
|
|
m_Handle->mDone = true;
|
|
|
|
// Return the changes made by this statement
|
|
|
|
return sqlite3_changes(m_Handle->mConn);
|
|
|
|
}
|
|
|
|
// Specify that we don't have any row and we haven't finished stepping
|
|
|
|
m_Handle->mGood = false;
|
|
|
|
m_Handle->mDone = false;
|
|
|
|
// Inspect the result
|
|
|
|
switch (m_Handle->mStatus)
|
|
|
|
{
|
|
|
|
// We don't expect any rows to be returned in this case!
|
2016-02-27 16:53:12 +01:00
|
|
|
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");
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Operation failed (shouldn't reach this point!)
|
2016-02-27 10:57:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Statement::Step()
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Did we reset first?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (m_Handle->mDone)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Stepped without resetting first");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to step the statement
|
|
|
|
m_Handle = sqlite3_step(m_Handle);
|
|
|
|
// Do we have a row available?
|
|
|
|
if (m_Handle == SQLITE_ROW)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
// Specify that we have a row available
|
|
|
|
return (m_Handle->mGood = true);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Have we finished stepping?
|
|
|
|
else if (m_Handle == SQLITE_DONE)
|
|
|
|
{
|
|
|
|
// Specify that we finished stepping
|
|
|
|
m_Handle->mDone = true;
|
|
|
|
// Specify that we don't have a row available
|
|
|
|
return (m_Handle->mGood = false);
|
|
|
|
}
|
|
|
|
// Specify that we don't have any row and we haven't finished stepping
|
|
|
|
m_Handle->mGood = false;
|
|
|
|
m_Handle->mDone = false;
|
|
|
|
// Inspect the result
|
|
|
|
switch (m_Handle->mStatus)
|
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
case SQLITE_BUSY: SqThrowF("Database was busy");
|
|
|
|
case SQLITE_ERROR: SqThrowF("Runtime error occurred");
|
|
|
|
case SQLITE_MISUSE: SqThrowF("Statement misuse");
|
|
|
|
default: SqThrowF("Unknown failure");
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Operation failed (shouldn't reach this point!)
|
2016-02-27 10:57:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::IndexBindA(Int32 idx, const Array & arr)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Know when to stop trying to bind values
|
|
|
|
const Int32 max = sqlite3_bind_parameter_count(m_Handle);
|
|
|
|
// Make sure that we are at least in bounds
|
|
|
|
if (idx >= max)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Parameter index out of range: %d >= %d", idx, max);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Should we clear onward parameters?
|
|
|
|
else if (arr.Length() <= 0)
|
|
|
|
{
|
|
|
|
// Clear all parameters after the specified index
|
|
|
|
for (Int32 idx = arr.Length(); idx < max; ++idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
sqlite3_bind_null(m_Handle, idx);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
// Attempt to retrieve and bind the specified values
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Allocated memory for the specified amount of values
|
|
|
|
std::vector< Object > values(arr.Length());
|
|
|
|
// Attempt to retrieve the specified values
|
|
|
|
arr.GetArray< Object >(&values[0], values.size());
|
|
|
|
// Obtain the start of the object list
|
|
|
|
std::vector< Object >::iterator itr = values.begin();
|
|
|
|
// Attempt to bind each specified element individually
|
|
|
|
for (; itr != values.end() && idx < max; ++itr)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
IndexBind(idx++, *itr);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindI(Int32 idx, Int32 value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "int", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::IndexBindL(Int32 idx, const Object & value)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Obtain the initial stack size
|
2016-03-18 11:58:02 +01:00
|
|
|
const StackGuard sg(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
Var< const Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:29 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-03-18 11:58:02 +01:00
|
|
|
if (SQ_FAILED(_SqMod->GetSLongValue(DefaultVM::Get(), -1, &longint)))
|
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Invalid long integer specified");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, longint);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "long", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindV(Int32 idx, SQInteger value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
#ifdef _SQ64
|
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, value);
|
|
|
|
#else
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
#endif // _SQ64
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "value", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindF(Int32 idx, SQFloat value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_double(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "float", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindS(Int32 idx, CSStr value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// 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)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "string", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindB(Int32 idx, bool value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "boolean", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::IndexBindN(Int32 idx)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_null(m_Handle, idx);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "null", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::NameBindT(const Table & tbl)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Should we clear the all the parameters?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (tbl.GetSize() <= 0)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
Clear();
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to assign the specified parameter values
|
|
|
|
else
|
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain a table iterator
|
2016-02-27 10:57:29 +01:00
|
|
|
Table::iterator itr;
|
2016-02-27 16:53:12 +01:00
|
|
|
// Used to retrieve element values
|
2016-02-27 10:57:29 +01:00
|
|
|
Object val;
|
|
|
|
// Process each element until _next returns null
|
|
|
|
while (tbl.Next(itr))
|
|
|
|
{
|
|
|
|
// Get the value object
|
|
|
|
val = Object(itr.getValue());
|
|
|
|
// Bind it to the associated key
|
|
|
|
NameBind(itr.getName(), val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindI(CSStr name, Int32 value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "int", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::NameBindL(CSStr name, const Object & value)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Obtain the initial stack size
|
2016-03-18 11:58:02 +01:00
|
|
|
const StackGuard sg(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
// Push the specified object onto the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
Var< const Object & >::push(DefaultVM::Get(), value);
|
2016-02-27 10:57:29 +01:00
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
2016-03-18 11:58:02 +01:00
|
|
|
if (SQ_FAILED(_SqMod->GetULongValue(DefaultVM::Get(), -1, &longint)))
|
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Invalid long integer specified");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, longint);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "long", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindV(CSStr name, SQInteger value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
#ifdef _SQ64
|
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, value);
|
|
|
|
#else
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
#endif // _SQ64
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "value", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindF(CSStr name, SQFloat value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_double(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "float", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindS(CSStr name, CSStr value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// 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)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "string", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindB(CSStr name, bool value)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "boolean", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::NameBindN(CSStr name)
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to bind the specified value
|
|
|
|
m_Handle = sqlite3_bind_null(m_Handle, idx);
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "null", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::IndexBind(Int32 idx, const Object & value)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to identify the specified type
|
|
|
|
switch (value.GetType())
|
|
|
|
{
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a native integer value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_INTEGER:
|
|
|
|
#ifdef _SQ64
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, value.Cast< SQInteger >());
|
2016-02-27 10:57:29 +01:00
|
|
|
#else
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value.Cast< SQInteger >());
|
2016-02-27 10:57:29 +01:00
|
|
|
#endif
|
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a native float value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_FLOAT:
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_double(m_Handle, idx, value.Cast< SQFloat >());
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a boolean value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_BOOL:
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value.Cast< bool >());
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a string value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_STRING:
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_text(m_Handle, idx, value.Cast< CSStr >(), -1, SQLITE_TRANSIENT);
|
|
|
|
break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this a null value?
|
|
|
|
case OT_NULL:
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_null(m_Handle, idx);
|
|
|
|
break;
|
|
|
|
// Is this an array value?
|
|
|
|
case OT_ARRAY:
|
|
|
|
IndexBindA(idx, value.Cast< const Array & >());
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this an instance value?
|
|
|
|
case OT_INSTANCE:
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
|
|
|
const StackGuard sg(DefaultVM::Get());
|
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< const Object & >::push(DefaultVM::Get(), value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
// Now bind the resulted long integer
|
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, longint);
|
|
|
|
} break;
|
|
|
|
// We don't recognize this kind of value!
|
2016-02-27 10:57:29 +01:00
|
|
|
default:
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Attempting to bind unknown value type (%d)", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamI, "auto", idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-18 11:58:02 +01:00
|
|
|
void Statement::NameBind(CSStr name, const Object & value)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to obtain the index of the specified parameter name
|
|
|
|
const Int32 idx = sqlite3_bind_parameter_index(m_Handle, name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (!idx)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown parameter named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Attempt to identify the specified type
|
|
|
|
switch (value.GetType())
|
|
|
|
{
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a native integer value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_INTEGER:
|
|
|
|
#ifdef _SQ64
|
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, value.Cast< SQInteger >());
|
|
|
|
#else
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value.Cast< SQInteger >());
|
|
|
|
#endif
|
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a native float value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_FLOAT:
|
|
|
|
m_Handle = sqlite3_bind_double(m_Handle, idx, value.Cast< SQFloat >());
|
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a boolean value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_BOOL:
|
|
|
|
m_Handle = sqlite3_bind_int(m_Handle, idx, value.Cast< bool >());
|
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this a string value?
|
2016-02-27 10:57:29 +01:00
|
|
|
case OT_STRING:
|
2016-03-18 11:58:02 +01:00
|
|
|
m_Handle = sqlite3_bind_text(m_Handle, idx, value.Cast< CSStr >(), -1, SQLITE_TRANSIENT);
|
|
|
|
break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this a null value?
|
|
|
|
case OT_NULL:
|
|
|
|
m_Handle = sqlite3_bind_null(m_Handle, idx);
|
|
|
|
break;
|
2016-03-18 11:58:02 +01:00
|
|
|
// Is this an array value?
|
|
|
|
case OT_TABLE:
|
|
|
|
NameBindT(value.Cast< const Table & >());
|
|
|
|
break;
|
|
|
|
// Is this an instance value?
|
|
|
|
case OT_INSTANCE:
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
|
|
|
const StackGuard sg(DefaultVM::Get());
|
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< const Object & >::push(DefaultVM::Get(), value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
// Now bind the resulted long integer
|
|
|
|
m_Handle = sqlite3_bind_int64(m_Handle, idx, longint);
|
|
|
|
} break;
|
|
|
|
// We don't recognize this kind of value!
|
2016-02-27 10:57:29 +01:00
|
|
|
default:
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Attempting to bind unknown value type (%s:%d)", name, idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
// Validate the result
|
|
|
|
if (m_Handle != SQLITE_OK)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF(s_BadParamS, "auto", name, idx, m_Handle.ErrMsg());
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Statement::Bind(const Object & param, const Object & value)
|
|
|
|
{
|
|
|
|
// Is this a string value?
|
|
|
|
if (param.GetType() == OT_STRING)
|
|
|
|
{
|
|
|
|
NameBind(param.Cast< CSStr >(), value);
|
|
|
|
}
|
|
|
|
// Is this an integer value?
|
|
|
|
else if (param.GetType() == OT_INTEGER)
|
|
|
|
{
|
|
|
|
IndexBind(param.Cast< SQInteger >(), value);
|
|
|
|
}
|
|
|
|
// We don't recognize this kind of value!
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SqThrowF("Unknown parameter index type");
|
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Statement::FetchColumnIndex(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Validate the handle and row
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateRow();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the specified index valid?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (!m_Handle->CheckIndex(idx))
|
|
|
|
SqThrowF("Column index is out of range: %d", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Obtain the initial stack size
|
2016-03-18 11:58:02 +01:00
|
|
|
const StackGuard sg(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
// Identify which type of value must be pushed on the stack
|
|
|
|
switch (sqlite3_column_type(m_Handle, idx))
|
|
|
|
{
|
|
|
|
// Is this a null value?
|
|
|
|
case SQLITE_NULL:
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushnull(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
|
|
|
// Is this an integer?
|
|
|
|
case SQLITE_INTEGER:
|
|
|
|
#ifdef _SQ64
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushinteger(DefaultVM::Get(), sqlite3_column_int64(m_Handle, idx));
|
2016-02-27 10:57:29 +01:00
|
|
|
#else
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushinteger(DefaultVM::Get(), sqlite3_column_int(m_Handle, idx));
|
2016-02-27 10:57:29 +01:00
|
|
|
#endif
|
2016-02-27 16:53:12 +01:00
|
|
|
break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this a floating point?
|
|
|
|
case SQLITE_FLOAT:
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushfloat(DefaultVM::Get(), sqlite3_column_double(m_Handle, idx));
|
2016-02-27 16:53:12 +01:00
|
|
|
break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this a string?
|
|
|
|
case SQLITE_TEXT:
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushstring(DefaultVM::Get(), (CSStr)sqlite3_column_text(m_Handle, idx),
|
2016-02-27 10:57:29 +01:00
|
|
|
sqlite3_column_bytes(m_Handle, idx));
|
2016-02-27 16:53:12 +01:00
|
|
|
break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this raw data?
|
|
|
|
case SQLITE_BLOB:
|
|
|
|
{
|
|
|
|
// Obtain the size of the data
|
|
|
|
const Int32 sz = sqlite3_column_bytes(m_Handle, idx);
|
|
|
|
// Allocate a blob of the same size
|
2016-03-18 11:58:02 +01:00
|
|
|
SQUserPointer p = sqstd_createblob(DefaultVM::Get(), sz);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Obtain a pointer to the data
|
|
|
|
const void * b = sqlite3_column_blob(m_Handle, idx);
|
|
|
|
// Could the memory blob be allocated?
|
|
|
|
if (!p)
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to allocate space for column blob value");
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is there any data to read?
|
|
|
|
else if (!b)
|
|
|
|
{
|
|
|
|
// Pop the memory blob from the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pop(DefaultVM::Get(), 1);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Push a null value instead
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushnull(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
// Copy the data into the memory blob
|
|
|
|
else
|
|
|
|
memcpy(p, b, sz);
|
2016-02-27 16:53:12 +01:00
|
|
|
} break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Unknown type
|
|
|
|
default:
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown value to fetch at index: %d", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
2016-02-28 15:20:33 +01:00
|
|
|
// Obtain the object with the value from the stack and return it
|
2016-03-18 11:58:02 +01:00
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Statement::FetchColumnName(CSStr name) const
|
|
|
|
{
|
|
|
|
// Validate the handle and row
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateRow();
|
|
|
|
// Return the requested information
|
|
|
|
return FetchColumnIndex(m_Handle->GetColumnIndex(name));
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 11:58:02 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Statement::FetchColumn(const Object & column) const
|
|
|
|
{
|
|
|
|
// Is this a string value?
|
|
|
|
if (column.GetType() == OT_STRING)
|
|
|
|
{
|
|
|
|
return FetchColumnName(column.Cast< CSStr >());
|
|
|
|
}
|
|
|
|
// Is this an integer value?
|
|
|
|
else if (column.GetType() == OT_INTEGER)
|
|
|
|
{
|
|
|
|
return FetchColumnIndex(column.Cast< SQInteger >());
|
|
|
|
}
|
|
|
|
// We don't recognize this kind of value!
|
|
|
|
SqThrowF("Unknown column identifier type");
|
|
|
|
// We have to return something!
|
|
|
|
return Object();
|
|
|
|
}
|
|
|
|
|
2016-02-27 10:57:29 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array Statement::FetchArray() const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-03-13 12:39:17 +01:00
|
|
|
return FetchArray(0, m_Handle->mColumns);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array Statement::FetchArray(Int32 min) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-03-13 12:39:17 +01:00
|
|
|
return FetchArray(min, m_Handle->mColumns);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array Statement::FetchArray(Int32 min, Int32 max) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateRow();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Was there anything selected?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (min == max)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
return Array(); // Nothing to retrieve
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the minimum actually the minimum?
|
|
|
|
else if (min > max)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Minimum is higher than maximum");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the minimum in range>
|
|
|
|
else if (!m_Handle->CheckIndex(min))
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Minimum is out of range");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the maximum in range?
|
|
|
|
else if (!m_Handle->CheckIndex(max))
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Maximum is out of range");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Allocate an array large enough to hold the values from selected columns
|
2016-03-18 11:58:02 +01:00
|
|
|
Array arr(DefaultVM::Get(), max-min);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Process the range of selected columns
|
|
|
|
for (Int32 elem = 0, idx = min; idx < max; ++elem, ++idx)
|
|
|
|
{
|
|
|
|
// Identify the type of value that must be assigned
|
|
|
|
switch (sqlite3_column_type(m_Handle, idx))
|
|
|
|
{
|
|
|
|
// Is this a null value?
|
|
|
|
case SQLITE_NULL:
|
|
|
|
// Array elements are initialized as null by default so we just leave it like that
|
|
|
|
break;
|
|
|
|
// Is this an integer?
|
|
|
|
case SQLITE_INTEGER:
|
|
|
|
#ifdef _SQ64
|
|
|
|
arr.SetValue(elem, sqlite3_column_int64(m_Handle, idx));
|
|
|
|
#else
|
|
|
|
arr.SetValue(elem, sqlite3_column_int(m_Handle, idx));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
// Is this a floating point?
|
|
|
|
case SQLITE_FLOAT:
|
|
|
|
arr.SetValue(elem, sqlite3_column_double(m_Handle, idx));
|
|
|
|
break;
|
|
|
|
// Is this a string?
|
|
|
|
case SQLITE_TEXT:
|
2016-03-18 11:58:02 +01:00
|
|
|
arr.SetValue(elem, reinterpret_cast< CCStr >(sqlite3_column_text(m_Handle, idx)));
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
|
|
|
// Is this raw data?
|
|
|
|
case SQLITE_BLOB:
|
2016-02-27 16:53:12 +01:00
|
|
|
{
|
2016-02-28 15:20:33 +01:00
|
|
|
// Obtain the initial stack size
|
2016-03-18 11:58:02 +01:00
|
|
|
const StackGuard sg(DefaultVM::Get());
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain the size of the data
|
|
|
|
const Int32 sz = sqlite3_column_bytes(m_Handle, idx);
|
|
|
|
// Allocate a blob of the same size
|
2016-03-18 11:58:02 +01:00
|
|
|
SQUserPointer p = sqstd_createblob(DefaultVM::Get(), sz);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain a pointer to the data
|
|
|
|
const void * b = sqlite3_column_blob(m_Handle, idx);
|
|
|
|
// Could the memory blob be allocated?
|
|
|
|
if (!p)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to allocate space for column blob value");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Is there any data to read?
|
|
|
|
else if (!b)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Pop the memory blob from the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pop(DefaultVM::Get(), 1);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Push a null value instead
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushnull(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Copy the data into the memory blob
|
|
|
|
else
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
memcpy(p, b, sz);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain the object from the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
Var< Object > obj(DefaultVM::Get(), -1);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Bind it as an array element
|
|
|
|
arr.Bind(elem, obj.value);
|
|
|
|
} break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Unknown type
|
|
|
|
default:
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown value to fetch at index: %d", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return the resulted array
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Table Statement::FetchTable() const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-03-13 12:39:17 +01:00
|
|
|
return FetchTable(0, m_Handle->mColumns);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Table Statement::FetchTable(Int32 min) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
2016-03-13 12:39:17 +01:00
|
|
|
return FetchTable(min, m_Handle->mColumns);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Table Statement::FetchTable(Int32 min, Int32 max) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateRow();
|
2016-02-27 10:57:29 +01:00
|
|
|
// Was there anything selected?
|
2016-02-27 16:53:12 +01:00
|
|
|
if (min == max)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 10:57:29 +01:00
|
|
|
return Table(); // Nothing to retrieve
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the minimum actually the minimum?
|
|
|
|
else if (min > max)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Minimum is higher than maximum");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the minimum in range>
|
|
|
|
else if (!m_Handle->CheckIndex(min))
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Minimum is out of range");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is the maximum in range?
|
|
|
|
else if (!m_Handle->CheckIndex(max))
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Maximum is out of range");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Create a table to hold the selected column values
|
2016-03-18 11:58:02 +01:00
|
|
|
Table tbl(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
// Used to bind null values
|
|
|
|
Object obj;
|
|
|
|
// Process the range of selected columns
|
|
|
|
for (Int32 elem = 0, idx = min; idx < max; ++elem, ++idx)
|
|
|
|
{
|
|
|
|
//Attempt to obtain the column name
|
|
|
|
CSStr name = sqlite3_column_name(m_Handle, idx);
|
|
|
|
// Validate the obtained name
|
|
|
|
if (!name)
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to retrieve name of column (%d)", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
// Identify the type of value that must be assigned
|
|
|
|
switch (sqlite3_column_type(m_Handle, idx))
|
|
|
|
{
|
|
|
|
// Is this a null value?
|
|
|
|
case SQLITE_NULL:
|
|
|
|
{
|
|
|
|
// Make sure we don't insert the same instance
|
|
|
|
obj.Release();
|
|
|
|
// Now it's safe to insert the value
|
|
|
|
tbl.SetValue(name, obj);
|
2016-02-27 16:53:12 +01:00
|
|
|
} break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Is this an integer?
|
|
|
|
case SQLITE_INTEGER:
|
|
|
|
#ifdef _SQ64
|
|
|
|
tbl.SetValue(name, sqlite3_column_int64(m_Handle, idx));
|
|
|
|
#else
|
|
|
|
tbl.SetValue(name, sqlite3_column_int(m_Handle, idx));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
// Is this a floating point?
|
|
|
|
case SQLITE_FLOAT:
|
|
|
|
tbl.SetValue(name, sqlite3_column_double(m_Handle, idx));
|
|
|
|
break;
|
|
|
|
// Is this a string?
|
|
|
|
case SQLITE_TEXT:
|
2016-03-18 11:58:02 +01:00
|
|
|
tbl.SetValue(name, reinterpret_cast< CCStr >(sqlite3_column_text(m_Handle, idx)));
|
2016-02-27 10:57:29 +01:00
|
|
|
break;
|
|
|
|
// Is this raw data?
|
|
|
|
case SQLITE_BLOB:
|
2016-02-27 16:53:12 +01:00
|
|
|
{
|
2016-02-28 15:20:33 +01:00
|
|
|
// Obtain the initial stack size
|
2016-03-18 11:58:02 +01:00
|
|
|
const StackGuard sg(DefaultVM::Get());
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain the size of the data
|
|
|
|
const Int32 sz = sqlite3_column_bytes(m_Handle, idx);
|
|
|
|
// Allocate a blob of the same size
|
2016-03-18 11:58:02 +01:00
|
|
|
SQUserPointer p = sqstd_createblob(DefaultVM::Get(), sz);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain a pointer to the data
|
|
|
|
const void * b = sqlite3_column_blob(m_Handle, idx);
|
|
|
|
// Could the memory blob be allocated?
|
|
|
|
if (!p)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unable to allocate space for column blob value");
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Is there any data to read?
|
|
|
|
else if (!b)
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
// Pop the memory blob from the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pop(DefaultVM::Get(), 1);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Push a null value instead
|
2016-03-18 11:58:02 +01:00
|
|
|
sq_pushnull(DefaultVM::Get());
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Copy the data into the memory blob
|
|
|
|
else
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
memcpy(p, b, sz);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Obtain the object from the stack
|
2016-03-18 11:58:02 +01:00
|
|
|
Var< Object > obj(DefaultVM::Get(), -1);
|
2016-02-27 16:53:12 +01:00
|
|
|
// Bind it as a table element
|
|
|
|
tbl.Bind(name, obj.value);
|
|
|
|
} break;
|
2016-02-27 10:57:29 +01:00
|
|
|
// Unknown type
|
|
|
|
default:
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown value to fetch at index: %d", idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return the resulted table
|
|
|
|
return tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Statement::CheckIndex(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Handle->CheckIndex(idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Statement::IsColumnNull(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return (sqlite3_column_type(m_Handle, idx) == SQLITE_NULL);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Statement::GetColumnIndex(CSStr name) const
|
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Return the requested information
|
|
|
|
return m_Handle->GetColumnIndex(name);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CSStr Statement::GetColumnName(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return sqlite3_column_name(m_Handle, idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CSStr Statement::GetColumnOriginName(Int32 idx) const
|
|
|
|
{
|
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return sqlite3_column_origin_name(m_Handle, idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
#else
|
2016-03-18 11:58:02 +01:00
|
|
|
// The compiler moans when extra warnings are enabled
|
2016-02-27 10:57:29 +01:00
|
|
|
SQMOD_UNUSED_VAR(idx);
|
2016-03-18 11:58:02 +01:00
|
|
|
// Stop the execution here!
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("The module was compiled without this feature");
|
2016-03-18 11:58:02 +01:00
|
|
|
// We have to return something
|
2016-02-27 10:57:29 +01:00
|
|
|
return _SC("");
|
2016-03-18 11:58:02 +01:00
|
|
|
#endif
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Statement::GetColumnType(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return sqlite3_column_type(m_Handle, idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Statement::GetColumnBytes(Int32 idx) const
|
|
|
|
{
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return sqlite3_column_bytes(m_Handle, idx);
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 12:51:14 +01:00
|
|
|
Object Statement::GetColumnByIndex(Int32 idx) const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Can we make the request?
|
2016-02-27 16:53:12 +01:00
|
|
|
ValidateIndex(idx);
|
|
|
|
// Return the requested information
|
|
|
|
return Object(new Column(m_Handle, idx));
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-27 12:51:14 +01:00
|
|
|
Object Statement::GetColumnByName(CSStr name) const
|
2016-02-27 10:57:29 +01:00
|
|
|
{
|
|
|
|
// Validate the handle
|
2016-02-27 16:53:12 +01:00
|
|
|
Validate();
|
|
|
|
// Attempt to obtain the requested column index
|
|
|
|
const Int32 idx = m_Handle->GetColumnIndex(name);
|
|
|
|
// Validate the obtained index
|
|
|
|
if (idx < 0)
|
2016-03-18 11:58:02 +01:00
|
|
|
{
|
2016-02-27 16:53:12 +01:00
|
|
|
SqThrowF("Unknown column named (%s)", name);
|
2016-03-18 11:58:02 +01:00
|
|
|
}
|
2016-02-27 16:53:12 +01:00
|
|
|
// Return the requested column
|
|
|
|
return Object(new Column(m_Handle, idx));
|
2016-02-27 10:57:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 11:58:02 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Statement::GetColumn(const Object & column) const
|
|
|
|
{
|
|
|
|
// Is this a string value?
|
|
|
|
if (column.GetType() == OT_STRING)
|
|
|
|
{
|
|
|
|
return GetColumnByName(column.Cast< CSStr >());
|
|
|
|
}
|
|
|
|
// Is this an integer value?
|
|
|
|
else if (column.GetType() == OT_INTEGER)
|
|
|
|
{
|
|
|
|
return GetColumnByIndex(column.Cast< SQInteger >());
|
|
|
|
}
|
|
|
|
// We don't recognize this kind of value!
|
|
|
|
SqThrowF("Unknown column identifier type");
|
|
|
|
// We have to return something!
|
|
|
|
return Object();
|
|
|
|
}
|
|
|
|
|
2016-02-27 10:57:29 +01:00
|
|
|
} // Namespace:: SqMod
|