A C++ wrapper for mysql meant to be used in combination with sqlpp11 (https://github.com/rbock/sqlpp11).
!If you are using the sqlpp11 version 0.61 or later:
!The mariadb/mysql connector is included in the sqlpp11 library directly and
!you do not need this repository.
Branch / Compiler | clang, gcc | MSVC |
---|---|---|
master | ||
develop |
The code is distributed under BSD License, but if you build the library, then the binary will be linked dynamically to mysqlclient, which is published under GPL or commercial license as of this writing. The resulting binary might therefore fall under GPL. To avoid this, an option to link against the equivalent MariaDB connector (under LGPL) is provided: see the build instructions below.
See for instance test/SampleTest.cpp
#include "TabSample.h"
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>
namespace mysql = sqlpp::mysql;
int main()
{
auto config = std::make_shared<mysql::connection_config>();
config->user = "root";
config->database = "sqlpp_mysql";
config->debug = true;
mysql::connection db(config);
TabSample tab;
for(const auto& row : db.run(sqlpp::select(all_of(tab)).from(tab).unconditionally()))
{
std::cerr << "row.alpha: " << row.alpha << ", row.beta: " << row.beta << ", row.gamma: " << row.gamma << std::endl;
};
return 0;
}
Compiler: sqlpp11-connector-mysql makes use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:
- clang-3.4 on Ubuntu-12.4 (requires thread_local)
- g++-4.8 on Ubuntu-12.4
- MSVC 2015 Update 2 on appveyor
- AppleClang 8 (Xcode 8 and upwards, since prior versions do not support
thread_local
)
C++ SQL Layer: sqlpp11-connector-mysql is meant to be used with sqlpp11 (https://github.com/rbock/sqlpp11).
mysqlclient: libmysqlclient version 5.5 and up (or the respective mariadb version)
date library by Howard Hinnant: https://github.com/howardhinnant/date
Download and unpack the latest release or clone the repository. Inside the directory run the following commands:
mkdir build
cd build
cmake ..
cmake --build . --target install
In order to customize the build process, you can add the following options to the cmake command above:
- CMAKE_INSTALL_PREFIX: path to the install folder
- CMAKE_PREFIX_PATH: if sqlpp11 and/or date library are installed in non-system prefix, provide their prefixes as a semicolon-separated list
- USE_MARIADB (default OFF): force the use of the MariaDB connector instead of the GPL'd MySQL connector
- ENABLE_TESTS (default ON): build unit tests
For example:
cmake -DCMAKE_INSTALL_PREFIX=/opt/sqlpp11_mariadb -DUSE_MARIADB=1 ..