A new MySQL product is born. The preview release of MySQL Connector/C++ is available for download at http://downloads.mysql.com/forge/connector_cpp_preview . Connector/C++ is a new database driver to connect C++ applications to the MySQL Server. The preview mimics parts of the JDBC 3.0 API and is licensed under the terms of the GPL (plus FLOSS License Exception). Have a look at the announcement and the MySQL Connector/C++ wiki page for further “official” information.
Motivation and Advantages
The Connector/C++ is based on an initial development from MySQL GUI team. The GUI team needed a C++ based connector with a JDBC like API. Andrey Hristov from the MySQL Connectors team had been assigned to take the initial code over from Vladimir Kolesnikov. He worked on it – to a different degree – over several months. Andrey is now the main developer of two Connectors for two of the five most common programming languages according to the TIOBE Programming Community Index – PHP and C++. Andrey, that is outstanding work! The TIOBE Index is in line with a MySQL quick poll asking for the primary programming language used for developing MySQL applications: C++ is very common and deserves a dedicated Connector.
Using the MySQL Connector/C++ instead of the MySQL C API (MySQL Client Library) offers the following advantages for C++ users:
- Convenience of using pure C++ code – no C function calls, no C mix-in
- Use of a commonly known, well designed and extensively documented API – JDBC 3.0
- Support of the object oriented programming paradigm
- Shorter development times due to commonly known API and better integration into C++
Status and Limitations
The MySQL Connector/C++ is available as a development preview version. It has been compiled on Linux, Windows, SunOS and Mac. We do not recommend using it for production systems or with critical data but we encourage you to try it out and provide feedback. You can ask questions on the C/C++ community forum at http://forums.mysql.com/ or join the MySQL Connector/C++ at http://lists.mysql.com/connector-cplusplus.
The preview version of the MySQL Connector/C++ does not implement all of the JDBC 3.0 API. The following classes are mostly implemented:
- Connection
- DatabaseMetaData
- Driver
- PreparedStatement
- ResultSet
- ResultSetMetaData
- Savepoint
- Statement
The API specification defines some 450 methods for the above mentioned classes. About 335 (=75%) of them are implemented and available with the preview release.
Comparison with MySQL++
The new MySQL Connector/C++ is not the first connector forMySQL developers using C++. MySQL++ is a community-driven C++ connector for MySQL available since years. From the MySQL++ website:
MySQL++ is a C++ wrapper for MySQL’s C API. It is built around STL principles, to make dealing with the database as easy as dealing with an STL container. MySQL++ relieves the programmer of dealing with cumbersome C data structures, generation of repetitive SQL statements, and manual creation of C++ data structures to mirror the database schema.
MySQL++ and the MySQL Connector/C++ follow different approaches. The table below compares three aspects to illustrate the major differences. You have the choice.
MySQL Connector/C++ | MySQL++ | |
---|---|---|
API |
|
|
License |
|
|
Status |
|
|
Examples and Feedback
You can find usages examples in the directory examples/ of the download package and on the Forge wiki page. This is a very basic example running a simple query without fetching any results to give you an impression of the API.
sql::mysql::MySQL_Driver *driver; sql::Connection *con; sql::Statement *stmt driver = sql::mysql::get_mysql_driver_instance(); con = driver->connect(EXAMPLE_HOST, EXAMPLE_PORT, EXAMPLE_USER, EXAMPLE_PASS); stmt = con->createStatement(); stmt->execute("USE " EXAMPLE_DB); stmt->execute("DROP TABLE IF EXISTS test"); stmt->execute("CREATE TABLE test(id INT, label CHAR(1))"); stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')"); delete stmt; delete con;
Feedback is welcome. Please post on the C/C++ community forum at http://forums.mysql.com/ or join the MySQL Connector/C++ at http://lists.mysql.com/connector-cplusplus. We will create a dedicated forum for the MySQL Connector/C++ at http://forums.mysql.com/index.php?36 very soon! I’ll change the blog posting to include the URL as soon as the forum has been created. PS: here you go – Connector/C++ forum at http://forums.mysql.com/list.php?167