MySQL Connector/C++ 8.0.22 has been released

Dear MySQL users,

MySQL Connector/Node.js is a new Node.js driver for use with the X
DevAPI. This release, v8.0.22, is a maintenance release of the
MySQL Connector/Node.js 8.0 series.

The X DevAPI enables application developers to write code that combines
the strengths of the relational and document models using a modern,
NoSQL-like syntax that does not assume previous experience writing
traditional SQL.

MySQL Connector/Node.js can be downloaded through npm (see
  https://www.npmjs.com/package/@mysql/xdevapi for details) or from
  https://dev.mysql.com/downloads/connector/nodejs/.

To learn more about how to write applications using the X DevAPI, see
  http://dev.mysql.com/doc/x-devapi-userguide/en/.
For more information about how the X DevAPI is implemented in MySQL
Connector/Node.js, and its usage, see
  http://dev.mysql.com/doc/dev/connector-nodejs/.

Please note that the X DevAPI requires at least MySQL Server version
8.0 or higher with the X Plugin enabled. For general documentation
about how to get started using MySQL as a document store, see
  http://dev.mysql.com/doc/refman/8.0/en/document-store.html.


Changes in MySQL Connector/Node.js 8.0.22 (2020-10-19, General Availability)

Functionality Added or Changed

     * Improved test execution configuration to better align
       with other connectors. For example, unified environment
       variable names (such as changing NODE_TEST_MYSQL_HOST to
       MYSQLX_HOST). See the Connector/Node.js documentation
       (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/) for
       usage information.


Bugs Fixed

     * Non-BIGINT values stored in BIGINT columns were not
       decoded properly in result sets. (Bug #31686805, Bug
       #100324)

     * Fetched results from a SET column would only contain one
       value from the set. (Bug #31654667, Bug #100255)

     * Deprecated the dbPassword and dbUser property names;
       which were aliases to the password and user properties.
       Their usage now emits deprecation level errors. (Bug
       #31599660)

     * Added a SERVER_GONE error handler to avoid potential
       circular dependency warnings with Node.js >= 14.0.0. (Bug
       #31586107, Bug #99869)

     * Restricted the offset() method to the CollectionFind and
       TableSelect APIs, as described in the X DevAPI
       specification. Using offset() on other APIs yielded this
       error: “Error: The server has gone away”. Instead, this
       intended behavior is available by using a combination of
       “sort()” or “orderBy()” and “limit()”. (Bug #31418813)

     * The nextResult() method returned false against an empty
       result set, and now returns true. Alternatively, use
       hasData() to check if a result set has data. (Bug
       #31037211)

     * The column.getType() method now returns the stringified
       type identifier when before it returned its numeric
       value. For example, DATETIME is now returned instead of
       12. (Bug #30922711)

     * Improved memory management for work performed by 3rd
       party APIs. (Bug #30845472)

     * Added support for lazy decoding of binary column metadata
       content. (Bug #30845366) Dear MySQL users,

MySQL Connector/C++ 8.0.22 is a new release version of the MySQL
Connector/C++ 8.0 series.

Connector/C++ 8.0 can be used to access MySQL implementing Document
Store or in a traditional way, using SQL queries. It allows writing
both C++ and plain C applications using X DevAPI and X DevAPI for C.
It also supports the legacy API of Connector/C++ 1.1 based on JDBC4.

To learn more about how to write applications using X DevAPI, see
“X DevAPI User Guide” at

  https://dev.mysql.com/doc/x-devapi-userguide/en/

See also “X DevAPI Reference” at

  https://dev.mysql.com/doc/dev/connector-cpp/devapi_ref.html

and “X DevAPI for C Reference” at

  https://dev.mysql.com/doc/dev/connector-cpp/xapi_ref.html

For generic information on using Connector/C++ 8.0, see

  https://dev.mysql.com/doc/dev/connector-cpp/

For general documentation about how to get started using MySQL
as a document store, see

  http://dev.mysql.com/doc/refman/8.0/en/document-store.html

To download MySQL Connector/C++ 8.0.22, see the “General Availability (GA)
Releases” tab at

  https://dev.mysql.com/downloads/connector/cpp/


Changes in MySQL Connector/C++ 8.0.22 (2020-10-19, General Availability)

Compilation Notes

     * Connector/C++ now can be compiled using MinGW on Windows.
       Thanks to Eric Beuque for the contribution. Note that
       this enables building on MinGW but does not make MinGW an
       officially supported platform for Connector/C++. (Bug
       #31636723, Bug #100248)


Connection Management Notes

     * For connections made using X Plugin, Connector/C++ now
       enables specifying the compression algorithms to be used
       for connections that use compression. Connection URIs and
       SessionSettings objects permit explicitly specifying the
       preferred algorithms:

          + URI strings permit a compression-algorithms option.
            The value is an algorithm name, or a list of one or
            more comma-separated algorithms specified as an
            array. Examples:
            mysqlx://user:password@host:port/db?compression-algorithms=lz4
            mysqlx://user:password@host:port/db?compression-algorithms=[lz4,zstd_stream]

          + SessionSettings objects permit a
            SessionOption::COMPRESSION_ALGORITHMS option. The
            value is a list of one or more comma-separated
            algorithms. Examples:
            mysqlx::Session sess(SessionOption::USER, “user_name”,
                     SessionOption::PWD, “password”,
                     SessionOption::COMPRESSION_ALGORITHMS, “lz4”);
            mysqlx::Session sess(SessionOption::USER, “user_name”,
                     SessionOption::PWD, “password”,
                     SessionOption::COMPRESSION_ALGORITHMS, “lz4,zstd_stream”);

            Alternatively, the algorithms value can be given as
            a container:
            std::list<std::string> algorithms = {“lz4″,”zstd_stream”};
            mysqlx::Session sess(SessionOption::USER, “user_name”,
                     SessionOption::PWD, “password”,
                     SessionOption::COMPRESSION_ALGORITHMS, algorithms);

          + For X DevAPI for C, there is a new
            MYSQLX_OPT_COMPRESSION_ALGORITHMS option and
            corresponding OPT_COMPRESSION_ALGORITHMS helper
            macro.
            URI mode follows X DevAPI URI mode:
            mysqlx_session_t *sess = mysqlx_get_session_from_url(
            “mysqlx://user:password@host:port/db?compression-algorithms=[lz4,zstd_stream]”, &error);

            Option mode follows the string format used for
            SessionOption:
            mysqlx_session_option_set(opt,
                      OPT_HOST(“host_name”),
                      OPT_USER(“user”),
                      OPT_PWD(“password”),
                      OPT_COMPRESSION_ALGORITHMS(“lz4,zstd_stream”),
                      PARAM_END));

       These rules apply:

          + Permitted algorithm names are zstd_stream,
            lz4_message, and deflate_stream, and their aliases
            zstd, lz4, and deflate. Names are case-insensitive.
            Unknown names are ignored.

          + Compression algorithms options permit multiple
            algorithms, which should be listed in priority
            order. Options that specify multiple algorithms can
            mix full algorithm names and aliases.

          + If no compression algorithms option is specified,
            the default is
            zstd_stream,lz4_message,deflate_stream.

          + The actual algorithm used is the first of those
            listed in the compression algorithms option that is
            also permitted on the server side. However, the
            option for compression algorithms is subject to the
            compression mode:
               o If the compression mode is disabled, the
                 compression algorithms option is ignored.
               o If the compression mode is preferred but no
                 listed algorithm is permitted on the server
                 side, the connection is uncompressed.
               o If the compression mode is required but no
                 listed algorithm is permitted on the server
                 side, an error occurs.
       See also Connection Compression with X Plugin
       (https://dev.mysql.com/doc/refman/8.0/en/x-plugin-connection-compression.html).


Legacy (JDBC API) Notes

     * For applications that use the legacy JDBC API (that is,
       not X DevAPI or X DevAPI for C), Connector/C++ binary
       distributions now include the libraries that provide the
       client-side LDAP authentication plugins, as well as any
       dependent libraries required by the plugins. This enables
       Connector/C++ application programs to connect to MySQL
       servers using simple LDAP authentication, or SASL LDAP
       authentication using the SCRAM-SHA-1 authentication
       method.
       Note
       LDAP authentication requires use of a server from a MySQL
       Enterprise Edition distribution. For more information
       about the LDAP authentication plugins, see LDAP Pluggable
       Authentication
       (https://dev.mysql.com/doc/refman/8.0/en/ldap-pluggable-authentication.html).
       If Connector/C++ was installed from a compressed tar file
       or Zip archive, the application program will need to set
       the OPT_PLUGIN_DIR connection option to the appropriate
       directory so that the bundled plugin library can be
       found. (Alternatively, copy the required plugin library
       to the default directory expected by the client library.)
       Example:
            sql::ConnectOptionsMap connection_properties;

            // To use simple LDAP authentication …

            connection_properties[“userName”] = “simple_ldap_user_name”;
            connection_properties[“password”] = “simple_ldap_password”;
            connection_properties[OPT_ENABLE_CLEARTEXT_PLUGIN]=true;

            // To use SASL LDAP authentication using SCRAM-SHA-1 …

            connection_properties[“userName”] = “sasl_ldap_user_name”;
            connection_properties[“password”] = “sasl_ldap_scram_password”;

            // Needed if Connector/C++ was installed from tar file or Zip archive …

            connection_properties[OPT_PLUGIN_DIR] = “${INSTALL_DIR}/lib{64}/plugin”;

            auto *driver = get_driver_instance();
            auto *con = driver->connect(connection_properties);

            // Execute statements …

            con->close();

     * For applications that use the legacy JDBC API (that is,
       not X DevAPI or X DevAPI for C), LOCAL data loading
       capability for the LOAD DATA statement previously could
       be controlled on the client side only by enabling it for
       all files accessible to the client, or by disabling it
       altogether. The new OPT_LOAD_DATA_LOCAL_DIR option
       enables restricting LOCAL data loading to files located
       in a designated directory. For example, to set the value
       at connect time:
            sql::ConnectOptionsMap opt;
            opt[OPT_HOSTNAME] = “localhost”;
            opt[OPT_LOAD_DATA_LOCAL_DIR] = “/tmp”;

            sql::Connection *conn = driver->connect(opt);

       OPT_LOAD_DATA_LOCAL_DIR can also be set after connect
       time:
            sql::ConnectOptionsMap opt;
            opt[OPT_HOSTNAME] = “localhost”;

            sql::Connection *conn = driver->connect(opt);

            //…. some queries / inserts / updates

            std::string path= “/tmp”;
            conn->setClientOption(OPT_LOAD_DATA_LOCAL_DIR, path);

            // LOAD LOCAL DATA DIR …

            //Disable LOCAL INFILE by setting to null
            conn->setClientOption(OPT_LOAD_DATA_LOCAL_DIR, nullptr);

       The OPT_LOAD_DATA_LOCAL_DIR option maps onto the
       MYSQL_OPT_LOAD_DATA_LOCAL_DIR option for the
       mysql_options() C API function. For more information, see
       Security Considerations for LOAD DATA LOCAL
       (https://dev.mysql.com/doc/refman/8.0/en/load-data-local-security.html).


Bugs Fixed

     * String decoding failed for utf-8 strings that began with
       a \xEF byte-order mark. (Bug #31656092)

     * With the CLIENT_MULTI_FLAG option enabled, executing
       multiple statements in a batch caused the next query to
       fail with a Commands out of sync error. (Bug #31399362)

     * For connections made using X Plugin, connections over
       Unix socket files did not work. (Bug #31329938)

     * For connections made using X Plugin, the default
       compression mode was DISABLED rather than PREFERRED. (Bug
       #31173447) Dear MySQL users,

MySQL Connector/Node.js is a new Node.js driver for use with the X
DevAPI. This release, v8.0.22, is a maintenance release of the
MySQL Connector/Node.js 8.0 series.

The X DevAPI enables application developers to write code that combines
the strengths of the relational and document models using a modern,
NoSQL-like syntax that does not assume previous experience writing
traditional SQL.

MySQL Connector/Node.js can be downloaded through npm (see
  https://www.npmjs.com/package/@mysql/xdevapi for details) or from
  https://dev.mysql.com/downloads/connector/nodejs/.

To learn more about how to write applications using the X DevAPI, see
  http://dev.mysql.com/doc/x-devapi-userguide/en/.
For more information about how the X DevAPI is implemented in MySQL
Connector/Node.js, and its usage, see
  http://dev.mysql.com/doc/dev/connector-nodejs/.

Please note that the X DevAPI requires at least MySQL Server version
8.0 or higher with the X Plugin enabled. For general documentation
about how to get started using MySQL as a document store, see
  http://dev.mysql.com/doc/refman/8.0/en/document-store.html.


Changes in MySQL Connector/Node.js 8.0.22 (2020-10-19, General Availability)

Functionality Added or Changed

     * Improved test execution configuration to better align
       with other connectors. For example, unified environment
       variable names (such as changing NODE_TEST_MYSQL_HOST to
       MYSQLX_HOST). See the Connector/Node.js documentation
       (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/) for
       usage information.


Bugs Fixed

     * Non-BIGINT values stored in BIGINT columns were not
       decoded properly in result sets. (Bug #31686805, Bug
       #100324)

     * Fetched results from a SET column would only contain one
       value from the set. (Bug #31654667, Bug #100255)

     * Deprecated the dbPassword and dbUser property names;
       which were aliases to the password and user properties.
       Their usage now emits deprecation level errors. (Bug
       #31599660)

     * Added a SERVER_GONE error handler to avoid potential
       circular dependency warnings with Node.js >= 14.0.0. (Bug
       #31586107, Bug #99869)

     * Restricted the offset() method to the CollectionFind and
       TableSelect APIs, as described in the X DevAPI
       specification. Using offset() on other APIs yielded this
       error: “Error: The server has gone away”. Instead, this
       intended behavior is available by using a combination of
       “sort()” or “orderBy()” and “limit()”. (Bug #31418813)

     * The nextResult() method returned false against an empty
       result set, and now returns true. Alternatively, use
       hasData() to check if a result set has data. (Bug
       #31037211)

     * The column.getType() method now returns the stringified
       type identifier when before it returned its numeric
       value. For example, DATETIME is now returned instead of
       12. (Bug #30922711)

     * Improved memory management for work performed by 3rd
       party APIs. (Bug #30845472)

     * Added support for lazy decoding of binary column metadata
       content. (Bug #30845366)

On Behalf of Oracle/MySQL Release Engineering Team,

Hery Ramilison

MySQL Connector/C++ 8.0.20 has been released

Dear MySQL users,

MySQL Connector/C++ 8.0.20 is a new release version of the MySQL
Connector/C++ 8.0 series.

Connector/C++ 8.0 can be used to access MySQL implementing Document
Store or in a traditional way, using SQL queries. It allows writing
both C++ and plain C applications using X DevAPI and X DevAPI for C.
It also supports the legacy API of Connector/C++ 1.1 based on JDBC4.

To learn more about how to write applications using X DevAPI, see
“X DevAPI User Guide” at

https://dev.mysql.com/doc/x-devapi-userguide/en/

See also “X DevAPI Reference” at

https://dev.mysql.com/doc/dev/connector-cpp/devapi_ref.html

and “X DevAPI for C Reference” at

https://dev.mysql.com/doc/dev/connector-cpp/xapi_ref.html

For generic information on using Connector/C++ 8.0, see

https://dev.mysql.com/doc/dev/connector-cpp/

For general documentation about how to get started using MySQL
as a document store, see

http://dev.mysql.com/doc/refman/8.0/en/document-store.html

To download MySQL Connector/C++ 8.0.20, see the “General Availability (GA)
Releases” tab at

https://dev.mysql.com/downloads/connector/cpp/

Changes in MySQL Connector/C++ 8.0.20 (2020-04-27, General Availability)

Connection Management Notes

     * For connections made using X Plugin, Connector/C++ now
       provides control over the use of compression to minimize
       the number of bytes sent over connections to the server.
       Connection URIs and SessionSettings objects permit
       explicitly specifying a compression option:

          + URI strings permit a compression option with
            permitted values of DISABLED, PREFERRED, and
            REQUIRED (not case-sensitive). Examples:
            mysqlx://user:password@host:port/db?compression=DISABLED
            mysqlx://user:password@host:port/db?compression=PREFERRED
            mysqlx://user:password@host:port/db?compression=REQUIRED

          + SessionSettings object permit a
            SessionOption::COMPRESSION option with permitted
            values of CompressionMode::DISABLED,
            CompressionMode::PREFERRED, and
            CompressionMode::REQUIRED. Example:
            mysqlx::Session sess(SessionOption::PORT, “user_name”,
                                 SessionOption::USER, “password”,
                                 SessionOption::COMPRESSION,
                                 CompressionMode::PREFERRED);

       These rules apply:

          + If compression is disabled, the connection is
            uncompressed.

          + If compression is preferred, Connector/C++
            negotiates with the server to find a compression
            algorithm supported in common on the server and
            client sides. If no common algorithm is available,
            the connection is uncompressed.

          + If compression is required, compression algorithm
            negotiation occurs as with compression preferred. If
            no common algorithm is available, the connection
            terminates with an error.
       To avoid CPU inefficiency, data packets are not
       compressed even when compression is enabled unless they
       exceed a threshold size (currently 1000 bytes; this is
       subject to change).
       See also Connection Compression with X Plugin
       (https://dev.mysql.com/doc/refman/8.0/en/x-plugin-connection-compression.html).


Packaging Notes

     * Previously, Connector/C++ binary distributions were
       compatible with projects built using MSVC 2019 (using
       either dynamic or static connector libraries) or MSVC
       2017 (using dynamic connector libraries only). Binary
       distributions now are also compatible with MSVC 2017
       using the static X DevAPI connector library. This means
       that binary distributions are fully compatible with MSVC
       2019, and fully compatible with MSVC 2017 with the
       exception of the static legacy (JDBC) connector library.


Bugs Fixed

     * For connections made using X Plugin, the last byte was
       removed from DATETIME values fetched as raw bytes. (Bug
       #30838230)

     * In X DevAPI expressions, Connector/C++ treated the JSON
       ->> operator the same as ->, rather than applying an
       additional JSON_UNQUOTE() operation. (Bug #29870832)

     * Comparison of JSON values from query results failed due
       to an extra \0 character erroneously being added to the
       end of such values. (Bug #29847865)

     * For connections made using X Plugin, warnings sent
       following result sets were not captured, and were thus
       unavailable to getWarnings(). (Bug #28047970)

On Behalf of Oracle/MySQL Release Engineering Team,
Hery Ramilison

MySQL Connector/C++ 8.0.17 has been released

Dear MySQL users,

MySQL Connector/C++ 8.0.17 is a new release version of the MySQL
Connector/C++ 8.0 series.

Connector/C++ 8.0 can be used to access MySQL implementing Document
Store or in a traditional way, using SQL queries. It allows writing
both C++ and plain C applications using X DevAPI and X DevAPI for C.
It also supports the legacy API of Connector/C++ 1.1 based on JDBC4.

To learn more about how to write applications using X DevAPI, see
“X DevAPI User Guide” at

https://dev.mysql.com/doc/x-devapi-userguide/en/

See also “X DevAPI Reference” at

https://dev.mysql.com/doc/dev/connector-cpp/devapi_ref.html

and “X DevAPI for C Reference” at

https://dev.mysql.com/doc/dev/connector-cpp/xapi_ref.html

For generic information on using Connector/C++ 8.0, see

https://dev.mysql.com/doc/dev/connector-cpp/

For general documentation about how to get started using MySQL
as a document store, see

http://dev.mysql.com/doc/refman/8.0/en/document-store.html

To download MySQL Connector/C++ 8.0.17, see the “Generally Available (GA)
Releases” tab at

https://dev.mysql.com/downloads/connector/cpp/

==================================================

Changes in MySQL Connector/C++ 8.0.17 (2019-07-22, General
Availability)


     * Character Set Support

     * Compilation Notes

     * Configuration Notes

     * Function and Operator Notes

     * X DevAPI Notes

     * Functionality Added or Changed

     * Bugs Fixed

Character Set Support


     * Connector/C++ now supports the new utf8mb4_0900_bin
       collation added for the utf8mb4 Unicode character set in
       MySQL 8.0.17. For more information about this collation,
       see Unicode Character Sets
(https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html).

Compilation Notes


     * Connector/C++ now compiles cleanly using the C++14
       compiler. This includes MSVC 2017. Binary distributions
       from Oracle are still built in C++11 mode using MSVC 2015
       for compatibility reasons.

Configuration Notes


     * The maximum permitted length of host names throughout
       Connector/C++ has been raised to 255 ASCII characters, up
       from the previous limit of 60 characters. Applications
       that expect host names to be a maximum of 60 characters
       should be adjusted to account for this change.

Function and Operator Notes


     * Connector/C++ now supports the OVERLAPS and NOT OVERLAPS
       operators for expressions on JSON arrays or objects:
expr OVERLAPS expr
expr NOT OVERLAPS expr

       Suppose that a collection has these contents:
[{
   “_id”: “1”,
   “list”: [1, 4]
 }, {
   “_id”: “2”,
   “list”: [4, 7]
}]

       This operation:
auto res = collection.find(“[1, 2, 3] OVERLAPS $.list”).fields(“_id”).
execute();
res.fetchAll();

       Should return:
[{ “_id”: “1” }]

       This operation:
auto res = collection.find(“$.list OVERLAPS [4]”).fields(“_id”).execut
e();
res.fetchAll();

       Should return:
[{ “_id”: “1” }, { “_id”: “2” }]

       An error occurs if an application uses either operator
       and the server does not support it.

X DevAPI Notes


     * For index specifications passed to the
       Collection::createIndex() method (for X DevAPI
       applications) or the mysqlx_collection_create_index()
       function (for X DevAPI for C applications), Connector/C++
       now supports indexing array fields. A single index field
       description can contain a new member name array that
       takes a Boolean value. If set to true, the field is
       assumed to contain arrays of elements of the given type.
       For example:
coll.createIndex(“idx”,
  R”({ “fields”: [{ “field”: “foo”, “type”: “INT”, “array”: true }] })

);

       In addition, the set of possible index field data types
       (used as values of member type in index field
       descriptions) is extended with type CHAR(N), where the
       length N is mandatory. For example:
coll.createIndex(“idx”,
  R”({ “fields”: [{ “field”: “foo”, “type”: “CHAR(10)” }] })”
);

Functionality Added or Changed


     * Previously, Connector/C++ reported INT in result set
       metadata for all integer result set columns, which
       required applications to check column lengths to
       determine particular integer types. The metadata now
       reports the more-specific TINYINT, SMALLINT, MEDIUMINT,
       INT, and or BIGINT types for integer columns. (Bug
       #29525077)

Bugs Fixed


     * Calling a method such as .fields() or .sort() on existing
       objects did not overwrite the effects of any previous
       call. (Bug #29402358)

     * When Connector/C++ applications reported connection
       attributes to the server upon establishing a new
       connection, some attributes were taken from the host on
       which Connector/C++ was built, not the host on which the
       application was being run. Now application host
       attributes are sent. (Bug #29394723)

     * Assignments of the following form on CollectionFind
       objects invoked a copy assignment operator, which was
       nonoptimal and prevented potential re-execution of
       statements using prepared statements:
find = find.limit(1);

       (Bug #29390170)

     * Legal constructs of this form failed to compile:
for (string id : res.getGeneratedIds()) { … }

       (Bug #29355100)

     * During build configuration, CMake could report an
       incorrect OpenSSL version. (Bug #29282948)

Enjoy and thanks for the support!

What is new in Connector/C++ 8.0

We are proud to announce that with version 8.0.11 the new MySQL Connector/C++ 8.0 series becomes GA! Connector/C++ 8.0 is your gateway to the new exciting features of MySQL Server 8.0 such as MySQL Document Store. It also lets you perform your usual database tasks in a simpler and more powerful way using new, modern APIs that bring to you the full advantage of modern C++ programming language.

The 8.0 series is a true milestone in the development of Connector/C++. We have not only added new APIs but also completely re-implemented the connector to create good foundation for future innovation and improvements.The new implementation of Connector/C++ is based entirely on the new X Protocol of MySQL Server 8.0 and is highly modular to allow rapid development of new features. For the first time we aligned our APIs with other MySQL connectors. Also, for the first time Connector/C++ is offering a plain C API for code written in C.

New APIs of Connector/C++ 8.0

Up to now Connector/C++ implemented a single API based on JDBC4 standard. While keeping the old API for backward compatibility, the 8.0 series introduces two new APIs that can be used for accessing MySQL database.

  • X DevAPI: a C++ implementation of the new, fluent CRUD API defined for accessing MySQL Document Store and relational data. The same API is also implemented by xshell and other connectors and provides a uniform interface to the MySQL database.
  • XAPI: a new plain C API with functionality similar to that of X DevAPI. This API allows applications written in plain C to have access to the new MySQL features such as Document Store (it might feel strange to have plain C API in a C++ connector but in fact plain C can be seen as a subset of the C++ language; also, placing both APIs in the same connector allows re-using common implementation components).

To give you a feeling of the new APIs, here is a sample code which opens a session, creates a document collection, adds a document to that collection and then lists documents in the collection.

#include <iostream>
#include <mysqlx/xdevapi.h>

using ::std::cout;
using ::std::endl;

int main()
try {
  using namespace ::mysqlx;

  Session sess("user:password@host/schema");
  Collection coll = sess
                    .getDefaultSchema()
                    .createCollection("myCollection", true);

  coll.add(R"({ "name": "foo"; "age": 7 })").execute();

  CollectionFind query = coll
                         .find("age < :age")
                         .fields("name", "age");

  DocResult res = query.bind("age", 18).execute();

  for (DbDoc doc : res)
  {
    cout << "name: " << doc["name"]
         << ", age: " << doc["age"]
         << endl;
  }
}
catch (const mysqlx::Error &err)
{
  cout << "ERROR: " << err << endl;
}

The same thing implemented in plain C, using XAPI, looks as follows (for simplicity, error handling logic is omitted).

#include <stdio.h>
#include <mysqlx/xapi.h>

int main()
{
  int error;
  char err_buff[256];
  mysqlx_result_t *res;

  mysqlx_session_t *sess
    = mysqlx_get_session_from_url(
        "user:password@host/schema",
        err_buff, &error
      );

  mysqlx_schema_t *sch
    = mysqlx_get_schema(sess, "schema", 0);

  error = mysqlx_collection_create(sch, "myCollection");

  mysqlx_collection_t *coll
    = mysqlx_get_collection(sch, "myCollection", 0);

  res = mysqlx_collection_add( coll,
          "{ \"name\": \"foo\"; \"age\": 7 }",
          PARAM_END
        );

  mysqlx_stmt_t *query = mysqlx_collection_find_new(coll);
  error = mysqlx_set_find_criteria(query, "age < :age");

  mysqlx_stmt_bind(query, "age", PARAM_UINT(18), PARAM_END);

  res = mysqlx_execute(query);

  const char *doc;

  while (NULL != (doc = mysqlx_json_fetch_one(res, NULL)))
  {
    printf("%s\n", doc);
  }

  mysqlx_session_close(sess);
}

Note that the choice of the API is done by including appropriate public header: either <mysqlx/xdevapi.h> or <mysqlx/xapi.h>.

Apart from a CRUD style interface for accessing the MySQL Document Store, which is shared with other MySQL connectors, the new APIs give you full access to SQL and relational data, including transactions, parameter binding, row locking, convenient classes for representing query results and more. For example, the following code shows how to execute a plain SQL query against a relational table using X DevAPI. Similar code can be written using XAPI.

Session sess("user:password@host/schema");

SqlStatement query = sess.sql(
  "SELECT ID, Name, Info FROM city"
  "WHERE CountryCode = ? AND Info->'$.Population' > ?"
);

SqlResult res = query.bind("USA", 100000).execute();

Row city;

while ((city = res.fetchOne()))
{
  DbDoc info = city[2];

  cout << "        ID: " << city[0] << endl;
  cout << "      Name: " << city[1] << endl;
  cout << "Population: " << info["Population"] << endl;
  cout << "=================" << endl;
}

The new APIs can be used as a modern replacement for the previous, JDBC based API of Connector/C++ 1.1 and for the CAPI of the MySQL client library. The X DevAPI brings the advantage and power of modern C++ programming with support for language constructs such as iterators, range loops, method chaining, RAII, overloaded operators, custom type conversions etc. The plain C XAPI is also a major re-design of the traditional MySQL CAPI with automatic memory management, better separation of public interface from internal implementation and with functions for accessing the MySQL Document Store. Note however that these new APIs are implemented over X Protocol and for that reason they will not work with older versions of MySQL Server.

For more information check available documentation on MySQL Document Store and X DevAPI User Guide. See also reference documentation for the Connector/C++ implementation of X DevAPI and XAPI reference documentation.

Getting started with Connector/C++ 8.0

Installing Connector/C++ 8.0

To develop applications that use Connector/C++ 8.0 you need the following files

  • Public headers containing declarations for the APIs implemented by the connector.
  • Connector libraries that contain implementation of the APIs. There are actually two libraries shipped with Connector/C++ 8.0 – the main library with base name mysqlcppconn8, implementing the new APIs (X DevAPI and XAPI), and a legacy library with base name mysqlcppconn which is a drop-in replacement for the 1.1 connector library. Both static and shared variants of each library are shipped.

These files are distributed as TGZ or ZIP packages that you can unpack to the location of your choice. There are several options for how to use the connector during compile time and at run-time, all depending on the platform you are working on and whether you want to install connector locally or system-wide. Below is some basic information to get you started. For more details see usage instructions in the reference manual.

Building code which uses Connector/C++ 8.0

Building code that uses Connector/C++ requires correctly setting include path, so that connector’s public headers can be found by the compiler, and passing connector library to the linker invocation. Assuming that Connector/C++ was installed under $MYSQL_CPPCONN_DIR the include path should be set to $MYSQL_CPPCONN_DIR/include (for gcc use -I option, for MSVC the C/C++ > Additional Include Directories  project setting). After that X DevAPI or XAPI declarations can be loaded using #include <mysqlx/xdevapi.h> or #include <mysqlx/xapi.h> directive, respectively.

Note: The X DevAPI uses C++11 language features. For some compilers C++11 must be explicitly enabled. For example gcc needs option -std=c++11 to understand C++11. This is not required for MSVC nor for XAPI code (which is plain C)

Depending on the platform, the shared Connector/C++ library is named:

  • libmysqlcppconn8.so on Unix platforms (soname libmysqlcppconn8.so.1)
  • libmysqlcppconn8.dylib on the OSX platform (link name libmysqlcppconn8.1.dylib)
  • mysqlcppconn8-1-vs14.dll on Windows platforms (with import library vs14/mysqlcppconn8.lib)

You need to add this library to your compiler/linker invocation when building code that uses the connector  (for gcc add -lmysqlcppconn8 to the linker options, for MSVC add vs14/mysqlcppconn8.lib to Linker > Input > Additional Dependencies  setting of your project). You also need to specify path where the connector library can be found (for gcc use -L option, for MSVC Linker > Additional Library Directories  setting). Assuming that Connector/C++ was installed under $MYSQL_CONCPP_DIR the libraries can be found under $MYSQL_CONCPP_DIR/lib on 32-bit platforms and $MYSQL_CONCPP_DIR/lib64 on 64-bit platforms.

Example gcc invocation for building application with sources in app.cc might look as follows (assuming that environment variable MYSQL_CONCPP_DIR is set to the location where Connector/C++ was installed)

$ g++ -std=c++11 -I $MYSQL_CONCPP_DIR/include -L $MYSQL_CONCPP_DIR/lib64 app.cc -lmysqlcppconn8 -o app

Due to ABI incompatiblities between different compiler versions, the code that uses Connector/C++ libraries should be built with the same compiler version as the connector itself. The information about compiler version used to build connector libraries can be found inside BUILDINFO.txt file distributed with the connector. In principle a different version of the compiler can be used provided that it is ABI compatible, but it is difficult to determine what versions of the compiler are ABI compatible with each other.

Running code which uses Connector/C++ 8.0

Code built against Connector/C++ depends on the shared connector library which must be found at run-time by the dynamic linker. It also requires OpenSSL libraries that are used by Connector/C++.  Here are example run-time dependencies shown by ldd for an application built with Connector/C++.

$ ldd ./app
	linux-vdso.so.1 =>  (0x00007ffc5d616000)
	libmysqlcppconn8.so.1 => ./libmysqlcppconn8.so.1 (0x00007f4f642be000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f4f63f95000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f4f63c93000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4f63a7d000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f4f636be000)
	libssl.so.10 => /lib64/libssl.so.10 (0x00007f4f6344c000)
	libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f4f62feb000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4f62dce000)
	/lib64/ld-linux-x86-64.so.2 (0x000055590017d000)
        ...

To be able to run such an application the dynamic linker must be able to find the connector library in its predefined locations. The easiest way of arranging this is to copy the shared connector library to the location of the executable. This method works for any operating system. Otherwise the exact way of registering Connector/C++ libraries with the dynamic linker depends on the operating system.

Note: For platforms such as Windows, that normally do not have OpenSSL libraries available, Connector/C++ packages include these libraries. Putting these libraries next to the connector ones usually ensures that the dynamic linker can find them at run-time.

Note: On Windows the executable will depend on the MSVC 2015 runtime DLLs, that need to be installed on the target system.

Note: Connector/C++ also ships static libraries that can be used to build applications that do not require shared connector libraries to be present on the target system. However, an application linked statically with Connector/C++ will still depend on shared OpenSSL libraries and on MSVC runtime in case of Windows.

In summary

MySQL 8 brings a lot of new, exciting features which allow you to work with your data in new ways, going beyond the traditional SQL paradigm. Connector/C++ 8.0 is a part of this story and it also invites you to exploring new ways of working with MySQL from your C++ or C code. It is a result of a long effort and we are eager to hear about your impressions of the new features we brought to you. Happy coding!