[odb-users] Configure MySQL client connection

Aarón Bueno Villares abv150ci at gmail.com
Wed Dec 30 12:38:01 EST 2015


Hi guys,

First of all, thank you for your amazing library. Second, sorry for my
English.

What I would like to do is to configure some parameters of my MySQL
connection, like `SET NAMES` or `SQL_MODE`, but, since each time I'm going
to start a transaction, it catchs a possibly new connection, I understand
that I should send a native SQL query inside each transaction.

For example:

   odb::transaction t(db.begin());
   // Probably a new connection, depending on the underlying factory
   // and the number of threads using connections/transactions).

   t.connection().execute(
        "SET SESSION SQL_MODES='STRICT_ALL_TABLES'"
   );

   auto o_ptr = db.load<User>(3);

   t.commit();

   // more code

   odb::transaction t(db.begin());
   // Probably another different connection.

   t.connection().execute(
       "SET SESSION SQL_MODES='STRICT_ALL_TABLES'"
   );

   auto o_ptr2 = db.load<User>(4); // Other user.

   t.commit();

Is there a way to specify these parameters globally for every connection? A
possible way to avoid that is using a same connection all the time
(suppose, for simplicity, that my application runs just over the main
process' thread) but I'm not sure about how to do that.

Thanks forehand,
Peregring-lk


More information about the odb-users mailing list