Thursday, October 4, 2018

MySQL Connector C++ 8.0 with wxWidgets

Let us discuss about using MySQL Connector C++ 8.0 with wxWidgets. Details about setting up and using wxWidgets, and MySQL server and connector can be found at the following links.

ceMySQL.h Cross-platform C++ programming with wxWidgets

Using MySQL Database with C++ on Various Platforms Including ARM Single Board Computers

For this example, by using MySQL Workbench, we will create a database called 'mytest' and a table called 'mytable' in the MySQL server that is to be connected and used.


Figure 1. Creating a database 'mytest' and a table 'mytable' using MySQL Workbench.


A class module for MySQL Connector C++ called ceMySQL is implemented in

ceMySQL.h (https://github.com/yan9a/odroid/blob/master/database-mysql/ceMySQL.h) and

ceMySQL.cpp (https://github.com/yan9a/odroid/blob/master/database-mysql/ceMySQL.cpp).

ceMySQL class is used in the wxWidgets example program,

wxmysql.cpp (https://github.com/yan9a/odroid/blob/master/database-mysql/wxmysql.cpp),

to demonstrate select, insert, update, and delete operations. The commands in the script file wxmysql-bar.sh (Listing 4), can be used to build and run the program.

g++ wxmysql.cpp ceMySQL.cpp -std=c++11 \
    `wx-config --cxxflags --libs` \
    -I /usr/local/mysql/connector-c++-8.0/include \
    -L /usr/local/mysql/connector-c++-8.0/lib64 \
    -lmysqlcppconn8 -o wxmysql
./wxmysql
Listing 4. Commands to build and run MySQL Connector C++ 8.0 wxWidgets

The GUI of the program and its output are shown in Figure 2.


Figure 2. Using MySQL C++ connector 8.0 with wxWidgets.


No comments:

Post a Comment

Comments are moderated and don't be surprised if your comment does not appear promptly.