1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00
sapphire/src/common/Database/PreparedStatement.h

91 lines
1.8 KiB
C
Raw Normal View History

#ifndef SAPPHIRE_PREPAREDSTATEMENT_H
#define SAPPHIRE_PREPAREDSTATEMENT_H
#include <stdint.h>
#include <vector>
#include <string>
2018-10-24 12:53:26 +02:00
#include <memory>
#include "Operation.h"
2018-10-28 21:53:21 +01:00
namespace Mysql
{
class PreparedStatement;
}
namespace Sapphire::Db
{
2018-10-28 21:53:21 +01:00
union PreparedStatementDataUnion
{
bool boolean;
uint32_t ui32;
int32_t i32;
uint64_t ui64;
int64_t i64;
double d;
};
2018-10-28 21:53:21 +01:00
enum PreparedStatementValueType
{
TYPE_BOOL,
TYPE_UI,
TYPE_UI64,
TYPE_I,
TYPE_I64,
TYPE_DOUBLE,
TYPE_STRING,
TYPE_BINARY,
TYPE_NULL
};
2018-10-28 21:53:21 +01:00
struct PreparedStatementData
{
PreparedStatementDataUnion data;
PreparedStatementValueType type;
std::vector< uint8_t > binary;
};
2018-10-28 21:53:21 +01:00
class PreparedStatement
{
public:
explicit PreparedStatement( uint32_t index );
2018-10-28 21:53:21 +01:00
~PreparedStatement();
2018-10-28 21:53:21 +01:00
void setBool( uint8_t index, bool value );
2018-10-28 21:53:21 +01:00
void setUInt( uint8_t index, uint32_t value );
2018-10-28 21:53:21 +01:00
void setUInt64( uint8_t index, uint64_t value );
2018-10-28 21:53:21 +01:00
void setInt( uint8_t index, int32_t value );
2018-10-28 21:53:21 +01:00
void setInt64( uint8_t index, int64_t value );
2018-10-28 21:53:21 +01:00
void setDouble( uint8_t index, double value );
2018-10-28 21:53:21 +01:00
void setString( uint8_t index, const std::string& value );
2018-10-28 21:53:21 +01:00
void setBinary( uint8_t index, const std::vector< uint8_t >& value );
2018-10-28 21:53:21 +01:00
void setNull( uint8_t index );
2018-10-28 21:53:21 +01:00
uint32_t getIndex() const;
2018-10-28 21:53:21 +01:00
void setMysqlPS( std::shared_ptr< Mysql::PreparedStatement > pStmt );
2018-10-28 21:53:21 +01:00
void bindParameters();
2018-10-28 21:53:21 +01:00
protected:
std::shared_ptr< Mysql::PreparedStatement > m_stmt;
uint32_t m_index;
std::vector< PreparedStatementData > m_statementData;
2018-10-28 21:53:21 +01:00
PreparedStatement( PreparedStatement const& right ) = delete;
2018-10-28 21:53:21 +01:00
PreparedStatement& operator=( PreparedStatement const& right ) = delete;
};
}
#endif //SAPPHIRE_PREPAREDSTATEMENT_H