Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the native C API connection structure from MySQL Connector/C++?

I'm using the MySQL Connector/C++ to communicate with a MySQL server from a C++ program. For some reason (see below for the background), I need at some point the native C API connection structure. How do I get it from the Connector/C++ classes?

Background:

I want to load a huge amount of data (up to 2-3 billion tuples) from the client's main memory into the server. Therefore, I want to try the LOAD DATA INFILE statement. To avoid to write the whole data to a text file first, I want to define my own local infile handler, which reads the data directly from the main memory.

However, the Connector/C++ comes with no method to set user-defined local infile handlers, but the native C API does. The corresponding C function mysql_set_local_infile_handler() needs a native connection handler (the structure MYSQL) as input parameter. So how do I get this handler from the Connector/C++? Or is there any better way to set the local infile handler in a Connector/C++ environment?

like image 573
user1494080 Avatar asked Nov 03 '22 06:11

user1494080


1 Answers

You want sql::mysql::NativeAPI::MySQL_NativeConnectionWrapper::mysql, but it is a private member that is not returned by any method. Therefore, to access the structure, you will have to fork the Connector/C++ source and compile your own connector.

If that's the path you take, you might prefer to provide access to mysql_set_local_infile_handler() from within Connector/C++.

like image 151
eggyal Avatar answered Nov 08 '22 03:11

eggyal