C++ client library for MariaDB. Uses the C connector.
- Prepared statements
- Transactions and savepoints
- Concurrency allows connection sharing between threads
- Data type support: blob, decimal, datetime, time, timespan, etc.
- Exceptions
Install mariadbclient
or mysqlclient
libraries.
- Initialize Git submodules:
git submodule update --init
- Add
mariadbclientpp
as a subdirectory in your ownCMakeLists.txt
:
add_subdirectory(/path/to/mariadbpp)
...
target_link_libraries(target mariadbclientpp)
- Initialize Git submodules:
git submodule update --init
mkdir build; cd build
cmake ..
make install
Add mariadbclientpp
as a CMake package to your CMake project. Make sure
that the environment variable CMAKE_PREFIX_PATH
includes the directory
where the mariadbclientpp-config.cmake
file was installed:
find_package(mariadbclientpp)
...
target_link_libraries(target mariadbclientpp::mariadbclientpp)
- Create database and user according to the information in test/CMakeLists.txt or adjust these values.
- Enable tests with
-DMARIADBPP_TEST=ON
and build the software.
// set up the account
account_ref acc = account::create(...);
// create connection
connection_ref con = connection::create(acc);
// insert, update, select on the connection
u64 id = con->insert("INSERT INTO table VALUES (1, 2, 3)");
u64 affected = con->execute("UPDATE table SET a=1");
result_set_ref result = con->query("SELECT * FROM table");
// create statement
statement_ref stmt = con->create_statement(...);
// insert, update, select on the statement
u64 id = stmt->insert();
u64 affected = stmt->execute();
result_set_ref result = stmt->query();
// reading from a result set
while (result->next()) {
int a = result->get_unsigned32(0);
int b = result->get_unsigned32("b");
}
// insert using prepared statement
statement_ref stmt = con->create_statement("INSERT INTO table (?, ?, ?)");
stmt->set_unsigned32(0, 13);
stmt->set_unsigned32(1, 37);
stmt->set_unsigned32(2, 42);
stmt->insert();
More usage examples can be found in the test/
directory.
This library was originally developed on Launchpad. It has since been forked and is now being actively maintained here.
This library is subject to the Boost Software License. See accompanying LICENSE file.