Solved Code::Blocks connectors for MySql

Hello,
I develop in C ++ since Code :: blocks, at first I would have made SQL queries since MySql 5.6 server, I have a code examples but I do not find where to put the ODBC / C ++ connector since C :: B.
Especially I can not find on the oracle site where to find the "headers" >> .h that the <main> program asks me. here is a first simple example :

Code:
#include <stdlib.h>
#include <iostream>
/* here where found the headers */

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »
   AS _message'..." << endl;

try {
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;

  /* Create a connection */
  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
  /* Connect to the MySQL test database */
  con->setSchema("test");

  stmt = con->createStatement();
  res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
  while (res->next()) {
    cout << "\t... MySQL replies: ";
    /* Access column data by alias or column name */
    cout << res->getString("_message") << endl;
    cout << "\t... MySQL says it again: ";
    /* Access column data by numeric offset, 1 is the first column */
    cout << res->getString(1) << endl;
  }
  delete res;
  delete stmt;
  delete con;

} catch (sql::SQLException &e) {
  cout << "# ERR: SQLException in " << __FILE__;
  cout << "(" << __FUNCTION__ << ") on line " »
     << __LINE__ << endl;
  cout << "# ERR: " << e.what();
  cout << " (MySQL error code: " << e.getErrorCode();
  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << endl;

return EXIT_SUCCESS;
}

I compiled the connector for the following ports:
1/
/usr/ports/databases/mysql-connector-c++
in this connector, is there what I look for the headers missing from my program "hello world", I should find, but I do not know where it is stored.
2/
/usr/ports/databases/mysql-connector-odbc
I do not see in the C :: B settings where to put the C ++ or ODBC connector ?

Regards
Philippe
 
I tried this:

% pkg install mysql-connector-c++

After the install, I see header files in /usr/local/include ...

% ls /usr/local/include/mysql*

/usr/local/include/mysql_connection.h
/usr/local/include/mysql_driver.h
/usr/local/include/mysql_error.h


/usr/local/include/mysql:
big_endian.h
byte_order_generic.h
byte_order_generic_x86.h
byte_order_generic_x86_64.h
decimal.h
errmsg.h
hash.h
keycache.h
little_endian.h
m_ctype.h
m_string.h
my_alloc.h
my_attribute.h
my_byteorder.h
my_compiler.h
my_config.h
my_dbug.h
my_dir.h
my_getopt.h
my_global.h
my_list.h
my_net.h
my_pthread.h
my_sys.h
my_xml.h
mysql
mysql.h
mysql_com.h
mysql_com_server.h
mysql_embed.h
mysql_time.h
mysql_version.h
mysqld_ername.h
mysqld_error.h
plugin.h
plugin_audit.h
plugin_ftparser.h
plugin_validate_password.h
sql_common.h
sql_state.h
sslopt-case.h
sslopt-longopts.h
sslopt-vars.h
typelib.h
 
i following your recommandations but i have only this headers files:
Code:
 ls
big_endian.h           my_pthread.h
byte_order_generic_x86_64.h   my_sys.h
byte_order_generic_x86.h   my_xml.h
byte_order_generic.h       mysql
decimal.h           mysql_com_server.h
errmsg.h           mysql_com.h
hash.h               mysql_embed.h
keycache.h           mysql_time.h
little_endian.h           mysql_version.h
m_ctype.h           mysql.h
m_string.h           mysqld_ername.h
my_alloc.h           mysqld_error.h
my_attribute.h           plugin_audit.h
my_byteorder.h           plugin_ftparser.h
my_compiler.h           plugin_validate_password.h
my_config.h           plugin.h
my_dbug.h           sql_common.h
my_dir.h           sql_state.h
my_getopt.h           sslopt-case.h
my_global.h           sslopt-longopts.h
my_list.h           sslopt-vars.h
my_net.h           typelib.h
$
there are missing :
Code:
#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
 
It looks like you have the files.

Some files are in /usr/local/include.
Some files are in /usr/local/include/mysql.
Other files are in /usr/local/include/cppcon.

Give Codeblocks the "I" and "L" switches eg. -I/usr/local/include and -L/usr/local/lib.

Go to the projects tab.
The project name is one line under "Workspace".
Right-click on the project name.
Select "Build Options".
Select the "Search Directories" tab.
Under "Compiler" enter "/usr/local/include".
Under "Linker", enter "/usr/local/lib".
Click "OK" to save.

You may need to repeat this for Debug vs. Release.
 
root@dct-soleil:/usr/local/include # cd /usr/local/include/cppcon
/usr/local/include/cppcon: No such file or directory.
root@dct-soleil:/usr/local/include #

is't not /cppcon but /cppconn
 
Back
Top