From 7b43eed24a592feae9b6ba8fa338fb9737bf089f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 3 Sep 2014 18:37:06 -0500 Subject: Add ability to set reconnect flag on MySQL connections Add database server ping method to SQL classes --- src/sql/drivers/psql/qsql_psql.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/sql/drivers/psql/qsql_psql.cpp') diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 7fe1a91..9d028c0 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -679,6 +679,29 @@ void QPSQLDriver::close() } } +bool QPSQLDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + PGresult *res = NULL; + + // Send ping + res = PQexec( d->connection, "" ); + PQclear(res); + + // Check connection status + if ( PQstatus( d->connection ) != CONNECTION_OK ) { + PQreset( d->connection ); + if ( PQstatus( d->connection ) != CONNECTION_OK ) { + setLastError( qMakeError("Unable to execute ping", QSqlError::Statement, d ) ); + return FALSE; + } + } + return TRUE; +} + QSqlQuery QPSQLDriver::createQuery() const { return QSqlQuery( new QPSQLResult( this, d ) ); -- cgit v1.2.3