#include "PrepareCreator.h"
bool PrepareCreator::prepare(const char* sql) {
this->_stmt = mysql_stmt_init(this->_connection);
if (!this->_stmt) {
this->stmtErrorInfo("mysql_stmt_init");
return false;
}
if (mysql_stmt_prepare(this->_stmt, sql, strlen(sql))) {
this->stmtErrorInfo("mysql_stmt_prepare");
return false;
}
this->_bindParamCount = static_cast<unsigned short>(mysql_stmt_param_count(this->_stmt));
if (this->_bindParamCount > 0) {
if (this->_bindParamArray != nullptr) {
delete []this->_bindParamArray;
this->_bindParamArray = nullptr;
}
this->_bindParamArray = new MYSQL_BIND[this->_bindParamCount];
if (!_bindParamArray) {
this->stmtErrorInfo("new MYSQL_BIND");
return false;
}
memset(this->_bindParamArray, 0, sizeof(MYSQL_BIND)*this->_bindParamCount);
}
return true;
}
bool PrepareCreator::validIndex(int index) {
return index < this->_bindParamCount;
}
bool PrepareCreator::bindInt8(int index, int8_t &value) {
if (index >= this->_bindParamCount) {
this->errorInfo("bindInt8 index out!");
return false;
}
this->_bindParamArray[index].buffer_type = MYSQL_TYPE_TINY;
this->_bindParamArray[index].buffer = &value;
this->_bindParamArray[index].is_unsigned = false;
return true;
}
bool PrepareCreator::bindInt32(int index, int &value) {
if (index >= this->_bindParamCount) {
this->errorInfo("bindInt32 index out!");
return false;
}
this->_bindParamArray[index].buffer_type = MYSQL_TYPE_LONG;
this->_bindParamArray[index].buffer &