Fixed some issues

This commit is contained in:
WolverinDEV 2019-11-06 12:00:08 +01:00
parent c532266cb8
commit ba80cbb229

View File

@ -218,6 +218,8 @@ result MySQLManager::connect(const std::string &url) {
my_bool reconnect = 1; my_bool reconnect = 1;
mysql_options(connection->handle, MYSQL_OPT_RECONNECT, &reconnect); mysql_options(connection->handle, MYSQL_OPT_RECONNECT, &reconnect);
} }
mysql_options(connection->handle, MYSQL_SET_CHARSET_NAME, "utf8");
mysql_options(connection->handle, MYSQL_INIT_COMMAND, "SET NAMES utf8");
auto result = mysql_real_connect(connection->handle, host.c_str(), username.c_str(), password.c_str(), database.c_str(), port, nullptr, 0); //CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS auto result = mysql_real_connect(connection->handle, host.c_str(), username.c_str(), password.c_str(), database.c_str(), port, nullptr, 0); //CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS
if(!result) if(!result)
@ -510,9 +512,15 @@ namespace sql::mysql {
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
case MYSQL_TYPE_BLOB: case MYSQL_TYPE_BLOB:
static ResultBindDescriptor _string = { static ResultBindDescriptor _string = {
/* primitive_size */ sizeof(void*) + sizeof(unsigned long*), /* we store the allocated buffer in the primitive types buffer and the length */ /* we store the allocated buffer in the primitive types buffer and the length */
/* destroy */ [](char*& primitive) { ::free(*(void**) primitive); primitive += sizeof(void*); primitive += sizeof(unsigned long*); }, /* primitive_size */ sizeof(void*) + sizeof(unsigned long*),
/* create */ [](const MYSQL_FIELD& field, MYSQL_BIND& bind, char*& primitive) {
/* destroy */ [](char*& primitive) {
::free(*(void**) primitive);
primitive += sizeof(void*);
primitive += sizeof(unsigned long*);
},
/* create */ [](const MYSQL_FIELD& field, MYSQL_BIND& bind, char*& primitive) {
bind.buffer_length = field.max_length > 0 ? field.max_length : min(field.length, 5UL * 1024UL * 1024UL); bind.buffer_length = field.max_length > 0 ? field.max_length : min(field.length, 5UL * 1024UL * 1024UL);
bind.buffer = malloc(bind.buffer_length); bind.buffer = malloc(bind.buffer_length);
bind.buffer_type = MYSQL_TYPE_BLOB; bind.buffer_type = MYSQL_TYPE_BLOB;
@ -525,7 +533,7 @@ namespace sql::mysql {
return bind.buffer != nullptr; return bind.buffer != nullptr;
}, },
/* get_as_string */ [](MYSQL_BIND& bind, std::string& result) { /* get_as_string */ [](MYSQL_BIND& bind, std::string& result) {
auto length = bind.length ? *bind.length : bind.length_value; auto length = bind.length ? *bind.length : bind.length_value;
result.reserve(length); result.reserve(length);
result.assign((const char*) bind.buffer, length); result.assign((const char*) bind.buffer, length);
@ -601,7 +609,7 @@ namespace sql::mysql {
return true; return true;
} }
logTrace(LOG_GENERAL, "[MYSQL] Allocated {} bytes for response", required_bytes); //logTrace(LOG_GENERAL, "[MYSQL] Allocated {} bytes for response", required_bytes);
result.memory = (BindMemory*) malloc(required_bytes); result.memory = (BindMemory*) malloc(required_bytes);
if(!result.memory) if(!result.memory)
return false; return false;
@ -693,10 +701,12 @@ result MySQLManager::executeCommand(std::shared_ptr<CommandData> _ptr) {
auto variables = ptr->variables; auto variables = ptr->variables;
vector<variable> mapped_variables; vector<variable> mapped_variables;
if(!sql::mysql::evaluate_sql_query(command, variables, mapped_variables)) return {ptr->sql_command, -1, "Could not map sqlite vars to mysql!"}; if(!sql::mysql::evaluate_sql_query(command, variables, mapped_variables))
return {ptr->sql_command, -1, "Could not map sqlite vars to mysql!"};
FreeGuard<BindMemory> bind_parameter_memory{nullptr}; FreeGuard<BindMemory> bind_parameter_memory{nullptr};
if(!sql::mysql::create_bind(bind_parameter_memory.ptr, mapped_variables)) return {ptr->sql_command, -1, "Failed to allocate bind memory!"}; if(!sql::mysql::create_bind(bind_parameter_memory.ptr, mapped_variables))
return {ptr->sql_command, -1, "Failed to allocate bind memory!"};
ResultBind bind_result_data{0, nullptr, nullptr}; ResultBind bind_result_data{0, nullptr, nullptr};