Hi all,
soci really doesn't have this "is_connected" info available and we can't
rely exclusively on exceptions to know that in a portable way across the
different database backends.
So our approach here was modifying soci at the backend level to try
reconnecting automatically during X seconds, making the execution to throw
a distinct message/code in case it can't do it.
I like our solution because it doesn't change soci's public interface and
AFAIK it also applies to connection_pool once all this logic is effective
during statement execution (which will block a while during reconnection
attempts).
It's working for the postgresql backend here, if any of you got interested
I can provide a patch or a pull request.
Regards,
Ricardo Andrade
On Wed, Mar 27, 2013 at 8:35 AM, Mateusz Loskot <[email protected]> wrote:
> On 27 March 2013 11:19, Krzysztof Bieleń <[email protected]> wrote:
> > W dniu 2013-03-27 12:10, Mateusz Loskot pisze:
> >> On 27 March 2013 11:02, isoul zi <[email protected]> wrote:
> >>> Not to find in soci functions something like soci :: session :: is_open
> >>> Bad looking? It really is not? And you only need to catch the
> exceptions?
> >> You can check if session::get_backend() != nullptr
> >
> > I think that @isoul means that there isn't function which checks if tcp
> > connection with database isn't broken.
>
> Yes, I sensed that.
> I just suggested related test that is currently possible.
>
> > Use case: long running server which doesn't make many queries to server.
> > Before next query it checks if the tcp connection still exists:
> >
> > if (!sql.isConnected())
> > sql.reconect();
> >
> > // ... do query
> >
> > It isn't perfect but provides simple pattern for reconnecting when tcp
> > connection goes out.
>
> Yes, good point.
>
> The trick is that implementing session::is_connected with consistent
> semantic across variety of backends is not easy, it may be impossible.
> For example, function PQstatus check only state cached by libpq library:
>
> session sql(...)
> sql.is_connected() -> CONNECTION_OK
> // someone unplugs power cord of the database server
> sql.is_connected() -> CONNECTION_OK
>
> There is know way libpq to detect external causes of connection lost
> It can detect local causes only.
> Unless,something has changed in libpq lately
>
> > Also maybe there should be possibility to create connection_pool with
> > parameter auto_reconnect = true; which ensures that sessions taken from
> > connection_pool are connected or it will throw execption.
>
> Good idea, if you would be willing to submit pull request, please do so.
> (If it's not a hassle, branch off of 'develop' please into
> feature/yourbranch
> i.e. feature/pool_auto_reconnect, trying to make us flowed by gitflow :))
>
> Best regards,
> --
> Mateusz Loskot, http://mateusz.loskot.net
>
>
> ------------------------------------------------------------------------------
> Own the Future-Intel® Level Up Game Demo Contest 2013
> Rise to greatness in Intel's independent game demo contest.
> Compete for recognition, cash, and the chance to get your game
> on Steam. $5K grand prize plus 10 genre and skill prizes.
> Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
> _______________________________________________
> soci-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/soci-users
>
------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game
on Steam. $5K grand prize plus 10 genre and skill prizes.
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users