Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Connecting C++ and MySQL with ADBC

Instructions

Tip

If you already have a MySQL instance running, skip the steps to install MySQL, start it, load data, and stop it.

Prerequisites

  1. Install Pixi

  2. Install dbc

Set up MySQL

  1. Install Docker

  2. Start a MySQL instance:

    docker run -d --rm --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 mysql
  3. Create a table in MySQL and load data into it:

    cat games.sql | docker exec -i some-mysql mysql --user=root --password=my-secret-pw

Connect to MySQL

  1. Install the MySQL ADBC driver:

    dbc install --level user mysql
  2. Customize the C++ program main.cpp as needed

    • Change the connection arguments in the AdbcDatabaseSetOption() calls
    • If you changed which database you're connecting to, also change the SQL SELECT statement in AdbcStatementSetSqlQuery()
  3. Build and run the C++ program:

    Using Make:

    pixi run make
    ./mysql_demo

    Or using CMake:

    pixi run cmake -B build
    pixi run cmake --build build
    ./build/mysql_demo

Clean up

  1. Clean build artifacts:

    Using Make:

    pixi run make clean

    Using CMake:

    rm -rf build
  2. Stop the Docker container running MySQL:

    docker stop some-mysql