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

291 lines
10 KiB
C++
Raw Normal View History

2016-02-27 10:57:29 +01:00
#ifndef _SQSQLITE_COLUMN_HPP_
#define _SQSQLITE_COLUMN_HPP_
// ------------------------------------------------------------------------------------------------
#include "Handle/Statement.hpp"
2016-02-27 10:57:29 +01:00
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Tsed to manage and interact with statement columns.
2016-02-27 10:57:29 +01:00
*/
class Column
{
// --------------------------------------------------------------------------------------------
friend class Statement;
private:
// --------------------------------------------------------------------------------------------
Int32 m_Index; // The index of the managed column.
// --------------------------------------------------------------------------------------------
StmtRef m_Handle; // The statement where the column exist.
protected:
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* 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
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* 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 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 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
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
Column(const StmtRef & stmt, Int32 idx)
: m_Index(idx), m_Handle(stmt)
2016-02-27 10:57:29 +01:00
{
/* ... */
}
public:
/* --------------------------------------------------------------------------------------------
* Default constructor (null).
*/
Column()
: m_Index(-1), m_Handle()
2016-02-27 10:57:29 +01:00
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Column(const Column & o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Move constructor.
2016-02-27 10:57:29 +01:00
*/
Column(Column && o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Column & operator = (const Column & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Column & operator = (Column && o) = default;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two connection handles.
*/
bool operator == (const Column & o) const
{
return (m_Index == o.m_Index);
}
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two connection handles.
*/
bool operator != (const Column & 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 Column & o) const
{
if (m_Handle.Get() == o.m_Handle.Get())
{
2016-02-27 10:57:29 +01:00
return 0;
}
else if (m_Handle.Get() > o.m_Handle.Get())
{
2016-02-27 10:57:29 +01:00
return 1;
}
2016-02-27 10:57:29 +01:00
else
{
2016-02-27 10:57:29 +01:00
return -1;
}
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
{
return FmtStr(_SC("%d"), m_Index);
}
/* --------------------------------------------------------------------------------------------
* 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 column
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Return the number of active references to this statement handle.
*/
Uint32 GetRefCount() const
{
return m_Handle.Count();
2016-02-27 10:57:29 +01:00
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated column index.
*/
Int32 GetIndex() const
{
return m_Index;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated database statement.
*/
Object GetStatement() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the associated database connection.
*/
Object GetConnection() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Release the reference to the associated database statement and index.
*/
void Release()
{
m_Handle.Reset();
2016-02-27 10:57:29 +01:00
m_Index = -1;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the associated column cel as a dynamic type.
2016-02-27 10:57:29 +01:00
*/
Object GetValue() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the associated column cel as a numeric type.
*/
Object GetNumber() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* 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.
2016-02-27 10:57:29 +01:00
*/
SQChar GetChar() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the associated column cel as a memory buffer.
2016-02-27 10:57:29 +01:00
*/
Object GetBuffer() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the value inside the associated column cel as a memory blob.
*/
Object GetBlob() const;
2016-02-27 10:57:29 +01:00
/* --------------------------------------------------------------------------------------------
* Check whether the associated column is null.
*/
bool IsNull() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the name of the associated column index.
*/
CSStr GetName() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the column origin name if the library was compiled with such feature.
*/
CSStr GetOriginName() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the type identifier of the associated column index.
*/
Int32 GetType() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the size in bytes of the associated column index.
*/
Int32 GetBytes() const;
};
} // Namespace:: SqMod
#endif // _SQSQLITE_COLUMN_HPP_