1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-14 03:37:16 +01:00
SqMod/modules/sqlite/Statement.hpp

871 lines
32 KiB
C++
Raw Normal View History

2016-02-27 10:57:29 +01:00
#ifndef _SQSQLITE_STATEMENT_HPP
#define _SQSQLITE_STATEMENT_HPP
// ------------------------------------------------------------------------------------------------
#include "Handle/Statement.hpp"
#include "Parameter.hpp"
#include "Column.hpp"
2016-02-27 10:57:29 +01:00
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Used to manage and interact a database statement.
2016-02-27 10:57:29 +01:00
*/
class Statement
{
private:
// --------------------------------------------------------------------------------------------
StmtRef m_Handle; // Reference to the managed statement.
2016-02-27 10:57:29 +01:00
protected:
/* --------------------------------------------------------------------------------------------
* Validate the managed statement handle and throw an error if invalid.
2016-02-27 10:57:29 +01:00
*/
#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 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 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
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Validate the statement reference and row, and throw an error if they're invalid.
*/
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
void ValidateRow(CCStr file, Int32 line) const;
#else
void ValidateRow() const;
#endif // _DEBUG
2016-02-27 10:57:29 +01:00
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Statement()
: m_Handle()
{
/* ... */
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Construct a statement under the specified connection using the specified string.
*/
Statement(const ConnRef & connection, const StackStrF & query)
: m_Handle(new StmtHnd(connection))
{
SQMOD_GET_VALID(*this)->Create(query.mPtr, query.mLen);
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Construct a statement under the specified connection using the specified string.
*/
Statement(const Connection & connection, const StackStrF & query);
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Direct handle constructor.
*/
Statement(const StmtRef & s)
: m_Handle(s)
2016-02-27 10:57:29 +01:00
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Statement(const Statement & o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Move constructor.
2016-02-27 10:57:29 +01:00
*/
Statement(Statement && o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Statement & operator = (const Statement & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Statement & operator = (Statement && o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two connections.
*/
bool operator == (const Statement & o) const
{
return (m_Handle.Get() == o.m_Handle.Get());
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two connections.
*/
bool operator != (const Statement & o) const
{
return (m_Handle.Get() != o.m_Handle.Get());
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw connection handle.
*/
operator sqlite3_stmt * ()
{
return m_Handle ? m_Handle->mPtr : nullptr;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Implicit conversion to the raw connection handle.
*/
operator sqlite3_stmt * () const
{
return m_Handle ? m_Handle->mPtr : nullptr;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
2016-02-27 10:57:29 +01:00
{
return m_Handle ? m_Handle->mQuery : NullString();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated statement handle.
2016-02-27 10:57:29 +01:00
*/
const StmtRef & GetHandle() const
2016-02-27 10:57:29 +01:00
{
return m_Handle;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* See whether the managed handle is valid.
2016-02-27 10:57:29 +01:00
*/
bool IsValid() const
2016-02-27 10:57:29 +01:00
{
return m_Handle;
}
/* --------------------------------------------------------------------------------------------
* See whether the managed statement is valid.
*/
bool IsPrepared() const
{
return m_Handle && (m_Handle->mPtr != nullptr);
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this statement handle.
*/
Uint32 GetReferences() const
2016-02-27 10:57:29 +01:00
{
return m_Handle.Count();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated database connection.
*/
Object GetConnection() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Release the reference to the associated database statement.
*/
void Release()
{
m_Handle.Reset();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the last received status code.
*/
Int32 GetStatus() const
{
return SQMOD_GET_VALID(*this)->mStatus;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Return the numeric result code for the most recent failed API call (if any).
*/
Int32 GetErrorCode() const
{
return SQMOD_GET_VALID(*this)->ErrNo();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Return the extended numeric result code for the most recent failed API call (if any).
*/
Int32 GetExtendedErrorCode() const
{
return SQMOD_GET_VALID(*this)->ExErrNo();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the message of the last received error code.
*/
CSStr GetErrStr() const
{
return SQMOD_GET_VALID(*this)->ErrStr();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Return the last error message associated with this database connection.
*/
CSStr GetErrMsg() const
{
return SQMOD_GET_VALID(*this)->ErrMsg();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of requested columns.
*/
Int32 GetColumns() const
{
return SQMOD_GET_VALID(*this)->mColumns;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of specified parameters.
*/
Int32 GetParameters() const
{
return SQMOD_GET_VALID(*this)->mParameters;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the query string used to create this statement.
*/
const String & GetQuery() const
2016-02-27 10:57:29 +01:00
{
return SQMOD_GET_VALID(*this)->mQuery;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* See if the last step retrieved a valid row.
*/
bool GetGood() const
{
return SQMOD_GET_CREATED(*this)->mGood;
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* See if there are any steps left.
*/
bool GetDone() const
{
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(const StackStrF & name) const
{
return sqlite3_bind_parameter_index(SQMOD_GET_VALID(*this)->mPtr, name.mPtr);
}
/* --------------------------------------------------------------------------------------------
* 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(const StackStrF & name) const
{
return SQMOD_GET_VALID(*this)->GetColumnIndex(name.mPtr, name.mLen);
}
/* --------------------------------------------------------------------------------------------
* 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);
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Reset the statement back to its initial position to be stepped again.
*/
Statement & Reset();
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Clear any values binded to this statement.
*/
Statement & Clear();
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Execute this statement and don't expect any rows to be returned.
*/
Int32 Exec();
/* --------------------------------------------------------------------------------------------
* Step the statement and expect a row to be returned.
*/
bool Step();
/* --------------------------------------------------------------------------------------------
* Retrieve the parameter with the specified name or index.
2016-02-27 10:57:29 +01:00
*/
Object GetParameter(const Object & param) const
{
return Object(new Parameter(m_Handle, param));
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a dynamic value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetValue(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetValue(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a boolean value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetBool(const Object & param, bool value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetBool(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a character value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetChar(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetChar(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a native integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetInteger(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetInteger(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a signed 8 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetInt8(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetInt8(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind an unsigned 8 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetUint8(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetUint8(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a signed 16 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetInt16(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetInt16(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind an unsigned 16 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetUint16(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetUint16(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a signed 32 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetInt32(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetInt32(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind an unsigned 32 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetUint32(const Object & param, SQInteger value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetUint32(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a signed 64 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetInt64(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetInt64(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind an unsigned 64 bit integer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetUint64(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetUint64(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a native floating point value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetFloat(const Object & param, SQFloat value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetFloat(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a 32 bit floating point value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetFloat32(const Object & param, SQFloat value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetFloat32(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a 64 bit floating point value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetFloat64(const Object & param, SQFloat value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetFloat64(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a string value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetString(const Object & param, const StackStrF & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetString(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a zeroed blob value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
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;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a buffer value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetData(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetData(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a date value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetDate(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetDate(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* 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;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a time value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetTime(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetTime(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a time value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
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;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a date-time value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetDatetime(const Object & param, const Object & value)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetDatetime(value);
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a date-time value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
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;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind the current timestamp at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetNow(const Object & param)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetNow();
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind a null value at the specified parameter index.
2016-02-27 10:57:29 +01:00
*/
Statement & SetNull(const Object & param)
{
Parameter(SQMOD_GET_CREATED(*this), param).SetNull();
// Allow chaining of operations
return *this;
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Attempt to bind the values from an array starting at the specified index.
*/
Statement & SetArray(Int32 idx, const Array & arr);
/* --------------------------------------------------------------------------------------------
* Attempt to bind the values from an associative container.
2016-02-27 10:57:29 +01:00
*/
Statement & SetTable(const Table & tbl);
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the column with the specified name or index.
2016-02-27 10:57:29 +01:00
*/
Object GetColumn(const Object & column) const
{
return Object(new Column(m_Handle, column));
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a dynamic type.
2016-02-27 10:57:29 +01:00
*/
Object GetValue(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetValue();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a numeric type.
*/
Object GetNumber(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetNumber();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a native script integer.
2016-02-27 10:57:29 +01:00
*/
SQInteger GetInteger(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetInteger();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a native script floating point.
2016-02-27 10:57:29 +01:00
*/
SQFloat GetFloat(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetFloat();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a long integer.
2016-02-27 10:57:29 +01:00
*/
Object GetLong(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetLong();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a string.
2016-02-27 10:57:29 +01:00
*/
Object GetString(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetString();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a boolean.
2016-02-27 10:57:29 +01:00
*/
bool GetBoolean(const Object & column) const
{
return Column(SQMOD_GET_CREATED(*this), column).GetBoolean();
}
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the referenced column as a character.
2016-02-27 10:57:29 +01:00
*/
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
{
// Is there something to return?
if (SQMOD_GET_CREATED(*this)->mColumns > 0)
{
return GetTable(0, m_Handle->mColumns - 1);
}
// Fallback to empty table
return NullTable();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the row as an associative container.
*/
Table GetTable(Int32 min) const
{
// Is there something to return?
if (SQMOD_GET_CREATED(*this)->mColumns > 0)
{
return GetTable(min, m_Handle->mColumns - 1);
}
// Fallback to empty table
return NullTable();
}
/* --------------------------------------------------------------------------------------------
* Retrieve the row as an associative container.
*/
Table GetTable(Int32 min, Int32 max) const;
2016-02-27 10:57:29 +01:00
};
} // Namespace:: SqMod
#endif // _SQSQLITE_STATEMENT_HPP