2016-06-03 20:33:21 +02:00
|
|
|
#ifndef _SQMYSQL_HANDLE_STATEMENT_HPP_
|
|
|
|
#define _SQMYSQL_HANDLE_STATEMENT_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Handle/Connection.hpp"
|
2016-06-28 00:15:31 +02:00
|
|
|
#include "Base/Buffer.hpp"
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* The structure that holds the data associated with a certain bind point.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
struct StmtBind
|
2016-06-03 20:33:21 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MYSQL_STMT Type; // The managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type* Pointer; // Pointer to the managed type.
|
|
|
|
typedef const Type* ConstPtr; // Constant pointer to the managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type& Reference; // Reference to the managed type.
|
|
|
|
typedef const Type& ConstRef; // Constant reference to the managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MYSQL_BIND BindType; // Database bind type.
|
|
|
|
typedef MYSQL_TIME TimeType; // Database time type.
|
|
|
|
typedef my_bool BoolType; // Database boolean type.
|
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
public:
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
BoolType mIsNull; // Allows the database to specify if the parameter is null.
|
|
|
|
BoolType mError; // Allows the database if errors occured on this parameter.
|
|
|
|
Buffer mData; // Buffer to store non fundamental data for the parameter.
|
|
|
|
BindType * mBind; // The associated database bind point handle.
|
|
|
|
TimeType mTime; // Structure used to store time data from database.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
union
|
2016-06-03 20:33:21 +02:00
|
|
|
{
|
2016-06-28 00:15:31 +02:00
|
|
|
Uint64 mUint64; // Store unsigned integer values for the parameter.
|
|
|
|
Int64 mInt64; // Store signed integer values for the parameter.
|
|
|
|
Int32 mInt32[2]; // Store 32 bit signed integer values for the parameter.
|
|
|
|
Float64 mFloat64; // Store 32 bit floating point values for the parameter.
|
|
|
|
Float32 mFloat32[2]; // Store 64 bit floating point values for the parameter.
|
|
|
|
};
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Default constructor.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtBind()
|
|
|
|
: mIsNull(0), mError(0), mData(), mBind(nullptr), mTime(), mUint64(0)
|
2016-06-03 20:33:21 +02:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Copy constructor. (disabled)
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtBind(const StmtBind & o) = delete;
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Move constructor. (disabled)
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtBind(StmtBind && o) = delete;
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Copy assignment operator. (disabled)
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtBind & operator = (const StmtBind & o) = delete;
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Move assignment operator. (disabled)
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtBind & operator = (StmtBind && o) = delete;
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Retrieve the used buffer.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
CStr GetBuffer()
|
2016-06-03 20:33:21 +02:00
|
|
|
{
|
2016-06-28 00:15:31 +02:00
|
|
|
return mData ? mData.Data() : reinterpret_cast< CStr >(&mUint64);
|
2016-06-03 20:33:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Retrieve the buffer length.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
Ulong GetLength() const
|
2016-06-03 20:33:21 +02:00
|
|
|
{
|
2016-06-28 00:15:31 +02:00
|
|
|
return (mBind == nullptr) ? 0 : mBind->buffer_length;
|
2016-06-03 20:33:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Configure the input of a certain statement parameter.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
void SetInput(enum_field_types type, BindType * bind, CCStr buffer = nullptr, Ulong length = 0);
|
|
|
|
};
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* The structure that holds the data associated with a certain statement handle.
|
|
|
|
*/
|
|
|
|
struct StmtHnd
|
|
|
|
{
|
|
|
|
public:
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MYSQL_STMT Type; // The managed type.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type* Pointer; // Pointer to the managed type.
|
|
|
|
typedef const Type* ConstPtr; // Constant pointer to the managed type.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type& Reference; // Reference to the managed type.
|
|
|
|
typedef const Type& ConstRef; // Constant reference to the managed type.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef MYSQL_BIND BindType; // Database bind type.
|
|
|
|
typedef MYSQL_TIME TimeType; // Database time type.
|
|
|
|
typedef my_bool BoolType; // Database boolean type.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
public:
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
Pointer mPtr; // The managed statement handle.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
Uint32 mErrNo; // Last received error string.
|
|
|
|
String mErrStr; // Last received error message.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
Ulong mParams; // Number of parameters in the statement.
|
|
|
|
StmtBind * mBinds; // List of parameter binds.
|
|
|
|
BindType * mMyBinds; // List of parameter binds.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
ConnRef mConnection; // Reference to the associated connection.
|
|
|
|
String mQuery; // The query string.
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Default constructor.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
StmtHnd();
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Destructor.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
~StmtHnd();
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Grab the current error in the associated statement handle.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
void GrabCurrent();
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Grab the current error in the associated statement handle and throw it.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void ThrowCurrent(CCStr act, CCStr file, Int32 line);
|
|
|
|
#else
|
|
|
|
void ThrowCurrent(CCStr act);
|
|
|
|
#endif // _DEBUG
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Validate the associated statement handle and parameter index and throw an error if invalid.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void ValidateParam(Uint32 idx, CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
void ValidateParam(Uint32 idx) const;
|
|
|
|
#endif // _DEBUG
|
2016-06-03 20:33:21 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-28 00:15:31 +02:00
|
|
|
* Create the actual statement.
|
2016-06-03 20:33:21 +02:00
|
|
|
*/
|
2016-06-28 00:15:31 +02:00
|
|
|
void Create(const ConnRef & conn, CSStr query);
|
2016-06-03 20:33:21 +02:00
|
|
|
};
|
|
|
|
|
2016-06-28 00:15:31 +02:00
|
|
|
|
2016-06-03 20:33:21 +02:00
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMYSQL_HANDLE_STATEMENT_HPP_
|