mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 00:07:19 +01:00 
			
		
		
		
	Initial implementation for the second revision of the SQLite module.
Added a utility function to retrieve a time instance in seconds.
This commit is contained in:
		@@ -1,7 +1,5 @@
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include "Column.hpp"
 | 
			
		||||
#include "Connection.hpp"
 | 
			
		||||
#include "Statement.hpp"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include <cerrno>
 | 
			
		||||
@@ -11,6 +9,17 @@
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
namespace SqMod {
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
static inline bool IsDigitsOnly(CSStr str)
 | 
			
		||||
{
 | 
			
		||||
    while (std::isdigit(*str) || std::isspace(*str))
 | 
			
		||||
    {
 | 
			
		||||
        ++str;
 | 
			
		||||
    }
 | 
			
		||||
    // Return whether we reached the end while searching
 | 
			
		||||
    return *str == '\0';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQInteger Column::Typename(HSQUIRRELVM vm)
 | 
			
		||||
{
 | 
			
		||||
@@ -117,6 +126,30 @@ const StmtRef & Column::GetCreated() const
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Column::ValidateColumn(Int32 idx, CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated(file, line);
 | 
			
		||||
    // Is the specified index in range?
 | 
			
		||||
    if (!m_Handle->CheckColumn(idx))
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Column index is out of range: %d:%d =>[%s:%d]", idx, m_Handle->mColumns,
 | 
			
		||||
                    file, line);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void Column::ValidateColumn(Int32 idx) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated();
 | 
			
		||||
    // Is the specified index in range?
 | 
			
		||||
    if (!m_Handle->CheckColumn(idx))
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Column index is out of range: %d:%d", idx, m_Handle->mColumns);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Column::ValidateRow(CCStr file, Int32 line) const
 | 
			
		||||
@@ -140,25 +173,132 @@ void Column::ValidateRow() const
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Column::SetIndex(const Object & column)
 | 
			
		||||
{
 | 
			
		||||
    // Where the index will be extracted
 | 
			
		||||
    Int32 idx = -1;
 | 
			
		||||
    // Grab the object virtual machine
 | 
			
		||||
    HSQUIRRELVM vm = column.GetVM();
 | 
			
		||||
    // Remember the current stack size
 | 
			
		||||
    const StackGuard sg(vm);
 | 
			
		||||
    // Push the specified object onto the stack
 | 
			
		||||
    Var< const Object & >::push(vm, column);
 | 
			
		||||
    // Identify the type of column was given
 | 
			
		||||
    switch  (column.GetType())
 | 
			
		||||
    {
 | 
			
		||||
        // Is this a string value?
 | 
			
		||||
        case OT_STRING:
 | 
			
		||||
        {
 | 
			
		||||
            // Obtain the object from the stack as a string
 | 
			
		||||
            const StackStrF val(vm, -1, false);
 | 
			
		||||
            // Validate the result
 | 
			
		||||
            if (SQ_FAILED(val.mRes))
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("%s", LastErrorString(vm).c_str());
 | 
			
		||||
            }
 | 
			
		||||
            // Is the obtained string empty?
 | 
			
		||||
            else if (val.mLen <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("Cannot use an empty column name");
 | 
			
		||||
            }
 | 
			
		||||
            // Attempt to find a column with the specified name
 | 
			
		||||
            idx = m_Handle->GetColumnIndex(val.mPtr);
 | 
			
		||||
        } break;
 | 
			
		||||
        // Is this an integer value? (or at least can be easily converted to one)
 | 
			
		||||
        case OT_INTEGER:
 | 
			
		||||
        case OT_FLOAT:
 | 
			
		||||
        case OT_BOOL:
 | 
			
		||||
        {
 | 
			
		||||
            idx = ConvTo< Int32 >::From(SqMod_PopStackInteger(vm, -1));
 | 
			
		||||
        } break;
 | 
			
		||||
        // Is this an instance that we can extract either a string or integer from it?
 | 
			
		||||
        case OT_INSTANCE:
 | 
			
		||||
        {
 | 
			
		||||
            // Obtain the object from the stack as a string
 | 
			
		||||
            const StackStrF val(vm, -1, false);
 | 
			
		||||
            // Validate the result
 | 
			
		||||
            if (SQ_FAILED(val.mRes))
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("%s", LastErrorString(vm).c_str());
 | 
			
		||||
            }
 | 
			
		||||
            // Is the obtained string empty?
 | 
			
		||||
            else if (val.mLen <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("Cannot use an empty column name");
 | 
			
		||||
            }
 | 
			
		||||
            // Check if this value is made only of digits
 | 
			
		||||
            else if (IsDigitsOnly(val.mPtr))
 | 
			
		||||
            {
 | 
			
		||||
                idx = ConvNum< Int32 >::FromStr(val.mPtr);
 | 
			
		||||
            }
 | 
			
		||||
            // Attempt to find a column with the specified name
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                idx = m_Handle->GetColumnIndex(val.mPtr);
 | 
			
		||||
            }
 | 
			
		||||
        } break;
 | 
			
		||||
        // We don't recognize this kind of value!
 | 
			
		||||
        default: STHROWF("Unknown column index of type (%s)", SqTypeName(column.GetType()));
 | 
			
		||||
    }
 | 
			
		||||
    // Validate the obtained column index
 | 
			
		||||
    SQMOD_VALIDATE_COLUMN(*this, idx);
 | 
			
		||||
    // Assign the new index
 | 
			
		||||
    m_Index = idx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetStatement() const
 | 
			
		||||
{
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return Object(new Statement(m_Handle));
 | 
			
		||||
    return GetStatementObj(m_Handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetConnection() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return Object(new Connection(m_Handle->mConn));
 | 
			
		||||
    return GetConnectionObj(SQMOD_GET_VALID(*this)->mConn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
bool Column::IsNull() const
 | 
			
		||||
{
 | 
			
		||||
    return (sqlite3_column_type(SQMOD_GET_CREATED(*this)->mPtr, m_Index) == SQLITE_NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
CSStr Column::GetName() const
 | 
			
		||||
{
 | 
			
		||||
    return sqlite3_column_name(SQMOD_GET_CREATED(*this)->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
CSStr Column::GetOriginName() const
 | 
			
		||||
{
 | 
			
		||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
 | 
			
		||||
    return sqlite3_column_origin_name(SQMOD_GET_CREATED(*this)->mPtr, m_Index);
 | 
			
		||||
#else
 | 
			
		||||
    STHROWF("The module was compiled without this feature");
 | 
			
		||||
    // Request failed
 | 
			
		||||
    return _SC("");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Column::GetType() const
 | 
			
		||||
{
 | 
			
		||||
    return sqlite3_column_type(SQMOD_GET_CREATED(*this)->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Column::GetBytes() const
 | 
			
		||||
{
 | 
			
		||||
    return sqlite3_column_bytes(SQMOD_GET_CREATED(*this)->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetValue() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Obtain the initial stack size
 | 
			
		||||
    const StackGuard sg;
 | 
			
		||||
    // Identify which type of value must be pushed on the stack
 | 
			
		||||
@@ -195,7 +335,7 @@ Object Column::GetValue() const
 | 
			
		||||
            // Retrieve the the actual blob data that must be returned
 | 
			
		||||
            CCStr data = reinterpret_cast< CCStr >(sqlite3_column_blob(m_Handle->mPtr, m_Index));
 | 
			
		||||
            // Attempt to create a buffer with the blob data on the stack
 | 
			
		||||
            if (SQ_FAILED(SqMod_PushBufferData(DefaultVM::Get(), data, size, size)))
 | 
			
		||||
            if (SQ_FAILED(SqMod_PushBufferData(DefaultVM::Get(), data, size, 0)))
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("Unable to allocate buffer of at least (%d) bytes", size);
 | 
			
		||||
            }
 | 
			
		||||
@@ -210,7 +350,7 @@ Object Column::GetValue() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetNumber() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Obtain the initial stack size
 | 
			
		||||
    const StackGuard sg;
 | 
			
		||||
    // Identify which type of value must be pushed on the stack
 | 
			
		||||
@@ -264,7 +404,7 @@ Object Column::GetNumber() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQInteger Column::GetInteger() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_integer(m_Handle->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
@@ -272,7 +412,7 @@ SQInteger Column::GetInteger() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQFloat Column::GetFloat() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index));
 | 
			
		||||
}
 | 
			
		||||
@@ -280,7 +420,7 @@ SQFloat Column::GetFloat() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetLong() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return MakeSLongObj(sqlite3_column_int64(m_Handle->mPtr, m_Index));
 | 
			
		||||
}
 | 
			
		||||
@@ -288,7 +428,7 @@ Object Column::GetLong() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetString() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Obtain the initial stack size
 | 
			
		||||
    const StackGuard sg(_SqVM);
 | 
			
		||||
    // Push the column text on the stack
 | 
			
		||||
@@ -301,7 +441,7 @@ Object Column::GetString() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
bool Column::GetBoolean() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_int(m_Handle->mPtr, m_Index) > 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -309,7 +449,7 @@ bool Column::GetBoolean() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQChar Column::GetChar() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return (SQChar)sqlite3_column_int(m_Handle->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
@@ -317,7 +457,7 @@ SQChar Column::GetChar() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetBuffer() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Remember the current stack size
 | 
			
		||||
    const StackGuard sg;
 | 
			
		||||
    // Retrieve the size of the blob that must be allocated
 | 
			
		||||
@@ -336,7 +476,7 @@ Object Column::GetBuffer() const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Column::GetBlob() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_ROW_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_ROW(*this);
 | 
			
		||||
    // Obtain the initial stack size
 | 
			
		||||
    const StackGuard sg(_SqVM);
 | 
			
		||||
    // Obtain the size of the data
 | 
			
		||||
@@ -367,52 +507,6 @@ Object Column::GetBlob() const
 | 
			
		||||
    return Var< Object >(_SqVM, -1).value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
bool Column::IsNull() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_CREATED_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return (sqlite3_column_type(m_Handle->mPtr, m_Index) == SQLITE_NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
CSStr Column::GetName() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_CREATED_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_name(m_Handle->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
CSStr Column::GetOriginName() const
 | 
			
		||||
{
 | 
			
		||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
 | 
			
		||||
    VALIDATE_CREATED_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_origin_name(m_Handle->mPtr, m_Index);
 | 
			
		||||
#else
 | 
			
		||||
    STHROWF("The module was compiled without this feature");
 | 
			
		||||
    // Request failed
 | 
			
		||||
    return _SC("");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Column::GetType() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_CREATED_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_type(m_Handle->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Column::GetBytes() const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_CREATED_HND(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return sqlite3_column_bytes(m_Handle->mPtr, m_Index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ================================================================================================
 | 
			
		||||
void Register_Column(Table & sqlns)
 | 
			
		||||
{
 | 
			
		||||
@@ -431,6 +525,11 @@ void Register_Column(Table & sqlns)
 | 
			
		||||
        .Prop(_SC("Index"), &Column::GetIndex)
 | 
			
		||||
        .Prop(_SC("Statement"), &Column::GetNumber)
 | 
			
		||||
        .Prop(_SC("Connection"), &Column::GetConnection)
 | 
			
		||||
        .Prop(_SC("IsNull"), &Column::IsNull)
 | 
			
		||||
        .Prop(_SC("Name"), &Column::GetName)
 | 
			
		||||
        .Prop(_SC("OriginName"), &Column::GetOriginName)
 | 
			
		||||
        .Prop(_SC("Type"), &Column::GetType)
 | 
			
		||||
        .Prop(_SC("Bytes"), &Column::GetBytes)
 | 
			
		||||
        .Prop(_SC("Value"), &Column::GetValue)
 | 
			
		||||
        .Prop(_SC("Number"), &Column::GetNumber)
 | 
			
		||||
        .Prop(_SC("Integer"), &Column::GetInteger)
 | 
			
		||||
@@ -441,11 +540,6 @@ void Register_Column(Table & sqlns)
 | 
			
		||||
        .Prop(_SC("Char"), &Column::GetChar)
 | 
			
		||||
        .Prop(_SC("Buffer"), &Column::GetBuffer)
 | 
			
		||||
        .Prop(_SC("Blob"), &Column::GetBlob)
 | 
			
		||||
        .Prop(_SC("IsNull"), &Column::IsNull)
 | 
			
		||||
        .Prop(_SC("Name"), &Column::GetName)
 | 
			
		||||
        .Prop(_SC("OriginName"), &Column::GetOriginName)
 | 
			
		||||
        .Prop(_SC("Type"), &Column::GetType)
 | 
			
		||||
        .Prop(_SC("Bytes"), &Column::GetBytes)
 | 
			
		||||
        // Member Methods
 | 
			
		||||
        .Func(_SC("Release"), &Column::Release)
 | 
			
		||||
    );
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,6 @@ private:
 | 
			
		||||
 | 
			
		||||
    // --------------------------------------------------------------------------------------------
 | 
			
		||||
    Int32       m_Index; // The index of the managed column.
 | 
			
		||||
 | 
			
		||||
    // --------------------------------------------------------------------------------------------
 | 
			
		||||
    StmtRef     m_Handle; // The statement where the column exist.
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
@@ -61,6 +59,15 @@ protected:
 | 
			
		||||
    const StmtRef & GetCreated() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the statement reference and column index, and throw an error if they're invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void ValidateColumn(Int32 idx, CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void ValidateColumn(Int32 idx) const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the statement reference and row, and throw an error if they're invalid.
 | 
			
		||||
    */
 | 
			
		||||
@@ -71,14 +78,28 @@ protected:
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Base constructor.
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    Column(const StmtRef & stmt, Int32 idx)
 | 
			
		||||
        : m_Index(idx), m_Handle(stmt)
 | 
			
		||||
    void SetIndex(Int32 idx)
 | 
			
		||||
    {
 | 
			
		||||
        /* ... */
 | 
			
		||||
        SQMOD_VALIDATE_COLUMN(*this, idx);
 | 
			
		||||
        // Assign the new index
 | 
			
		||||
        m_Index = idx;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    void SetIndex(CSStr name)
 | 
			
		||||
    {
 | 
			
		||||
        SetIndex(SQMOD_GET_CREATED(*this)->GetColumnIndex(name));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    void SetIndex(const Object & column);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -90,6 +111,47 @@ public:
 | 
			
		||||
        /* ... */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * No column constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Column(const StmtRef & stmt)
 | 
			
		||||
        : m_Index(-1), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        /* ... */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Index constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Column(const StmtRef & stmt, Int32 idx)
 | 
			
		||||
        : m_Index(idx), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_COLUMN(*this, m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Name constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Column(const StmtRef & stmt, CSStr name)
 | 
			
		||||
        : m_Index(stmt ? stmt->GetColumnIndex(name) : -1), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_COLUMN(*this, m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Dynamic constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Column(const StmtRef & stmt, const Object & column)
 | 
			
		||||
        : m_Index(-1), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        if (!m_Handle)
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("Invalid SQLite statement reference");
 | 
			
		||||
        }
 | 
			
		||||
        // Extract the index
 | 
			
		||||
        SetIndex(column);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Copy constructor.
 | 
			
		||||
    */
 | 
			
		||||
@@ -111,7 +173,7 @@ public:
 | 
			
		||||
    Column & operator = (Column && o) = default;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Perform an equality comparison between two connection handles.
 | 
			
		||||
     * Perform an equality comparison between two table column indexes.
 | 
			
		||||
    */
 | 
			
		||||
    bool operator == (const Column & o) const
 | 
			
		||||
    {
 | 
			
		||||
@@ -119,7 +181,7 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Perform an inequality comparison between two connection handles.
 | 
			
		||||
     * Perform an inequality comparison between two table column indexes.
 | 
			
		||||
    */
 | 
			
		||||
    bool operator != (const Column & o) const
 | 
			
		||||
    {
 | 
			
		||||
@@ -139,11 +201,11 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 Cmp(const Column & o) const
 | 
			
		||||
    {
 | 
			
		||||
        if (m_Handle.Get() == o.m_Handle.Get())
 | 
			
		||||
        if (m_Index == o.m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else if (m_Handle.Get() > o.m_Handle.Get())
 | 
			
		||||
        else if (m_Index > o.m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
@@ -158,7 +220,18 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    CSStr ToString() const
 | 
			
		||||
    {
 | 
			
		||||
        return FmtStr(_SC("%d"), m_Index);
 | 
			
		||||
        CSStr val = nullptr;
 | 
			
		||||
        // Can we attempt to return the parameter name?
 | 
			
		||||
        if (m_Handle && m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            val = sqlite3_column_name(m_Handle->mPtr, m_Index);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            val = ToStrF(_SC("%d"), m_Index);
 | 
			
		||||
        }
 | 
			
		||||
        // Return the value if valid
 | 
			
		||||
        return val ? val : _SC("");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -183,7 +256,7 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated column index.
 | 
			
		||||
     * Retrieve the referenced column index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetIndex() const
 | 
			
		||||
    {
 | 
			
		||||
@@ -191,17 +264,17 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated database statement.
 | 
			
		||||
     * Retrieve the referenced database statement.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetStatement() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated database connection.
 | 
			
		||||
     * Retrieve the referenced database connection.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetConnection() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Release the reference to the associated database statement and index.
 | 
			
		||||
     * Release the reference to the referenced database statement and column index.
 | 
			
		||||
    */
 | 
			
		||||
    void Release()
 | 
			
		||||
    {
 | 
			
		||||
@@ -210,62 +283,12 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a dynamic type.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetValue() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a numeric type.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetNumber() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a native script integer.
 | 
			
		||||
    */
 | 
			
		||||
    SQInteger GetInteger() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a native script floating point.
 | 
			
		||||
    */
 | 
			
		||||
    SQFloat GetFloat() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a long integer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetLong() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a string.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetString() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a boolean.
 | 
			
		||||
    */
 | 
			
		||||
    bool GetBoolean() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a character.
 | 
			
		||||
    */
 | 
			
		||||
    SQChar GetChar() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a memory buffer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBuffer() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the associated column cel as a memory blob.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBlob() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether the associated column is null.
 | 
			
		||||
     * Check whether the referenced column is null.
 | 
			
		||||
    */
 | 
			
		||||
    bool IsNull() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the name of the associated column index.
 | 
			
		||||
     * Retrieve the name of the referenced column index.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetName() const;
 | 
			
		||||
 | 
			
		||||
@@ -275,14 +298,64 @@ public:
 | 
			
		||||
    CSStr GetOriginName() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the type identifier of the associated column index.
 | 
			
		||||
     * Retrieve the type identifier of the referenced column index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetType() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the size in bytes of the associated column index.
 | 
			
		||||
     * Retrieve the size in bytes of the referenced column index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetBytes() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a dynamic type.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetValue() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a numeric type.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetNumber() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a native script integer.
 | 
			
		||||
    */
 | 
			
		||||
    SQInteger GetInteger() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a native script floating point.
 | 
			
		||||
    */
 | 
			
		||||
    SQFloat GetFloat() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a long integer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetLong() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a string.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetString() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a boolean.
 | 
			
		||||
    */
 | 
			
		||||
    bool GetBoolean() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a character.
 | 
			
		||||
    */
 | 
			
		||||
    SQChar GetChar() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a memory buffer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBuffer() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a memory blob.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBlob() const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // Namespace:: SqMod
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include "Common.hpp"
 | 
			
		||||
#include "Handle/Connection.hpp"
 | 
			
		||||
#include "Connection.hpp"
 | 
			
		||||
#include "Statement.hpp"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
@@ -10,6 +11,18 @@
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
namespace SqMod {
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object GetConnectionObj(const ConnRef & conn)
 | 
			
		||||
{
 | 
			
		||||
    return Object(new Connection(conn));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object GetStatementObj(const StmtRef & stmt)
 | 
			
		||||
{
 | 
			
		||||
    return Object(new Statement(stmt));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
CSStr QFmtStr(CSStr str, ...)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -35,25 +35,23 @@ class Transaction;
 | 
			
		||||
 * Handle validation.
 | 
			
		||||
*/
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    #define VALIDATE_HND(x) (x).Validate(__FILE__, __LINE__)
 | 
			
		||||
    #define VALIDATE_OPENED_HND(x) (x).ValidateOpened(__FILE__, __LINE__)
 | 
			
		||||
    #define VALIDATE_CREATED_HND(x) (x).ValidateCreated(__FILE__, __LINE__)
 | 
			
		||||
    #define VALIDATE_COLUMN_HND(x, i) (x).ValidateColumn((i), __FILE__, __LINE__)
 | 
			
		||||
    #define VALIDATE_PARAMETER_HND(x, i) (x).ValidateParameter((i), __FILE__, __LINE__)
 | 
			
		||||
    #define VALIDATE_ROW_HND(x) (x).ValidateRow(__FILE__, __LINE__)
 | 
			
		||||
    #define GET_VALID_HND(x) (x).GetValid(__FILE__, __LINE__)
 | 
			
		||||
    #define GET_OPENED_HND(x) (x).GetOpened(__FILE__, __LINE__)
 | 
			
		||||
    #define GET_CREATED_HND(x) (x).GetCreated(__FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_THROW_CURRENT(x, a)       (x).ThrowCurrent(a, __FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_VALIDATE(x)               (x).Validate(__FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_VALIDATE_CREATED(x)       (x).ValidateCreated(__FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_VALIDATE_PARAM(x, i)      (x).ValidateParam((i), __FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_VALIDATE_COLUMN(x, i)     (x).ValidateColumn((i), __FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_VALIDATE_ROW(x)           (x).ValidateRow(__FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_GET_VALID(x)              (x).GetValid(__FILE__, __LINE__)
 | 
			
		||||
    #define SQMOD_GET_CREATED(x)            (x).GetCreated(__FILE__, __LINE__)
 | 
			
		||||
#else
 | 
			
		||||
    #define VALIDATE_HND(x) (x).Validate()
 | 
			
		||||
    #define VALIDATE_OPENED_HND(x) (x).ValidateOpened()
 | 
			
		||||
    #define VALIDATE_CREATED_HND(x) (x).ValidateCreated()
 | 
			
		||||
    #define VALIDATE_COLUMN_HND(x, i) (x).ValidateColumn((i))
 | 
			
		||||
    #define VALIDATE_PARAMETER_HND(x, i) (x).ValidateParameter((i))
 | 
			
		||||
    #define VALIDATE_ROW_HND(x) (x).ValidateRow()
 | 
			
		||||
    #define GET_VALID_HND(x) (x).GetValid()
 | 
			
		||||
    #define GET_OPENED_HND(x) (x).GetOpened()
 | 
			
		||||
    #define GET_CREATED_HND(x) (x).GetCreated()
 | 
			
		||||
    #define SQMOD_THROW_CURRENT(x, a)       (x).ThrowCurrent(a)
 | 
			
		||||
    #define SQMOD_VALIDATE(x)               (x).Validate()
 | 
			
		||||
    #define SQMOD_VALIDATE_CREATED(x)       (x).ValidateCreated()
 | 
			
		||||
    #define SQMOD_VALIDATE_PARAM(x, i)      (x).ValidateParam((i))
 | 
			
		||||
    #define SQMOD_VALIDATE_COLUMN(x, i)     (x).ValidateColumn((i))
 | 
			
		||||
    #define SQMOD_VALIDATE_ROW(x)           (x).ValidateRow()
 | 
			
		||||
    #define SQMOD_GET_VALID(x)              (x).GetValid()
 | 
			
		||||
    #define SQMOD_GET_CREATED(x)            (x).GetCreated()
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -80,6 +78,16 @@ struct StmtHnd;
 | 
			
		||||
typedef SharedPtr< ConnHnd > ConnRef;
 | 
			
		||||
typedef SharedPtr< StmtHnd > StmtRef;
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
 * Obtain a script object from a connection handle. (meant to avoid having to include the header)
 | 
			
		||||
*/
 | 
			
		||||
Object GetConnectionObj(const ConnRef & conn);
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
 * Obtain a script object from a statement handle. (meant to avoid having to include the header)
 | 
			
		||||
*/
 | 
			
		||||
Object GetStatementObj(const StmtRef & stmt);
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
 * Generate a formatted query.
 | 
			
		||||
*/
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ void Connection::Validate() const
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Connection::ValidateOpened(CCStr file, Int32 line) const
 | 
			
		||||
void Connection::ValidateCreated(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
@@ -58,7 +58,7 @@ void Connection::ValidateOpened(CCStr file, Int32 line) const
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void Connection::ValidateOpened() const
 | 
			
		||||
void Connection::ValidateCreated() const
 | 
			
		||||
{
 | 
			
		||||
    if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
@@ -88,15 +88,15 @@ const ConnRef & Connection::GetValid() const
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
const ConnRef & Connection::GetOpened(CCStr file, Int32 line) const
 | 
			
		||||
const ConnRef & Connection::GetCreated(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateOpened(file, line);
 | 
			
		||||
    ValidateCreated(file, line);
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
const ConnRef & Connection::GetOpened() const
 | 
			
		||||
const ConnRef & Connection::GetCreated() const
 | 
			
		||||
{
 | 
			
		||||
    ValidateOpened();
 | 
			
		||||
    ValidateCreated();
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
@@ -110,7 +110,7 @@ void Connection::Open(CSStr name)
 | 
			
		||||
        m_Handle = ConnRef(new ConnHnd());
 | 
			
		||||
    }
 | 
			
		||||
    // Make sure another database isn't opened
 | 
			
		||||
    if (GET_VALID_HND(*this)->mPtr != nullptr)
 | 
			
		||||
    if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Already referencing a valid database connection");
 | 
			
		||||
    }
 | 
			
		||||
@@ -127,7 +127,7 @@ void Connection::Open(CSStr name, Int32 flags)
 | 
			
		||||
        m_Handle = ConnRef(new ConnHnd());
 | 
			
		||||
    }
 | 
			
		||||
    // Make sure another database isn't opened
 | 
			
		||||
    if (GET_VALID_HND(*this)->mPtr != nullptr)
 | 
			
		||||
    if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Already referencing a valid database connection");
 | 
			
		||||
    }
 | 
			
		||||
@@ -144,7 +144,7 @@ void Connection::Open(CSStr name, Int32 flags, CSStr vfs)
 | 
			
		||||
        m_Handle = ConnRef(new ConnHnd());
 | 
			
		||||
    }
 | 
			
		||||
    // Make sure another database isn't opened
 | 
			
		||||
    if (GET_VALID_HND(*this)->mPtr != nullptr)
 | 
			
		||||
    if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Already referencing a valid database connection");
 | 
			
		||||
    }
 | 
			
		||||
@@ -155,7 +155,7 @@ void Connection::Open(CSStr name, Int32 flags, CSStr vfs)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Connection::Exec(CSStr str)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to execute the specified query
 | 
			
		||||
    m_Handle->mStatus = sqlite3_exec(m_Handle->mPtr, str, nullptr, nullptr, nullptr);
 | 
			
		||||
    // Validate the execution result
 | 
			
		||||
@@ -170,7 +170,7 @@ Int32 Connection::Exec(CSStr str)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Connection::Query(CSStr str) const
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Return the requested information
 | 
			
		||||
    return Object(new Statement(m_Handle, str));
 | 
			
		||||
}
 | 
			
		||||
@@ -178,7 +178,7 @@ Object Connection::Query(CSStr str) const
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Connection::Queue(CSStr str)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE(*this);
 | 
			
		||||
    // Is there a query to commit?
 | 
			
		||||
    if (IsQueryEmpty(str))
 | 
			
		||||
    {
 | 
			
		||||
@@ -192,7 +192,7 @@ void Connection::Queue(CSStr str)
 | 
			
		||||
bool Connection::IsReadOnly() const
 | 
			
		||||
{
 | 
			
		||||
    // Request the desired information
 | 
			
		||||
    const int result = sqlite3_db_readonly(GET_OPENED_HND(*this)->mPtr, "main");
 | 
			
		||||
    const int result = sqlite3_db_readonly(SQMOD_GET_CREATED(*this)->mPtr, "main");
 | 
			
		||||
    // Verify the result
 | 
			
		||||
    if (result == -1)
 | 
			
		||||
    {
 | 
			
		||||
@@ -206,12 +206,12 @@ bool Connection::IsReadOnly() const
 | 
			
		||||
bool Connection::TableExists(CCStr name) const
 | 
			
		||||
{
 | 
			
		||||
    // Prepare a statement to inspect the master table
 | 
			
		||||
    Statement stmt(GET_OPENED_HND(*this), "SELECT count(*) FROM [sqlite_master] WHERE [type]='table' AND [name]=?");
 | 
			
		||||
    Statement stmt(SQMOD_GET_CREATED(*this), "SELECT count(*) FROM [sqlite_master] WHERE [type]='table' AND [name]=?");
 | 
			
		||||
    // Could the statement be created?
 | 
			
		||||
    if (stmt.IsValid())
 | 
			
		||||
    {
 | 
			
		||||
        // Bind the specified name onto the statement parameter
 | 
			
		||||
        stmt.IndexBindString(1, name);
 | 
			
		||||
        Parameter(stmt.GetHandle(), 1).SetString(name);
 | 
			
		||||
        // Attempt to step the statement and obtain a value
 | 
			
		||||
        if (stmt.Step())
 | 
			
		||||
        {
 | 
			
		||||
@@ -226,7 +226,7 @@ bool Connection::TableExists(CCStr name) const
 | 
			
		||||
void Connection::SetTracing(bool toggle)
 | 
			
		||||
{
 | 
			
		||||
    // Check whether changes are necessary
 | 
			
		||||
    if (GET_OPENED_HND(*this)->mTrace == toggle)
 | 
			
		||||
    if (SQMOD_GET_CREATED(*this)->mTrace == toggle)
 | 
			
		||||
    {
 | 
			
		||||
        return; // No point in proceeding
 | 
			
		||||
    }
 | 
			
		||||
@@ -246,7 +246,7 @@ void Connection::SetTracing(bool toggle)
 | 
			
		||||
void Connection::SetProfiling(bool toggle)
 | 
			
		||||
{
 | 
			
		||||
    // Check whether changes are necessary
 | 
			
		||||
    if (GET_OPENED_HND(*this)->mProfile == toggle)
 | 
			
		||||
    if (SQMOD_GET_CREATED(*this)->mProfile == toggle)
 | 
			
		||||
    {
 | 
			
		||||
        return; // No point in proceeding
 | 
			
		||||
    }
 | 
			
		||||
@@ -265,7 +265,7 @@ void Connection::SetProfiling(bool toggle)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Connection::SetBusyTimeout(Int32 millis)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Apply the requested timeout
 | 
			
		||||
    if ((m_Handle->mStatus = sqlite3_busy_timeout(m_Handle->mPtr, millis)) != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
@@ -280,7 +280,7 @@ Int32 Connection::GetInfo(Int32 operation, bool highwater, bool reset)
 | 
			
		||||
    Int32 cur_value;
 | 
			
		||||
    Int32 hiwtr_value;
 | 
			
		||||
    // Attempt to retrieve the specified information
 | 
			
		||||
    if ((m_Handle->mStatus = sqlite3_db_status(GET_OPENED_HND(*this)->mPtr, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
 | 
			
		||||
    if ((m_Handle->mStatus = sqlite3_db_status(SQMOD_GET_CREATED(*this)->mPtr, operation, &cur_value, &hiwtr_value, reset)) != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Unable to get runtime status information", m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
@@ -296,7 +296,7 @@ Int32 Connection::GetInfo(Int32 operation, bool highwater, bool reset)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Connection::ReserveQueue(Uint32 num)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    m_Handle->mQueue.reserve(m_Handle->mQueue.size() + num);
 | 
			
		||||
}
 | 
			
		||||
@@ -304,9 +304,9 @@ void Connection::ReserveQueue(Uint32 num)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Connection::PopQueue()
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    if (!GET_VALID_HND(*this)->mQueue.empty())
 | 
			
		||||
    if (!SQMOD_GET_VALID(*this)->mQueue.empty())
 | 
			
		||||
    {
 | 
			
		||||
        m_Handle->mQueue.pop_back();
 | 
			
		||||
    }
 | 
			
		||||
@@ -315,7 +315,7 @@ void Connection::PopQueue()
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Connection::Flush()
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    return m_Handle->Flush(m_Handle->mQueue.size(), NullObject(), NullFunction());
 | 
			
		||||
}
 | 
			
		||||
@@ -323,7 +323,7 @@ Int32 Connection::Flush()
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Connection::Flush(SQInteger num)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    return m_Handle->Flush(ConvTo< Uint32 >::From(num), NullObject(), NullFunction());
 | 
			
		||||
}
 | 
			
		||||
@@ -331,7 +331,7 @@ Int32 Connection::Flush(SQInteger num)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Connection::Flush(Object & env, Function & func)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    return m_Handle->Flush(m_Handle->mQueue.size(), env, func);
 | 
			
		||||
}
 | 
			
		||||
@@ -339,7 +339,7 @@ Int32 Connection::Flush(Object & env, Function & func)
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Int32 Connection::Flush(SQInteger num, Object & env, Function & func)
 | 
			
		||||
{
 | 
			
		||||
    VALIDATE_OPENED_HND(*this);
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    return m_Handle->Flush(ConvTo< Uint32 >::From(num), env, func);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -49,9 +49,9 @@ protected:
 | 
			
		||||
     * Validate the managed connection handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void ValidateOpened(CCStr file, Int32 line) const;
 | 
			
		||||
    void ValidateCreated(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void ValidateOpened() const;
 | 
			
		||||
    void ValidateCreated() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -67,9 +67,9 @@ protected:
 | 
			
		||||
     * Validate the managed connection handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    const ConnRef & GetOpened(CCStr file, Int32 line) const;
 | 
			
		||||
    const ConnRef & GetCreated(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    const ConnRef & GetOpened() const;
 | 
			
		||||
    const ConnRef & GetCreated() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
@@ -89,7 +89,7 @@ public:
 | 
			
		||||
    Connection(CSStr name)
 | 
			
		||||
        : m_Handle(new ConnHnd())
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->Create(name, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
 | 
			
		||||
        SQMOD_GET_VALID(*this)->Create(name, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -98,7 +98,7 @@ public:
 | 
			
		||||
    Connection(CSStr name, Int32 flags)
 | 
			
		||||
        : m_Handle(new ConnHnd())
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->Create(name, flags, nullptr);
 | 
			
		||||
        SQMOD_GET_VALID(*this)->Create(name, flags, nullptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -107,7 +107,7 @@ public:
 | 
			
		||||
    Connection(CSStr name, Int32 flags, CSStr vfs)
 | 
			
		||||
        : m_Handle(new ConnHnd())
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->Create(name, flags, vfs);
 | 
			
		||||
        SQMOD_GET_VALID(*this)->Create(name, flags, vfs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -248,7 +248,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetStatus() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mStatus;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mStatus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -256,7 +256,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetFlags() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mFlags;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mFlags;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -264,7 +264,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    const String & GetName() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mName;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -272,7 +272,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    const String GetVFS() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mVFS;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mVFS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -280,7 +280,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetErrorCode() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrNo();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrNo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -288,7 +288,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetExtendedErrorCode() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ExErrNo();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ExErrNo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -296,7 +296,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetErrStr() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrStr();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrStr();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -304,7 +304,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetErrMsg() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrMsg();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrMsg();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -352,7 +352,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetAutoCommit() const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_get_autocommit(GET_OPENED_HND(*this)->mPtr);
 | 
			
		||||
        return sqlite3_get_autocommit(SQMOD_GET_CREATED(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -360,7 +360,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Object GetLastInsertRowID() const
 | 
			
		||||
    {
 | 
			
		||||
        return MakeSLongObj(sqlite3_last_insert_rowid(GET_OPENED_HND(*this)->mPtr));
 | 
			
		||||
        return MakeSLongObj(sqlite3_last_insert_rowid(SQMOD_GET_CREATED(*this)->mPtr));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -369,7 +369,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetChanges() const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_changes(GET_OPENED_HND(*this)->mPtr);
 | 
			
		||||
        return sqlite3_changes(SQMOD_GET_CREATED(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -378,7 +378,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetTotalChanges() const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_total_changes(GET_OPENED_HND(*this)->mPtr);
 | 
			
		||||
        return sqlite3_total_changes(SQMOD_GET_CREATED(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -386,7 +386,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetTracing() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mTrace;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mTrace;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -399,7 +399,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetProfiling() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mProfile;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mProfile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -417,7 +417,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    void InterruptOperation() const
 | 
			
		||||
    {
 | 
			
		||||
        sqlite3_interrupt(GET_OPENED_HND(*this)->mPtr);
 | 
			
		||||
        sqlite3_interrupt(SQMOD_GET_CREATED(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -425,7 +425,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    void ReleaseMemory() const
 | 
			
		||||
    {
 | 
			
		||||
        sqlite3_db_release_memory(GET_OPENED_HND(*this)->mPtr);
 | 
			
		||||
        sqlite3_db_release_memory(SQMOD_GET_CREATED(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -454,7 +454,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Uint32 QueueSize() const
 | 
			
		||||
    {
 | 
			
		||||
        return ConvTo< Uint32 >::From(GET_VALID_HND(*this)->mQueue.size());
 | 
			
		||||
        return ConvTo< Uint32 >::From(SQMOD_GET_VALID(*this)->mQueue.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -467,7 +467,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    void CompactQueue()
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->mQueue.shrink_to_fit();
 | 
			
		||||
        SQMOD_GET_VALID(*this)->mQueue.shrink_to_fit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -475,7 +475,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    void ClearQueue()
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->mQueue.clear();
 | 
			
		||||
        SQMOD_GET_VALID(*this)->mQueue.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
 
 | 
			
		||||
@@ -179,6 +179,7 @@ extern void Register_Constants(Table & sqlns);
 | 
			
		||||
extern void Register_Common(Table & sqlns);
 | 
			
		||||
extern void Register_Connection(Table & sqlns);
 | 
			
		||||
extern void Register_Statement(Table & sqlns);
 | 
			
		||||
extern void Register_Parameter(Table & sqlns);
 | 
			
		||||
extern void Register_Column(Table & sqlns);
 | 
			
		||||
extern void Register_Transaction(Table & sqlns);
 | 
			
		||||
 | 
			
		||||
@@ -191,6 +192,7 @@ void RegisterAPI(HSQUIRRELVM vm)
 | 
			
		||||
    Register_Common(sqlns);
 | 
			
		||||
    Register_Connection(sqlns);
 | 
			
		||||
    Register_Statement(sqlns);
 | 
			
		||||
    Register_Parameter(sqlns);
 | 
			
		||||
    Register_Column(sqlns);
 | 
			
		||||
    Register_Transaction(sqlns);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										835
									
								
								modules/sqlite/Parameter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										835
									
								
								modules/sqlite/Parameter.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,835 @@
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include "Parameter.hpp"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include <ctime>
 | 
			
		||||
#include <cerrno>
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
namespace SqMod {
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
// Error message when failed to bind value to parameter index.
 | 
			
		||||
#define SQMOD_BINDFAILED "Unable to bind (%s) parameter (%d) because [%s]"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
static inline bool IsDigitsOnly(CSStr str)
 | 
			
		||||
{
 | 
			
		||||
    while (std::isdigit(*str) || std::isspace(*str))
 | 
			
		||||
    {
 | 
			
		||||
        ++str;
 | 
			
		||||
    }
 | 
			
		||||
    // Return whether we reached the end while searching
 | 
			
		||||
    return *str == '\0';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQInteger Parameter::Typename(HSQUIRRELVM vm)
 | 
			
		||||
{
 | 
			
		||||
    static const SQChar name[] = _SC("SqSQLiteParameter");
 | 
			
		||||
    sq_pushstring(vm, name, sizeof(name));
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Parameter::Validate(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    // Are we pointing to a valid index?
 | 
			
		||||
    if (m_Index < 0)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid column index: %d < 0 =>[%s:%d]", m_Index, file, line);
 | 
			
		||||
    }
 | 
			
		||||
    // Do we have a valid statement handle?
 | 
			
		||||
    else if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement reference =>[%s:%d]", file, line);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void Parameter::Validate() const
 | 
			
		||||
{
 | 
			
		||||
    // Are we pointing to a valid index?
 | 
			
		||||
    if (m_Index < 0)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid column index: %d < 0", m_Index);
 | 
			
		||||
    }
 | 
			
		||||
    // Do we have a valid statement handle?
 | 
			
		||||
    else if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement reference");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Parameter::ValidateCreated(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    // Are we pointing to a valid index?
 | 
			
		||||
    if (m_Index < 0)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid column index: %d < 0 =>[%s:%d]", m_Index, file, line);
 | 
			
		||||
    }
 | 
			
		||||
    else if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement reference =>[%s:%d]", file, line);
 | 
			
		||||
    }
 | 
			
		||||
    else if (m_Handle->mPtr == nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement =>[%s:%d]", file, line);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void Parameter::ValidateCreated() const
 | 
			
		||||
{
 | 
			
		||||
    // Are we pointing to a valid index?
 | 
			
		||||
    if (m_Index < 0)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid column index: %d < 0", m_Index);
 | 
			
		||||
    }
 | 
			
		||||
    else if (!m_Handle)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement reference");
 | 
			
		||||
    }
 | 
			
		||||
    else if (m_Handle->mPtr == nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Invalid SQLite statement");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
const StmtRef & Parameter::GetValid(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    Validate(file, line);
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
const StmtRef & Parameter::GetValid() const
 | 
			
		||||
{
 | 
			
		||||
    Validate();
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
const StmtRef & Parameter::GetCreated(CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated(file, line);
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
const StmtRef & Parameter::GetCreated() const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated();
 | 
			
		||||
    return m_Handle;
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
void Parameter::ValidateParam(Int32 idx, CCStr file, Int32 line) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated(file, line);
 | 
			
		||||
    // Is the specified index in range?
 | 
			
		||||
    if (!m_Handle->CheckParameter(idx))
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Parameter index is out of range (%d:%d) =>[%s:%d]", idx, m_Handle->mParameters,
 | 
			
		||||
                    file, line);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void Parameter::ValidateParam(Int32 idx) const
 | 
			
		||||
{
 | 
			
		||||
    ValidateCreated();
 | 
			
		||||
    // Is the specified index in range?
 | 
			
		||||
    if (!m_Handle->CheckParameter(idx))
 | 
			
		||||
    {
 | 
			
		||||
        SqThrowF("Parameter index is out of range (%d:%d)", idx, m_Handle->mParameters);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetIndex(const Object & param)
 | 
			
		||||
{
 | 
			
		||||
    // Where the index will be extracted
 | 
			
		||||
    Int32 idx = 0;
 | 
			
		||||
    // Grab the object virtual machine
 | 
			
		||||
    HSQUIRRELVM vm = param.GetVM();
 | 
			
		||||
    // Remember the current stack size
 | 
			
		||||
    const StackGuard sg(vm);
 | 
			
		||||
    // Push the specified object onto the stack
 | 
			
		||||
    Var< const Object & >::push(vm, param);
 | 
			
		||||
    // Identify the type of parameter was given
 | 
			
		||||
    switch  (param.GetType())
 | 
			
		||||
    {
 | 
			
		||||
        // Is this a string value?
 | 
			
		||||
        case OT_STRING:
 | 
			
		||||
        {
 | 
			
		||||
            // Obtain the object from the stack as a string
 | 
			
		||||
            const StackStrF val(vm, -1, false);
 | 
			
		||||
            // Validate the result
 | 
			
		||||
            if (SQ_FAILED(val.mRes))
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("%s", LastErrorString(vm).c_str());
 | 
			
		||||
            }
 | 
			
		||||
            // Is the obtained string empty?
 | 
			
		||||
            else if (val.mLen <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("Cannot use an empty parameter name");
 | 
			
		||||
            }
 | 
			
		||||
            // Attempt to find a parameter with the specified name
 | 
			
		||||
            idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->mPtr, val.mPtr);
 | 
			
		||||
        } break;
 | 
			
		||||
        // Is this an integer value? (or at least can be easily converted to one)
 | 
			
		||||
        case OT_INTEGER:
 | 
			
		||||
        case OT_FLOAT:
 | 
			
		||||
        case OT_BOOL:
 | 
			
		||||
        {
 | 
			
		||||
            idx = ConvTo< Int32 >::From(SqMod_PopStackInteger(vm, -1));
 | 
			
		||||
        } break;
 | 
			
		||||
        // Is this an instance that we can extract either a string or integer from it?
 | 
			
		||||
        case OT_INSTANCE:
 | 
			
		||||
        {
 | 
			
		||||
            // Obtain the object from the stack as a string
 | 
			
		||||
            const StackStrF val(vm, -1, false);
 | 
			
		||||
            // Validate the result
 | 
			
		||||
            if (SQ_FAILED(val.mRes))
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("%s", LastErrorString(vm).c_str());
 | 
			
		||||
            }
 | 
			
		||||
            // Is the obtained string empty?
 | 
			
		||||
            else if (val.mLen <= 0)
 | 
			
		||||
            {
 | 
			
		||||
                STHROWF("Cannot use an empty parameter name");
 | 
			
		||||
            }
 | 
			
		||||
            // Check if this value is made only of digits
 | 
			
		||||
            else if (IsDigitsOnly(val.mPtr))
 | 
			
		||||
            {
 | 
			
		||||
                idx = ConvNum< Int32 >::FromStr(val.mPtr);
 | 
			
		||||
            }
 | 
			
		||||
            // Attempt to find a parameter with the specified name
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->mPtr, val.mPtr);
 | 
			
		||||
            }
 | 
			
		||||
        } break;
 | 
			
		||||
        // We don't recognize this kind of value!
 | 
			
		||||
        default: STHROWF("Unknown parameter index of type (%s)", SqTypeName(param.GetType()));
 | 
			
		||||
    }
 | 
			
		||||
    // Validate the obtained parameter index
 | 
			
		||||
    SQMOD_VALIDATE_PARAM(*this, idx);
 | 
			
		||||
    // Assign the new index
 | 
			
		||||
    m_Index = idx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Parameter::GetStatement() const
 | 
			
		||||
{
 | 
			
		||||
    return GetStatementObj(m_Handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
Object Parameter::GetConnection() const
 | 
			
		||||
{
 | 
			
		||||
    return GetConnectionObj(SQMOD_GET_VALID(*this)->mConn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetValue(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    switch (value.GetType())
 | 
			
		||||
    {
 | 
			
		||||
        case OT_NULL:
 | 
			
		||||
        {
 | 
			
		||||
            SetNull();
 | 
			
		||||
        } break;
 | 
			
		||||
        case OT_INTEGER:
 | 
			
		||||
        {
 | 
			
		||||
            SetInteger(value.Cast< SQInteger >());
 | 
			
		||||
        } break;
 | 
			
		||||
        case OT_FLOAT:
 | 
			
		||||
        {
 | 
			
		||||
            SetFloat(value.Cast< SQFloat >());
 | 
			
		||||
        } break;
 | 
			
		||||
        case OT_BOOL:
 | 
			
		||||
        {
 | 
			
		||||
            SetBool(value.Cast< bool >());
 | 
			
		||||
        } break;
 | 
			
		||||
        case OT_STRING:
 | 
			
		||||
        {
 | 
			
		||||
            SetString(value.Cast< CSStr >());
 | 
			
		||||
        } break;
 | 
			
		||||
        default: STHROWF("No known conversion for the specified value type");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetBool(bool value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, value);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "bool", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetChar(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< SQChar >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "char", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetInteger(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_integer(m_Handle->mPtr, m_Index, value);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "integer", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetInt8(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Int8 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "int8", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetUint8(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Uint8 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "uint8", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetInt16(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Int16 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "int16", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetUint16(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Uint16 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "uint16", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetInt32(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Int32 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "int32", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetUint32(SQInteger value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< Uint32 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "uint32", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetInt64(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int64(m_Handle->mPtr, m_Index, FetchSLongObjVal(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "int64", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetUint64(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int64(m_Handle->mPtr, m_Index,
 | 
			
		||||
                                            static_cast< Int64 >(FetchULongObjVal(value)));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "uint64", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetFloat(SQFloat value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, value);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "float", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetFloat32(SQFloat value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, ConvTo< Float32 >::From(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "float32", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetFloat64(SQFloat value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, value);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "float64", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetString(CSStr value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, value, -1, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "string", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetStringEx(CSStr value, Int32 length)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, value, length, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "string", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetZeroBlob(SQInteger size)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_zeroblob(m_Handle->mPtr, m_Index, ConvTo< Int32 >::From(size));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "blob", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetBlob(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // The blob data pointer and size
 | 
			
		||||
    SQUserPointer ptr = 0;
 | 
			
		||||
    SQInteger len = 0;
 | 
			
		||||
    // Grab the associated object virtual machine
 | 
			
		||||
    HSQUIRRELVM vm = value.GetVM();
 | 
			
		||||
    // Extract the blob data from the specified object
 | 
			
		||||
    {
 | 
			
		||||
        // Remember the current stack size
 | 
			
		||||
        const StackGuard sg(vm);
 | 
			
		||||
        // Push the specified object onto the stack
 | 
			
		||||
        Var< const Object & >::push(vm, value);
 | 
			
		||||
        // Grab the blob data pointer
 | 
			
		||||
        if (SQ_FAILED(sqstd_getblob(vm, -1, &ptr)))
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("Unable to obtain the blob data");
 | 
			
		||||
        }
 | 
			
		||||
        // Grab the blob data size
 | 
			
		||||
        len = sqstd_getblobsize(vm, -1);
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_blob(m_Handle->mPtr, m_Index, ptr, len, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "blob", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetData(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // The buffer data pointer and size
 | 
			
		||||
    CCStr ptr = 0;
 | 
			
		||||
    SQInteger len = 0;
 | 
			
		||||
    // Grab the associated object virtual machine
 | 
			
		||||
    HSQUIRRELVM vm = value.GetVM();
 | 
			
		||||
    // Extract the buffer data from the specified object
 | 
			
		||||
    {
 | 
			
		||||
        // Remember the current stack size
 | 
			
		||||
        const StackGuard sg(vm);
 | 
			
		||||
        // Push the specified object onto the stack
 | 
			
		||||
        Var< const Object & >::push(vm, value);
 | 
			
		||||
        // Grab the buffer data pointer and size
 | 
			
		||||
        if (SQ_FAILED(SqMod_GetBufferInfo(vm, -1, &ptr, &len, nullptr)))
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("Unable to obtain the buffer data");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_blob(m_Handle->mPtr, m_Index, ptr, len, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "buffer", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetDate(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to generate the specified date string
 | 
			
		||||
    CSStr ptr = FmtStr(_SC("%s 00:00:00"), FetchDateObjStr(value));
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, ptr, -1, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "date", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetDateEx(SQInteger year, SQInteger month, SQInteger day)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Convert the specified values within the proper ranges
 | 
			
		||||
    const uint16_t y = ConvTo< uint16_t >::From(year);
 | 
			
		||||
    const uint8_t m = ConvTo< uint8_t >::From(month), d = ConvTo< uint8_t >::From(day);
 | 
			
		||||
    // Validate the specified date
 | 
			
		||||
    if (!SqMod_ValidDate(y, m, d))
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Invalid date (%u-%u-%u)", y, m, d);
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to generate the specified date string
 | 
			
		||||
    CSStr ptr = FmtStr(_SC("%u-%u-%u 00:00:00"), y, m, d);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, ptr, -1, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "date", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetTime(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, FetchTimeObjSeconds(value));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "time", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetTimeEx(SQInteger hour, SQInteger minute, SQInteger second)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Convert the specified values within the proper ranges
 | 
			
		||||
    const uint8_t h = ConvTo< uint8_t >::From(hour)
 | 
			
		||||
                , m = ConvTo< uint8_t >::From(minute)
 | 
			
		||||
                , s = ConvTo< uint8_t >::From(second);
 | 
			
		||||
    // Is the specified hour within range?
 | 
			
		||||
    if (h >= 24)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Hour value is out of range: %u >= 24", h);
 | 
			
		||||
    }
 | 
			
		||||
    // Is the specified minute within range?
 | 
			
		||||
    else if (m >= 60)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Minute value is out of range: %u >= 60", m);
 | 
			
		||||
    }
 | 
			
		||||
    // Is the specified second within range?
 | 
			
		||||
    else if (s >= 60)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Second value is out of range: %u >= 60", s);
 | 
			
		||||
    }
 | 
			
		||||
    // Calculate the number of seconds in the specified time and bind the resulted value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, (h * (60 * 60)) + (m * 60) + s);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "time", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetDatetime(const Object & value)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to generate the specified date string and bind the resulted value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, FetchDatetimeObjStr(value),
 | 
			
		||||
                                            -1, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "date-time", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetDatetimeEx(SQInteger year, SQInteger month, SQInteger day, SQInteger hour, SQInteger minute, SQInteger second)
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Convert the specified values within the proper ranges
 | 
			
		||||
    const uint16_t y = ConvTo< uint16_t >::From(year);
 | 
			
		||||
    const uint8_t mo = ConvTo< uint8_t >::From(month)
 | 
			
		||||
                , d = ConvTo< uint8_t >::From(day)
 | 
			
		||||
                , h = ConvTo< uint8_t >::From(hour)
 | 
			
		||||
                , mi = ConvTo< uint8_t >::From(minute)
 | 
			
		||||
                , s = ConvTo< uint8_t >::From(second);
 | 
			
		||||
    // Validate the specified date
 | 
			
		||||
    if (!SqMod_ValidDate(y, mo, d))
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Invalid date (%u-%u-%u)", y, mo, d);
 | 
			
		||||
    }
 | 
			
		||||
    // Is the specified hour within range?
 | 
			
		||||
    else if (h >= 24)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Hour value is out of range: %u >= 24", h);
 | 
			
		||||
    }
 | 
			
		||||
    // Is the specified minute within range?
 | 
			
		||||
    else if (mi >= 60)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Minute value is out of range: %u >= 60", mi);
 | 
			
		||||
    }
 | 
			
		||||
    // Is the specified second within range?
 | 
			
		||||
    else if (s >= 60)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF("Second value is out of range: %u >= 60", s);
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to generate the specified date string
 | 
			
		||||
    CSStr ptr = FmtStr(_SC("%04u-%02u-%02u %02u:%02u:%02u"), y, mo, d, h, mi, s);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, ptr, -1, SQLITE_TRANSIENT);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "date-time", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetNow()
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index,
 | 
			
		||||
                                            static_cast< Int32 >(std::time(nullptr)));
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "time-stamp", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Parameter::SetNull()
 | 
			
		||||
{
 | 
			
		||||
    SQMOD_VALIDATE_CREATED(*this);
 | 
			
		||||
    // Attempt to bind the specified value
 | 
			
		||||
    m_Handle->mStatus = sqlite3_bind_null(m_Handle->mPtr, m_Index);
 | 
			
		||||
    // Validate the result
 | 
			
		||||
    if (m_Handle->mStatus != SQLITE_OK)
 | 
			
		||||
    {
 | 
			
		||||
        STHROWF(SQMOD_BINDFAILED, "null", m_Index, m_Handle->ErrMsg());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
SQInteger Parameter::SetStringF(HSQUIRRELVM vm)
 | 
			
		||||
{
 | 
			
		||||
    const Int32 top = sq_gettop(vm);
 | 
			
		||||
    // Was the parameter value specified?
 | 
			
		||||
    if (top <= 1)
 | 
			
		||||
    {
 | 
			
		||||
        return sq_throwerror(vm, "Missing parameter value");
 | 
			
		||||
    }
 | 
			
		||||
    // The parameter instance
 | 
			
		||||
    Parameter * param = nullptr;
 | 
			
		||||
    // Attempt to extract the argument values
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        param = Var< Parameter * >(vm, 1).value;
 | 
			
		||||
    }
 | 
			
		||||
    catch (const Sqrat::Exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        // Propagate the error
 | 
			
		||||
        return sq_throwerror(vm, e.what());
 | 
			
		||||
    }
 | 
			
		||||
    // Do we have a valid parameter instance?
 | 
			
		||||
    if (!param)
 | 
			
		||||
    {
 | 
			
		||||
        return sq_throwerror(vm, "Invalid SQLite parameter instance");
 | 
			
		||||
    }
 | 
			
		||||
    // Validate the parameter info
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_CREATED(*param);
 | 
			
		||||
    }
 | 
			
		||||
    catch (const Sqrat::Exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        // Propagate the error
 | 
			
		||||
        return sq_throwerror(vm, e.what());
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to retrieve the value from the stack as a string
 | 
			
		||||
    StackStrF val(vm, 2);
 | 
			
		||||
    // Have we failed to retrieve the string?
 | 
			
		||||
    if (SQ_FAILED(val.mRes))
 | 
			
		||||
    {
 | 
			
		||||
        return val.mRes; // Propagate the error!
 | 
			
		||||
    }
 | 
			
		||||
    // Attempt to bind the obtained string
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        param->SetStringEx(val.mPtr, val.mLen);
 | 
			
		||||
    }
 | 
			
		||||
    catch (const Sqrat::Exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        // Propagate the error
 | 
			
		||||
        return sq_throwerror(vm, e.what());
 | 
			
		||||
    }
 | 
			
		||||
    // This function does not return any value
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// ================================================================================================
 | 
			
		||||
void Register_Parameter(Table & sqlns)
 | 
			
		||||
{
 | 
			
		||||
    sqlns.Bind(_SC("Parameter"),
 | 
			
		||||
        Class< Parameter >(sqlns.GetVM(), _SC("SqSQLiteParameter"))
 | 
			
		||||
        // Constructors
 | 
			
		||||
        .Ctor()
 | 
			
		||||
        .Ctor< const Parameter & >()
 | 
			
		||||
        // Meta-methods
 | 
			
		||||
        .Func(_SC("_cmp"), &Parameter::Cmp)
 | 
			
		||||
        .SquirrelFunc(_SC("_typename"), &Parameter::Typename)
 | 
			
		||||
        .Func(_SC("_tostring"), &Parameter::ToString)
 | 
			
		||||
        // Properties
 | 
			
		||||
        .Prop(_SC("IsValid"), &Parameter::IsValid)
 | 
			
		||||
        .Prop(_SC("References"), &Parameter::GetRefCount)
 | 
			
		||||
        .Prop(_SC("Index"), &Parameter::GetIndex)
 | 
			
		||||
        .Prop(_SC("Statement"), &Parameter::GetStatement)
 | 
			
		||||
        .Prop(_SC("Connection"), &Parameter::GetConnection)
 | 
			
		||||
        .Prop(_SC("References"), &Parameter::GetRefCount)
 | 
			
		||||
        .Prop(_SC("Name"), &Parameter::GetName)
 | 
			
		||||
        // Member Methods
 | 
			
		||||
        .Func(_SC("Release"), &Parameter::Release)
 | 
			
		||||
        .Func(_SC("SetValue"), &Parameter::SetValue)
 | 
			
		||||
        .Func(_SC("SetBool"), &Parameter::SetBool)
 | 
			
		||||
        .Func(_SC("SetChar"), &Parameter::SetChar)
 | 
			
		||||
        .Func(_SC("SetInteger"), &Parameter::SetInteger)
 | 
			
		||||
        .Func(_SC("SetInt8"), &Parameter::SetInt8)
 | 
			
		||||
        .Func(_SC("SetUint8"), &Parameter::SetUint8)
 | 
			
		||||
        .Func(_SC("SetInt16"), &Parameter::SetInt16)
 | 
			
		||||
        .Func(_SC("SetUint16"), &Parameter::SetUint16)
 | 
			
		||||
        .Func(_SC("SetInt32"), &Parameter::SetInt32)
 | 
			
		||||
        .Func(_SC("SetUint32"), &Parameter::SetUint32)
 | 
			
		||||
        .Func(_SC("SetInt64"), &Parameter::SetInt64)
 | 
			
		||||
        .Func(_SC("SetUint64"), &Parameter::SetUint64)
 | 
			
		||||
        .Func(_SC("SetFloat"), &Parameter::SetFloat)
 | 
			
		||||
        .Func(_SC("SetFloat32"), &Parameter::SetFloat32)
 | 
			
		||||
        .Func(_SC("SetFloat64"), &Parameter::SetFloat64)
 | 
			
		||||
        .Func(_SC("SetString"), &Parameter::SetString)
 | 
			
		||||
        .Func(_SC("SetZeroBlob"), &Parameter::SetZeroBlob)
 | 
			
		||||
        .Func(_SC("SetBlob"), &Parameter::SetBlob)
 | 
			
		||||
        .Func(_SC("SetData"), &Parameter::SetData)
 | 
			
		||||
        .Func(_SC("SetDate"), &Parameter::SetDate)
 | 
			
		||||
        .Func(_SC("SetDateEx"), &Parameter::SetDateEx)
 | 
			
		||||
        .Func(_SC("SetTime"), &Parameter::SetTime)
 | 
			
		||||
        .Func(_SC("SetTimeEx"), &Parameter::SetTimeEx)
 | 
			
		||||
        .Func(_SC("SetDatetime"), &Parameter::SetDatetime)
 | 
			
		||||
        .Func(_SC("SetDatetimeEx"), &Parameter::SetDatetimeEx)
 | 
			
		||||
        .Func(_SC("SetNow"), &Parameter::SetNow)
 | 
			
		||||
        .Func(_SC("SetNull"), &Parameter::SetNull)
 | 
			
		||||
        // Squirrel Methods
 | 
			
		||||
        .SquirrelFunc(_SC("SetStringF"), &Parameter::SetStringF)
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // Namespace:: SqMod
 | 
			
		||||
							
								
								
									
										436
									
								
								modules/sqlite/Parameter.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										436
									
								
								modules/sqlite/Parameter.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,436 @@
 | 
			
		||||
#ifndef _SQSQLITE_PARAMETER_HPP_
 | 
			
		||||
#define _SQSQLITE_PARAMETER_HPP_
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include "Handle/Statement.hpp"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include <cctype>
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
namespace SqMod {
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
 * Used to manage and interact with parameters from a database statement.
 | 
			
		||||
*/
 | 
			
		||||
class Parameter
 | 
			
		||||
{
 | 
			
		||||
    // --------------------------------------------------------------------------------------------
 | 
			
		||||
    friend class Statement;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    // --------------------------------------------------------------------------------------------
 | 
			
		||||
    Int32       m_Index; // The index of the managed parameter.
 | 
			
		||||
    StmtRef     m_Handle; // Reference to the managed statement.
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the managed statement handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void Validate(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void Validate() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the managed statement handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void ValidateCreated(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void ValidateCreated() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the managed statement handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    const StmtRef & GetValid(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    const StmtRef & GetValid() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the managed statement handle and throw an error if invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    const StmtRef & GetCreated(CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    const StmtRef & GetCreated() const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Validate the statement reference and parameter index, and throw an error if they're invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void ValidateParam(Int32 idx, CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void ValidateParam(Int32 idx) const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    void SetIndex(Int32 idx)
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_PARAM(*this, idx);
 | 
			
		||||
        // Assign the new index
 | 
			
		||||
        m_Index = idx;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    void SetIndex(CSStr name)
 | 
			
		||||
    {
 | 
			
		||||
        SetIndex(sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->mPtr, name));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the index to the specified value.
 | 
			
		||||
    */
 | 
			
		||||
    void SetIndex(const Object & param);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Default constructor (null).
 | 
			
		||||
    */
 | 
			
		||||
    Parameter()
 | 
			
		||||
        : m_Index(0), m_Handle()
 | 
			
		||||
    {
 | 
			
		||||
        /* ... */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * No parameter constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(const StmtRef & stmt)
 | 
			
		||||
        : m_Index(0), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        /* ... */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Index constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(const StmtRef & stmt, Int32 idx)
 | 
			
		||||
        : m_Index(idx), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_PARAM(*this, m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Name constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(const StmtRef & stmt, CSStr name)
 | 
			
		||||
        : m_Index(stmt ? sqlite3_bind_parameter_index(stmt->mPtr, name) : 0), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        SQMOD_VALIDATE_PARAM(*this, m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Dynamic constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(const StmtRef & stmt, const Object & param)
 | 
			
		||||
        : m_Index(0), m_Handle(stmt)
 | 
			
		||||
    {
 | 
			
		||||
        if (!m_Handle)
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("Invalid SQLite statement reference");
 | 
			
		||||
        }
 | 
			
		||||
        // Extract the index
 | 
			
		||||
        SetIndex(param);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Copy constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(const Parameter & o) = default;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Move constructor.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter(Parameter && o) = default;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Copy assignment operator.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter & operator = (const Parameter & o) = default;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Move assignment operator.
 | 
			
		||||
    */
 | 
			
		||||
    Parameter & operator = (Parameter && o) = default;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Perform an equality comparison between two parameter indexes.
 | 
			
		||||
    */
 | 
			
		||||
    bool operator == (const Parameter & o) const
 | 
			
		||||
    {
 | 
			
		||||
        return (m_Index == o.m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Perform an inequality comparison between two parameter indexes.
 | 
			
		||||
    */
 | 
			
		||||
    bool operator != (const Parameter & o) const
 | 
			
		||||
    {
 | 
			
		||||
        return (m_Index != o.m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Implicit conversion to boolean for use in boolean operations.
 | 
			
		||||
    */
 | 
			
		||||
    operator bool () const
 | 
			
		||||
    {
 | 
			
		||||
        return m_Index >= 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Used by the script engine to compare two instances of this type.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 Cmp(const Parameter & o) const
 | 
			
		||||
    {
 | 
			
		||||
        if (m_Index == o.m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else if (m_Index > o.m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Used by the script engine to convert an instance of this type to a string.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr ToString() const
 | 
			
		||||
    {
 | 
			
		||||
        CSStr val = nullptr;
 | 
			
		||||
        // Can we attempt to return the parameter name?
 | 
			
		||||
        if (m_Handle && m_Index)
 | 
			
		||||
        {
 | 
			
		||||
            val = sqlite3_bind_parameter_name(m_Handle->mPtr, m_Index);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            val = ToStrF(_SC("%d"), m_Index);
 | 
			
		||||
        }
 | 
			
		||||
        // Return the value if valid
 | 
			
		||||
        return val ? val : _SC("");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Used by the script engine to retrieve the name from instances of this type.
 | 
			
		||||
    */
 | 
			
		||||
    static SQInteger Typename(HSQUIRRELVM vm);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * See whether this statement is valid.
 | 
			
		||||
    */
 | 
			
		||||
    bool IsValid() const
 | 
			
		||||
    {
 | 
			
		||||
        return m_Handle; // An invalid statement means an invalid parameter
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Return the number of active references to this statement handle.
 | 
			
		||||
    */
 | 
			
		||||
    Uint32 GetRefCount() const
 | 
			
		||||
    {
 | 
			
		||||
        return m_Handle.Count();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetIndex() const
 | 
			
		||||
    {
 | 
			
		||||
        return m_Index;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated database statement.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetStatement() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the associated database connection.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetConnection() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the name of the referenced parameter.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetName() const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_bind_parameter_name(SQMOD_GET_CREATED(*this)->mPtr, m_Index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Release the reference to the associated database statement and parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void Release()
 | 
			
		||||
    {
 | 
			
		||||
        m_Handle.Reset();
 | 
			
		||||
        m_Index = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a dynamic value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetValue(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a boolean value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetBool(bool value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a character value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetChar(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a native integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetInteger(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 8 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetInt8(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 8 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetUint8(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 16 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetInt16(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 16 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetUint16(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 32 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetInt32(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 32 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetUint32(SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 64 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetInt64(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 64 bit integer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetUint64(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a native floating point value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetFloat(SQFloat value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a 32 bit floating point value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetFloat32(SQFloat value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a 64 bit floating point value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetFloat64(SQFloat value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a string value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetString(CSStr value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a string value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetStringEx(CSStr value, Int32 length);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a zeroed blob value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetZeroBlob(SQInteger size);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a blob value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetBlob(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a buffer value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetData(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetDate(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetDateEx(SQInteger year, SQInteger month, SQInteger day);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a time value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetTime(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a time value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetTimeEx(SQInteger hour, SQInteger minute, SQInteger second);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date-time value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetDatetime(const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date-time value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetDatetimeEx(SQInteger year, SQInteger month, SQInteger day, SQInteger hour, SQInteger minute, SQInteger second);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the current timestamp at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetNow();
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a null value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    void SetNull();
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a string value at the referenced parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    static SQInteger SetStringF(HSQUIRRELVM vm);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // Namespace:: SqMod
 | 
			
		||||
 | 
			
		||||
#endif // _SQSQLITE_PARAMETER_HPP_
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -3,6 +3,8 @@
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
#include "Handle/Statement.hpp"
 | 
			
		||||
#include "Parameter.hpp"
 | 
			
		||||
#include "Column.hpp"
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
namespace SqMod {
 | 
			
		||||
@@ -68,9 +70,9 @@ protected:
 | 
			
		||||
     * Validate the statement reference and parameter index, and throw an error if they're invalid.
 | 
			
		||||
    */
 | 
			
		||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
 | 
			
		||||
    void ValidateParameter(Int32 idx, CCStr file, Int32 line) const;
 | 
			
		||||
    void ValidateParam(Int32 idx, CCStr file, Int32 line) const;
 | 
			
		||||
#else
 | 
			
		||||
    void ValidateParameter(Int32 idx) const;
 | 
			
		||||
    void ValidateParam(Int32 idx) const;
 | 
			
		||||
#endif // _DEBUG
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -99,7 +101,7 @@ public:
 | 
			
		||||
    Statement(const ConnRef & connection, CSStr query)
 | 
			
		||||
        : m_Handle(new StmtHnd(connection))
 | 
			
		||||
    {
 | 
			
		||||
        GET_VALID_HND(*this)->Create(query);
 | 
			
		||||
        SQMOD_GET_VALID(*this)->Create(query);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -250,7 +252,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetStatus() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mStatus;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mStatus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -258,7 +260,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetErrorCode() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrNo();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrNo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -266,7 +268,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetExtendedErrorCode() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ExErrNo();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ExErrNo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -274,7 +276,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetErrStr() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrStr();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrStr();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -282,7 +284,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetErrMsg() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->ErrMsg();
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->ErrMsg();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -290,7 +292,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumns() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mColumns;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mColumns;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -298,7 +300,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetParameters() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mParameters;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mParameters;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -306,7 +308,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    const String & GetQuery() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_VALID_HND(*this)->mQuery;
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->mQuery;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -314,7 +316,7 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetGood() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_CREATED_HND(*this)->mGood;
 | 
			
		||||
        return SQMOD_GET_CREATED(*this)->mGood;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -322,7 +324,117 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool GetDone() const
 | 
			
		||||
    {
 | 
			
		||||
        return GET_CREATED_HND(*this)->mDone;
 | 
			
		||||
        return SQMOD_GET_CREATED(*this)->mDone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether a specific parameter index is within range.
 | 
			
		||||
    */
 | 
			
		||||
    bool CheckParameter(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->CheckParameter(idx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the parameter index associated with the specified name.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetParameterIndex(CSStr name) const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_bind_parameter_index(SQMOD_GET_VALID(*this)->mPtr, name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the parameter name associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetParameterName(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        // Validate the specified index
 | 
			
		||||
        if (!idx)
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("Invalid parameter index (%d)", idx);
 | 
			
		||||
        }
 | 
			
		||||
        // Attempt to locate the name at the specified index
 | 
			
		||||
        CSStr name = sqlite3_bind_parameter_name(SQMOD_GET_VALID(*this)->mPtr, idx);
 | 
			
		||||
        // Validate the obtained string
 | 
			
		||||
        if (!name)
 | 
			
		||||
        {
 | 
			
		||||
            STHROWF("No such parameter exists (%d)", idx);
 | 
			
		||||
        }
 | 
			
		||||
        // Return the obtained string
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether a specific column index is within range.
 | 
			
		||||
    */
 | 
			
		||||
    bool CheckColumn(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->CheckColumn(idx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the amount of columns available in the current row.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetDataCount() const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_data_count(SQMOD_GET_VALID(*this)->mPtr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether the specified column is null.
 | 
			
		||||
    */
 | 
			
		||||
    bool IsColumnNull(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return (sqlite3_column_type(SQMOD_GET_VALID(*this)->mPtr, idx) == SQLITE_NULL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column index associated with the specified name.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnIndex(CSStr name) const
 | 
			
		||||
    {
 | 
			
		||||
        return SQMOD_GET_VALID(*this)->GetColumnIndex(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column name associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetColumnName(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_column_name(SQMOD_GET_VALID(*this)->mPtr, idx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column origin name if the library was compiled with such feature.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetColumnOriginName(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
 | 
			
		||||
        return sqlite3_column_origin_name(SQMOD_GET_VALID(*this)->mPtr, idx);
 | 
			
		||||
#else
 | 
			
		||||
        // The compiler moans when extra warnings are enabled
 | 
			
		||||
        SQMOD_UNUSED_VAR(idx);
 | 
			
		||||
        // Stop the execution here!
 | 
			
		||||
        STHROWF("The module was compiled without this feature");
 | 
			
		||||
        // We have to return something
 | 
			
		||||
        return _SC("");
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the type identifier of the column associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnType(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_column_type(SQMOD_GET_VALID(*this)->mPtr, idx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the size in bytes of the column associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnBytes(Int32 idx) const
 | 
			
		||||
    {
 | 
			
		||||
        return sqlite3_column_bytes(SQMOD_GET_VALID(*this)->mPtr, idx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -345,215 +457,424 @@ public:
 | 
			
		||||
    */
 | 
			
		||||
    bool Step();
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the parameter with the specified name or index.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetParameter(const Object & param) const
 | 
			
		||||
    {
 | 
			
		||||
        return Object(new Parameter(m_Handle, param));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a dynamic value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetValue(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetValue(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a boolean value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetBool(const Object & param, bool value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetBool(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a character value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetChar(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetChar(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a native integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetInteger(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetInteger(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 8 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetInt8(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetInt8(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 8 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetUint8(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetUint8(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 16 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetInt16(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetInt16(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 16 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetUint16(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetUint16(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 32 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetInt32(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetInt32(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 32 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetUint32(const Object & param, SQInteger value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetUint32(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a signed 64 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetInt64(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetInt64(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind an unsigned 64 bit integer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetUint64(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetUint64(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a native floating point value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetFloat(const Object & param, SQFloat value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetFloat(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a 32 bit floating point value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetFloat32(const Object & param, SQFloat value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetFloat32(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a 64 bit floating point value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetFloat64(const Object & param, SQFloat value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetFloat64(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a string value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetString(const Object & param, CSStr value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetString(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a zeroed blob value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetZeroBlob(const Object & param, SQInteger size)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetZeroBlob(size);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a blob value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetBlob(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetBlob(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a buffer value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetData(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetData(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetDate(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetDate(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetDateEx(const Object & param, SQInteger year, SQInteger month, SQInteger day)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetDateEx(year, month, day);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a time value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetTime(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetTime(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a time value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetTimeEx(const Object & param, SQInteger hour, SQInteger minute, SQInteger second)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetTimeEx(hour, minute, second);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date-time value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetDatetime(const Object & param, const Object & value)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetDatetime(value);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a date-time value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetDatetimeEx(const Object & param, SQInteger year, SQInteger month, SQInteger day,
 | 
			
		||||
                                    SQInteger hour, SQInteger minute, SQInteger second)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetDatetimeEx(year, month, day, hour, minute, second);
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the current timestamp at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetNow(const Object & param)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetNow();
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind a null value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & SetNull(const Object & param)
 | 
			
		||||
    {
 | 
			
		||||
        Parameter(SQMOD_GET_CREATED(*this), param).SetNull();
 | 
			
		||||
        // Allow chaining of operations
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the values from an array starting at the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindArray(Int32 idx, const Array & arr);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a numeric value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindValue(Int32 idx, Int32 value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a long integer value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindLong(Int32 idx, const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a native integer value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindInteger(Int32 idx, SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a floating point value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindFloat(Int32 idx, SQFloat value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a string value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindString(Int32 idx, CSStr value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a boolean value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindBool(Int32 idx, bool value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a null value at the the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBindNull(Int32 idx);
 | 
			
		||||
    Statement & SetArray(Int32 idx, const Array & arr);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the values from an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindTable(const Table & tbl);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a integer value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindValue(CSStr name, Int32 value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a long integer value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindLong(CSStr name, const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a native integer value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindInteger(CSStr name, SQInteger value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a floating point value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindFloat(CSStr name, SQFloat value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a string value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindString(CSStr name, CSStr value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a boolean value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindBool(CSStr name, bool value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the a null value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBindNull(CSStr name);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the specified value at the specified parameter index.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & IndexBind(Int32 idx, const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the specified value at the specified parameter name.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & NameBind(CSStr name, const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Attempt to bind the specified value at the specified parameter.
 | 
			
		||||
    */
 | 
			
		||||
    Statement & Bind(const Object & param, const Object & value);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the value at the specific column index.
 | 
			
		||||
    */
 | 
			
		||||
    Object FetchColumnIndex(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the value at the specific column name.
 | 
			
		||||
    */
 | 
			
		||||
    Object FetchColumnName(CSStr name) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the value at the specific column.
 | 
			
		||||
    */
 | 
			
		||||
    Object FetchColumn(const Object & column) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array FetchArray() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array FetchArray(Int32 min) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array FetchArray(Int32 min, Int32 max) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table FetchTable() const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table FetchTable(Int32 min) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Fetch the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table FetchTable(Int32 min, Int32 max) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether a specific column index is in range.
 | 
			
		||||
    */
 | 
			
		||||
    bool CheckColumn(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether a specific parameter index is in range.
 | 
			
		||||
    */
 | 
			
		||||
    bool CheckParameter(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Check whether the specified column is null.
 | 
			
		||||
    */
 | 
			
		||||
    bool IsColumnNull(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column index associated with the specified name.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnIndex(CSStr name) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column name associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetColumnName(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column origin name if the library was compiled with such feature.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetColumnOriginName(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the type identifier of the column associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnType(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the size in bytes of the column associated with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetColumnBytes(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column with the specified index.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetColumnByIndex(Int32 idx) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column with the specified name.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetColumnByName(CSStr name) const;
 | 
			
		||||
    Statement & SetTable(const Table & tbl);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the column with the specified name or index.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetColumn(const Object & column) const;
 | 
			
		||||
    Object GetColumn(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Object(new Column(m_Handle, column));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the amount of columns available in the current row.
 | 
			
		||||
     * Retrieve the value inside the referenced column as a dynamic type.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetDataCount() const;
 | 
			
		||||
    Object GetValue(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the parameter index associated with the specified name.
 | 
			
		||||
     * Retrieve the value inside the referenced column as a numeric type.
 | 
			
		||||
    */
 | 
			
		||||
    Int32 GetParameterIndex(CSStr name) const;
 | 
			
		||||
    Object GetNumber(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetNumber();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the parameter name associated with the specified index.
 | 
			
		||||
     * Retrieve the value inside the referenced column as a native script integer.
 | 
			
		||||
    */
 | 
			
		||||
    CSStr GetParameterName(Int32 idx) const;
 | 
			
		||||
    SQInteger GetInteger(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetInteger();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a native script floating point.
 | 
			
		||||
    */
 | 
			
		||||
    SQFloat GetFloat(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetFloat();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a long integer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetLong(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetLong();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a string.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetString(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a boolean.
 | 
			
		||||
    */
 | 
			
		||||
    bool GetBoolean(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetBoolean();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a character.
 | 
			
		||||
    */
 | 
			
		||||
    SQChar GetChar(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetChar();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a memory buffer.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBuffer(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetBuffer();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the value inside the referenced column as a memory blob.
 | 
			
		||||
    */
 | 
			
		||||
    Object GetBlob(const Object & column) const
 | 
			
		||||
    {
 | 
			
		||||
        return Column(SQMOD_GET_CREATED(*this), column).GetBlob();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array GetArray() const
 | 
			
		||||
    {
 | 
			
		||||
        return GetArray(0, SQMOD_GET_CREATED(*this)->mColumns);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array GetArray(Int32 min) const
 | 
			
		||||
    {
 | 
			
		||||
        return GetArray(min, SQMOD_GET_CREATED(*this)->mColumns);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an array container.
 | 
			
		||||
    */
 | 
			
		||||
    Array GetArray(Int32 min, Int32 max) const;
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table GetTable() const
 | 
			
		||||
    {
 | 
			
		||||
        return GetTable(0, SQMOD_GET_CREATED(*this)->mColumns);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table GetTable(Int32 min) const
 | 
			
		||||
    {
 | 
			
		||||
        return GetTable(min, SQMOD_GET_CREATED(*this)->mColumns);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Retrieve the row as an associative container.
 | 
			
		||||
    */
 | 
			
		||||
    Table GetTable(Int32 min, Int32 max) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // Namespace:: SqMod
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user