diff --git a/src/sql/mysql/MySQL.cpp b/src/sql/mysql/MySQL.cpp index 9dfc418..6eb0cd9 100644 --- a/src/sql/mysql/MySQL.cpp +++ b/src/sql/mysql/MySQL.cpp @@ -218,6 +218,8 @@ result MySQLManager::connect(const std::string &url) { my_bool reconnect = 1; 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 if(!result) @@ -510,9 +512,15 @@ namespace sql::mysql { case MYSQL_TYPE_STRING: case MYSQL_TYPE_BLOB: static ResultBindDescriptor _string = { - /* primitive_size */ sizeof(void*) + sizeof(unsigned long*), /* 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*); }, - /* create */ [](const MYSQL_FIELD& field, MYSQL_BIND& bind, char*& primitive) { + /* we store the allocated buffer in the primitive types buffer and the length */ + /* primitive_size */ sizeof(void*) + sizeof(unsigned long*), + + /* 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 = malloc(bind.buffer_length); bind.buffer_type = MYSQL_TYPE_BLOB; @@ -525,7 +533,7 @@ namespace sql::mysql { 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; result.reserve(length); result.assign((const char*) bind.buffer, length); @@ -601,7 +609,7 @@ namespace sql::mysql { 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); if(!result.memory) return false; @@ -693,10 +701,12 @@ result MySQLManager::executeCommand(std::shared_ptr _ptr) { auto variables = ptr->variables; vector 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 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};