Skip to content

Commit

Permalink
feat(DB): add support MariaDB 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Winfidonarleyan committed Jul 8, 2024
1 parent d0a1ced commit b5b9287
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ if (${CMAKE_VERSION} GREATER_EQUAL 3.28)
cmake_policy(SET CMP0153 OLD)
endif ()

if(POLICY CMP0153)
cmake_policy(SET CMP0153 NEW) # The exec_program() command should not be called
endif()

# Set projectname (must be done AFTER setting configurationtypes)
project(WarheadBand VERSION 3.0.0 LANGUAGES CXX C)

Expand Down Expand Up @@ -152,4 +156,4 @@ if (BUILD_TESTING AND BUILD_APPLICATION_WORLDSERVER)
COMMAND genhtml -o ${CMAKE_CURRENT_SOURCE_DIR}/coverage-report coverage.info
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()
endif()
20 changes: 11 additions & 9 deletions src/cmake/macros/FindMySQL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,20 @@ if( UNIX )
if( MYSQL_CONFIG )
message(STATUS "Using mysql-config: ${MYSQL_CONFIG}")
# set INCLUDE_DIR
exec_program(${MYSQL_CONFIG}
ARGS --include
execute_process(
COMMAND "${MYSQL_CONFIG}" --include
OUTPUT_VARIABLE MY_TMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REGEX REPLACE "-I([^ ]*)( .*)?" "\\1" MY_TMP "${MY_TMP}")
set(MYSQL_ADD_INCLUDE_PATH ${MY_TMP} CACHE FILEPATH INTERNAL)
#message("[DEBUG] MYSQL ADD_INCLUDE_PATH : ${MYSQL_ADD_INCLUDE_PATH}")
# set LIBRARY_DIR
exec_program(${MYSQL_CONFIG}
ARGS --libs_r
execute_process(
COMMAND "${MYSQL_CONFIG}" --libs_r
OUTPUT_VARIABLE MY_TMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(MYSQL_ADD_LIBRARIES "")
string(REGEX MATCHALL "-l[^ ]*" MYSQL_LIB_LIST "${MY_TMP}")
Expand All @@ -153,7 +155,7 @@ if( UNIX )
string(REGEX REPLACE "[ ]*-L([^ ]*)" "\\1" LIB "${LIB}")
list(APPEND MYSQL_ADD_LIBRARIES_PATH "${LIB}")
#message("[DEBUG] MYSQL ADD_LIBRARIES_PATH : ${MYSQL_ADD_LIBRARIES_PATH}")
endforeach(LIB ${MYSQL_LIBS})
endforeach(LIB)

else( MYSQL_CONFIG )
set(MYSQL_ADD_LIBRARIES "")
Expand Down Expand Up @@ -196,7 +198,7 @@ if( UNIX )
foreach(LIB ${MYSQL_ADD_LIBRARIES})
find_library( MYSQL_LIBRARY
NAMES
mysql libmysql ${LIB}
mysql libmariadb libmysql ${LIB}
PATHS
${MYSQL_ADD_LIBRARIES_PATH}
/usr/lib
Expand All @@ -206,7 +208,7 @@ if( UNIX )
/usr/local/mysql/lib
DOC "Specify the location of the mysql library here."
)
endforeach(LIB ${MYSQL_ADD_LIBRARY})
endforeach(LIB)
endif( UNIX )

if( WIN32 )
Expand Down Expand Up @@ -260,7 +262,7 @@ else( NOT WIN32 )
endif( NOT WIN32 )

if( UNIX )
find_program(MYSQL_EXECUTABLE mysql
find_program(MYSQL_EXECUTABLE mariadb mysql
PATHS
${MYSQL_CONFIG_PREFER_PATH}
/usr/local/mysql/bin/
Expand Down Expand Up @@ -303,4 +305,4 @@ if( MYSQL_LIBRARY )
mark_as_advanced( MYSQL_FOUND MYSQL_LIBRARY MYSQL_EXTRA_LIBRARIES MYSQL_INCLUDE_DIR MYSQL_EXECUTABLE )
else( MYSQL_LIBRARY )
message(FATAL_ERROR "Could not find the MySQL libraries! Please install the development libraries and headers")
endif( MYSQL_LIBRARY )
endif( MYSQL_LIBRARY )
10 changes: 8 additions & 2 deletions src/server/database/Updater/DBUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void DBUpdater::ApplyFile(DatabaseWorkerPool& pool, std::string_view host, std::
std::string_view port_or_socket, std::string_view database, std::string_view ssl, Path const& path)
{
std::vector<std::string> args;
args.reserve(9);
args.reserve(10);

// Add password from extra file
args.emplace_back(Warhead::StringFormat("--defaults-extra-file={}", pool.GetPathToExtraFile()));
Expand Down Expand Up @@ -401,6 +401,12 @@ void DBUpdater::ApplyFile(DatabaseWorkerPool& pool, std::string_view host, std::
#else
if (ssl == "ssl")
args.emplace_back("--ssl");
else
{
#ifdef MARIADB_VERSION_ID && MARIADB_VERSION_ID > 110000
args.emplace_back("--ssl=0");
#endif
}
#endif

// Execute sql file
Expand All @@ -426,4 +432,4 @@ void DBUpdater::ApplyFile(DatabaseWorkerPool& pool, std::string_view host, std::

throw UpdateException("update failed");
}
}
}

0 comments on commit b5b9287

Please sign in to comment.