[odb-users] Configure MySQL client connection

Aarón Bueno Villares abv150ci at gmail.com
Wed Jan 13 20:54:26 EST 2016

Thanks for you reply. It's pretty clear.

There is, however, a possibility that the (network) connection to the
> database will be lost at some point. In
> this case, the pool will try to automatically re-connect by creating a new
> connection.

In the case of disconnection... for example, if in a constructor of a class
(a main class which lifecycle is the application's one), I create a
transaction, and call transaction::connection() to asign the returned
reference to a member of my object (for example, to be used/check later or
whatever), and the connection is lost, will that connection object be
destroyed under any circunstance?

My doubt comes from that sentence from the docs:

To obtain a connection we call the database::connection() function. The
> connection is returned as odb::connection_ptr, which is an
> implementation-specific smart pointer with the shared pointer semantics.
> (...). Once the last instance of connection_ptr pointing to the same
> connection is destroyed, the connection is returned to the database
> instance.

So since as you said, after a disconnection the database will try to get a
new connection, it means that it won't reuse the previous connection
object, and consequently, it is useless and can be a target of deletion if
"there is no more instances of connection_ptr pointing to the same
connection" (if there's no more instances of connection_ptr, the database
thinks it's the only owner of the object, and thus, it can delete it if it
is useless).

But, since I have got the connection as a reference, and saved that
connection, it could point to a destroyed object because the database
thought nobody had access to it.

Is it that scene likely, or the internal behaviour of ODB works differently
as I've depicted?

More information about the odb-users mailing list