Todo App with MariaDB Connector/C++

Todo is a sample console application for managing a todo list. The application is compatible with MariaDB Connector/C++ and MariaDB Platform for Transactions using the HA (Primary/Replica), Galera, or Transactional Standalone topologies on MariaDB SkySQL.

Todo demonstrates the ease-of-use of MariaDB Connectors and MariaDB Platform for Transactions on MariaDB SkySQL by managing a list of arbitrary tasks, adding new tasks, and tracking their status.

Todo has two components:

  • C++-based front-end command-line application

  • MariaDB Platform for Transactions back-end database service running on MariaDB SkySQL


Clone the Repository

The Todo example application is available from the MariaDB Corporation repository on GitHub. The repository contains the console application, as well as a back-end API or testing other languages and other MariaDB Connectors.

To download the Todo application, clone the repository from GitHub:

$ git clone

This creates a dev-example-todo directory on your file system.

Provision Database Service

Todo requires a back-end database service using the InnoDB storage engine. The application is compatible with all topologies of MariaDB Platform for Transactions, including HA (Primary/Replica), Galera, and Transactional Standalone. For the purposes of demonstration, this guide uses the Transactional Standalone topology on MariaDB SkySQL.

For additional information, see "Launch".

Create the Database Schema

Todo uses an InnoDB table to store the todo entries.

Use the MariaDB Client to connect to the database service and initialize the schema:

  1. Connect to your database service.

  2. Use CREATE DATABASE to create a database for the application:

  3. Use CREATE TABLE to create a table to store the todo entries:

    CREATE TABLE todo.tasks (
      description VARCHAR(500) NOT NULL,
      completed BOOLEAN NOT NULL DEFAULT 0
    ) ENGINE = InnoDB;

This creates a todo.tasks table for use by the Todo application with MariaDB SkySQL as a database back-end.

Install the MariaDB Connectors

The Todo console application requires that you install MariaDB Connector/C and MariaDB Connector/C++.

Install the Application

Todo connects to MariaDB SkySQL through the C++ console application. The repository contains the C++ console code as well as different versions of a back-end application service and a React.js front-end for testing Todo with other languages on different MariaDB Connector.

Navigate to the console/cpp directory in the cloned repository:

$ cd dev-example-todo/console/cpp

Configure the Application

Edit the tasks.cpp file, update the main() function to configure the connection, with the login credentials for your MariaDB SkySQL service.

sql::SQLString url("jdbc:mariadb://");
sql::Properties properties({{"user", "db_user"}, {"password", "db_user_passwd"}});

Compile Application

Compile the task.cpp file to produce an executable called tasks:

$ g++ -o tasks tasks.cpp -std=c++11 -lmariadbcpp

Live Demonstration

Todo simulates a database-backed console-based todo list manager, maintaining a record of open and completed tasks on MariaDB Platform for Transactions. It supports the following operations:

  • Create a new task:

    $ ./tasks addTask "Test Todo Sample Console App."
  • Update the completion status of a task:

    $ ./tasks updateTaskStatus 1 1
  • Show all tasks:

    $ ./tasks showTasks
    id = 1, description = Test Todo Sample Console App, completed = 1
  • Remove a task by its numeric identifier:

    $ ./tasks deleteTask 1