Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2008
General QSqlDatabase connection questions


Message 1 in thread

disclamer: I am very new to the Qt API.

I've found that I can connect to a PostgreSQL database just fine.
Query it, work with data...etc.  No Problem.

The problem I'm looking to gracefully deal with is when a connection is 
suddenly and unexpectedly disconnected.
For example, if I pull the ethernet cable after a connection is made.
In this scenario, after the connection is made and isOpen() says yes, I yank 
the ethernet cable - .isOpen() continues to say yes.
Additionally, if I submit a query via .exec(Qstring), it just hangs.  Maybe it 
would timeout eventually - I've only waited 3 minutes.

I've tried db->setConnectOptions("connect_timeout=10;"); as described here: 
http://doc.trolltech.com/4.2/qsqldatabase.html#setConnectOptions
But...
1 - that doesn't cause connection to timeout after 10 seconds, as I suspect it 
should.
2  - that parameter refers to connections, not executions of queries.

So:
Why does connect_timeout=10 as a connection option not set the connection 
timeout to 10 seconds?
What is the preferred method for testing an established connection?
How can I make an exec timeout a little faster?

Thanks

--
 [ signature omitted ] 

Message 2 in thread

Rick Vernam wrote:
> disclamer: I am very new to the Qt API.
> 
> I've found that I can connect to a PostgreSQL database just fine.
> Query it, work with data...etc.  No Problem.
> 
> The problem I'm looking to gracefully deal with is when a connection is 
> suddenly and unexpectedly disconnected.
> For example, if I pull the ethernet cable after a connection is made.
> In this scenario, after the connection is made and isOpen() says yes, I yank 
> the ethernet cable - .isOpen() continues to say yes.
> Additionally, if I submit a query via .exec(Qstring), it just hangs.  Maybe it 
> would timeout eventually - I've only waited 3 minutes.
> 
> I've tried db->setConnectOptions("connect_timeout=10;"); as described here: 
> http://doc.trolltech.com/4.2/qsqldatabase.html#setConnectOptions
> But...
> 1 - that doesn't cause connection to timeout after 10 seconds, as I suspect it 
> should.
> 2  - that parameter refers to connections, not executions of queries.
> 
> So:
> Why does connect_timeout=10 as a connection option not set the connection 
> timeout to 10 seconds?
> What is the preferred method for testing an established connection?
> How can I make an exec timeout a little faster?
> 
> Thanks
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

Are you using setConnectOptions before you open the connection? It has 
no effect if you use it on an open connection. A simple thing but I have 
to ask :)  Also, I believe that connect_timeout only applies to the 
actual connection phase of your database session (i.e. when you call 
db->open()).

As for checking the connection, there doesn't seem to be a pretty way to 
do that... if you can afford the overhead and it is critical that you 
know if the connection is open, you may just want to re-open the 
connection before executing a query.

Hope that helps,
Stuart

--
 [ signature omitted ]