2016-06-03 20:33:21 +02:00
|
|
|
#ifndef _SQMYSQL_RESULTSET_HPP_
|
|
|
|
#define _SQMYSQL_RESULTSET_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
#include "Handle/ResultSet.hpp"
|
2016-07-19 20:42:41 +02:00
|
|
|
#include "Field.hpp"
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-06-03 21:17:52 +02:00
|
|
|
* Allows management and interaction with a result set handle.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
|
|
|
class ResultSet
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
ResRef m_Handle; // Reference to the actual database result-set.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-07-27 23:41:43 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed statement handle and row, and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void ValidateStepped(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
void ValidateStepped() const;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed statement handle and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
const ResRef & GetValid(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
const ResRef & GetValid() const;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed statement handle and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
const ResRef & GetCreated(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
const ResRef & GetCreated() const;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2016-07-27 23:41:43 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed statement handle and row, and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
const ResRef & GetStepped(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
const ResRef & GetStepped() const;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the statement reference and field index, and throw an error if they're invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void ValidateField(Int32 idx, CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
void ValidateField(Int32 idx) const;
|
|
|
|
#endif // _DEBUG
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
ResultSet()
|
|
|
|
: m_Handle()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Connection constructor.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
ResultSet(const ConnRef & conn)
|
|
|
|
: m_Handle(new ResHnd())
|
|
|
|
{
|
|
|
|
m_Handle->Create(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Statement constructor.
|
|
|
|
*/
|
|
|
|
ResultSet(const StmtRef & stmt)
|
|
|
|
: m_Handle(new ResHnd())
|
|
|
|
{
|
|
|
|
m_Handle->Create(stmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Handle constructor.
|
|
|
|
*/
|
|
|
|
ResultSet(const ResRef & hnd)
|
2016-06-03 20:33:21 +02:00
|
|
|
: m_Handle(hnd)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
ResultSet(const ResultSet & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
ResultSet(ResultSet && o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~ResultSet() = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
|
|
|
ResultSet & operator = (const ResultSet & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
ResultSet & operator = (ResultSet && o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to compare two instances of this type.
|
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
Int32 Cmp(const ResultSet & o) const
|
|
|
|
{
|
|
|
|
if (m_Handle.Get() == o.m_Handle.Get())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (m_Handle.Get() > o.m_Handle.Get())
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
CSStr ToString() const
|
|
|
|
{
|
|
|
|
// Do we have a valid handle?
|
|
|
|
if (m_Handle)
|
|
|
|
{
|
|
|
|
ToStrF("%u", m_Handle->mFieldCount);
|
|
|
|
}
|
|
|
|
// Default to a negative value
|
|
|
|
return _SC("-1");
|
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to retrieve the name from instances of this type.
|
|
|
|
*/
|
|
|
|
static SQInteger Typename(HSQUIRRELVM vm);
|
|
|
|
|
2016-06-05 04:36:33 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the managed handle is valid.
|
|
|
|
*/
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return m_Handle;
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:31:10 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-28 00:11:21 +02:00
|
|
|
* Returns an array with all the field names available in the managed result set.
|
|
|
|
*/
|
2016-07-28 00:16:52 +02:00
|
|
|
Array GetFieldNames() const;
|
2016-07-28 00:11:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-28 00:13:55 +02:00
|
|
|
* Returns an array with wrapper instances for all the field available in the managed result set.
|
|
|
|
*/
|
|
|
|
Array GetFieldsArray() const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-28 00:15:39 +02:00
|
|
|
* Returns a table with wrapper instances for all the field available in the managed result set.
|
|
|
|
*/
|
|
|
|
Table GetFieldsTable() const;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-29 17:31:10 +02:00
|
|
|
* Returns the current position of the row cursor for the last Next().
|
|
|
|
*/
|
|
|
|
Object RowIndex() const
|
|
|
|
{
|
|
|
|
return MakeULongObj(SQMOD_GET_CREATED(*this)->RowIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Returns the number of rows in the result set.
|
|
|
|
*/
|
|
|
|
Object RowCount() const
|
|
|
|
{
|
|
|
|
return MakeULongObj(SQMOD_GET_CREATED(*this)->RowCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the next row from the query.
|
|
|
|
*/
|
|
|
|
bool Next() const
|
|
|
|
{
|
|
|
|
return SQMOD_GET_CREATED(*this)->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Seeks to an arbitrary row in a query result set.
|
|
|
|
*/
|
|
|
|
bool SetRowIndex(SQInteger index) const
|
|
|
|
{
|
|
|
|
return SQMOD_GET_CREATED(*this)->SetRowIndex(ConvTo< Uint64 >::From(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Seeks to an arbitrary row in a query result set.
|
|
|
|
*/
|
|
|
|
bool SetLongRowIndex(Object & index) const
|
|
|
|
{
|
|
|
|
return SQMOD_GET_CREATED(*this)->SetRowIndex(FetchULongObjVal(index));
|
|
|
|
}
|
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the field with the specified name or index.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
Field GetField(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field);
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a boolean value.
|
|
|
|
*/
|
|
|
|
bool GetBoolean(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetBoolean();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a character.
|
|
|
|
*/
|
|
|
|
SQChar GetChar(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetChar();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a native script integer.
|
|
|
|
*/
|
|
|
|
SQInteger GetInteger(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetInteger();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a native script floating point.
|
|
|
|
*/
|
|
|
|
SQFloat GetFloat(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetFloat();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a signed 8 bit integer value.
|
|
|
|
*/
|
|
|
|
SQInteger GetInt8(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetInt8();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as an unsigned 8 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQInteger GetUint8(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetUint8();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a signed 16 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQInteger GetInt16(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetInt16();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as an unsigned 16 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQInteger GetUint16(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetUint16();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a signed 32 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQInteger GetInt32(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetInt32();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as an unsigned 32 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQInteger GetUint32(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetUint32();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a signed 64 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
Object GetInt64(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetInt64();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as an unsigned 64 bit integer value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
Object GetUint64(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetUint64();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a 32 bit floating point value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQFloat GetFloat32(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetFloat32();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a 64 bit floating point value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
SQFloat GetFloat64(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetFloat64();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a string value.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
Object GetString(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetString();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-30 14:52:20 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-07-19 20:42:41 +02:00
|
|
|
* Retrieve the value inside the specified field as a memory buffer.
|
2016-06-30 14:52:20 +02:00
|
|
|
*/
|
2016-07-19 20:42:41 +02:00
|
|
|
Object GetBuffer(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetBuffer();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the value inside the specified field as a memory blob.
|
|
|
|
*/
|
|
|
|
Object GetBlob(const Object & field) const
|
|
|
|
{
|
2016-07-27 23:41:43 +02:00
|
|
|
return Field(SQMOD_GET_STEPPED(*this), field).GetBlob();
|
2016-07-19 20:42:41 +02:00
|
|
|
}
|
2016-06-03 20:33:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMYSQL_RESULTSET_HPP_
|