Skip to content

Commit

Permalink
[CMake][CI] Allow to build DatabaseExplorer plugin with mariaDb (mysq…
Browse files Browse the repository at this point in the history
…l) (#3510)

* [CMake][CI] Add option `WITH_MYSQL` to enable MySQL in DatabaseExplorer plugin

* Fix warnings and compilation.

* Add missing libmariadb.dll for win32 install and fix `MysqlInterface::Init()` to look for this dll

* Factorize code and improve error message

* Add missing dependencies for win32 install

* [CMake] Change default of WITH_MYSQL to OFF on MacOS
  • Loading branch information
Jarod42 authored Oct 25, 2024
1 parent 92790bb commit 7bf7111
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 389 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Codelite's dependencies
run: |
# brew update && brew upgrade # fails somehow
brew install git cmake libssh hunspell bison flex
brew install git cmake libssh hunspell bison flex mariadb
# WxWidgets
- name: Checkout
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
mkdir build-release
cd build-release
brew install autoconf automake libtool gettext
cmake .. -DCMAKE_BUILD_TYPE=Release -Wno-dev -DBUILD_TESTING=1
cmake .. -DCMAKE_BUILD_TYPE=Release -Wno-dev -DWITH_MYSQL=1 -DBUILD_TESTING=1
cmake --build . -j $(sysctl -n hw.physicalcpu)
cmake --build . --target install
ctest --output-on-failure
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
mingw-w64-clang-x86_64-openssl
mingw-w64-clang-x86_64-sqlite3
mingw-w64-clang-x86_64-llvm-openmp
mingw-w64-clang-x86_64-libmariadbclient
bison
flex
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: install dependencies for wxWidgets
run: |
sudo apt-get update
sudo apt-get install build-essential cmake git libedit-dev libgtk-3-dev libhunspell-dev libsqlite3-dev libssh-dev pkg-config xterm
sudo apt-get install build-essential cmake git libedit-dev libgtk-3-dev libhunspell-dev libsqlite3-dev libssh-dev pkg-config xterm libmariadb-dev
- name: Checkout WxWidgets
uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions DatabaseExplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ if(WITH_MYSQL)
message("-- LIBMYSQLCLIENT is set to ${LIBMYSQLCLIENT}")
endif(${LIBMYSQLCLIENT} STREQUAL "LIBMYSQLCLIENT-NOTFOUND")
add_definitions(-DDBL_USE_MYSQL=1)

if(MINGW)
install(FILES "${MSYS2_BASE}/clang64/bin/libmariadb.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}")
msys_list_deps(${MSYS2_BASE}/clang64/bin/libmariadb.dll LIBMARIA_DEPS)
foreach(DEP ${LIBMARIA_DEPS})
install(FILES "${DEP}" DESTINATION "${CMAKE_INSTALL_PREFIX}")
endforeach()
endif()
endif(WITH_MYSQL)

# On UNIX we require GTK
Expand Down
7 changes: 5 additions & 2 deletions docs/docs/build/build_from_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pacman -S mingw-w64-clang-x86_64-zlib \
mingw-w64-clang-x86_64-hunspell \
mingw-w64-clang-x86_64-openssl \
mingw-w64-clang-x86_64-sqlite3 \
mingw-w64-clang-x86_64-libmariadbclient \
flex bison
```

Expand Down Expand Up @@ -62,8 +63,9 @@ cd build-release/install

```bash
sudo apt install build-essential \
git cmake flex \
git cmake \
libssh-dev libsqlite3-dev \
libmariadb-dev \
libpcre2-dev bison flex
```

Expand Down Expand Up @@ -130,6 +132,7 @@ brew install git \
autoconf \
automake \
libtool \
mariadb \
gettext
```

Expand All @@ -151,7 +154,7 @@ source $HOME/.$(basename $SHELL)rc
git submodule update --init --recursive
mkdir build-release
cd $_
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_MYSQL=1
make -j$(sysctl -n hw.physicalcpu) install
```

Expand Down
6 changes: 6 additions & 0 deletions sdk/databaselayer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Our project is called 'databaselayersqlite' this is how it will be called in visual studio, and in our makefiles.
project(databaselayersqlite)

if (APPLE)
option(WITH_MYSQL "Enable support of MySQL for DatabaseExplorer plugin" OFF)
else ()
option(WITH_MYSQL "Enable support of MySQL for DatabaseExplorer plugin" ON)
endif ()

# It was noticed that when using MinGW gcc it is essential that 'core' is mentioned before 'base'.

# wxWidgets include (this will do all the magic to configure everything)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class WXDLLIMPEXP_DATABASELAYER MysqlDatabaseLayer : public DatabaseLayer
void ParseServerAndPort(const wxString& strServer);

#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
MysqlInterface* m_pInterface;
MysqlInterface* m_pInterface = nullptr;
#endif
wxString m_strServer;
wxString m_strDatabase;
wxString m_strUser;
wxString m_strPassword;
int m_iPort;
void* m_pDatabase;
int m_iPort = 0;

void* m_pDatabase = nullptr;

#if wxUSE_UNICODE
PointerLookupMap m_ResultSets;
Expand Down
88 changes: 13 additions & 75 deletions sdk/databaselayer/src/dblayer/MysqlDatabaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,100 +12,38 @@

// ctor
MysqlDatabaseLayer::MysqlDatabaseLayer()
: DatabaseLayer()
: MysqlDatabaseLayer(wxT("localhost:3306"), wxT(""), wxT(""), wxT(""))
{
#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
m_pInterface = new MysqlInterface();
if (!m_pInterface->Init())
{
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library"));
ThrowDatabaseException();
return;
}
#endif
InitDatabase();
m_strServer = _("localhost");
m_iPort = 3306; // default
m_strDatabase = wxT("");
m_strUser = wxT("");
m_strPassword = wxT("");
}

MysqlDatabaseLayer::MysqlDatabaseLayer(const wxString& strDatabase)
: DatabaseLayer()
: MysqlDatabaseLayer(wxT("localhost:3306"), strDatabase, wxT(""), wxT(""))
{
#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
m_pInterface = new MysqlInterface();
if (!m_pInterface->Init())
{
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library"));
ThrowDatabaseException();
return;
}
#endif
InitDatabase();
m_strServer = _("localhost");
m_iPort = 3306; // default
m_strUser = wxT("");
m_strPassword = wxT("");
Open(strDatabase);
}

MysqlDatabaseLayer::MysqlDatabaseLayer(const wxString& strServer, const wxString& strDatabase)
: DatabaseLayer()
: MysqlDatabaseLayer(strServer, strDatabase, wxT(""), wxT(""))
{
#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
m_pInterface = new MysqlInterface();
if (!m_pInterface->Init())
{
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library"));
ThrowDatabaseException();
return;
}
#endif
InitDatabase();
ParseServerAndPort(strServer);
m_strUser = wxT("");
m_strPassword = wxT("");
Open(strDatabase);
}

MysqlDatabaseLayer::MysqlDatabaseLayer(const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
: DatabaseLayer()
: MysqlDatabaseLayer(wxT("localhost:3306"), strDatabase, strUser, strPassword)
{
#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
m_pInterface = new MysqlInterface();
if (!m_pInterface->Init())
{
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library"));
ThrowDatabaseException();
return;
}
#endif
InitDatabase();
m_strServer = _("localhost");
m_iPort = 3306; // default
m_strUser = strUser;
m_strPassword = strPassword;
Open(strDatabase);
}

MysqlDatabaseLayer::MysqlDatabaseLayer(const wxString& strServer, const wxString& strDatabase, const wxString& strUser, const wxString& strPassword)
: DatabaseLayer()
{
#ifndef DONT_USE_DYNAMIC_DATABASE_LAYER_LINKING
m_pInterface = new MysqlInterface();
if (!m_pInterface->Init())
{
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library5"));
ThrowDatabaseException();
return;
}
try {
m_pInterface = new MysqlInterface();
m_pInterface->Init();
} catch (const wxString& error) {
SetErrorCode(DATABASE_LAYER_ERROR_LOADING_LIBRARY);
SetErrorMessage(wxT("Error loading MySQL library : ") + error);
ThrowDatabaseException();
return;
}
#endif
InitDatabase();
ParseServerAndPort(strServer);
Expand Down
Loading

0 comments on commit 7bf7111

Please sign in to comment.