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 SkySQL Single Node Transactions and Replicated Transactions services.

Todo demonstrates the ease-of-use of MariaDB Connectors and Single Node Transactions or Replicated 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

  • Single Node 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 Single Node Transactions and Replicated Transactions topologies of MariaDB SkySQL. For the purposes of demonstration, this guide uses the Single Node Transactions 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 a Single Node Transactions database service on MariaDB SkySQL. 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