diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 6a1d0abf..ee2976d6 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -848,6 +848,17 @@ void TQIBaseDriver::close() } } +bool TQIBaseDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + TQSqlQuery TQIBaseDriver::createQuery() const { return TQSqlQuery(new TQIBaseResult(this)); diff --git a/src/sql/drivers/ibase/qsql_ibase.h b/src/sql/drivers/ibase/qsql_ibase.h index 45cb4b86..023a6b02 100644 --- a/src/sql/drivers/ibase/qsql_ibase.h +++ b/src/sql/drivers/ibase/qsql_ibase.h @@ -94,6 +94,7 @@ public: const TQString & host, int port ) { return open (db, user, password, host, port, TQString()); } void close(); + bool ping(); TQSqlQuery createQuery() const; bool beginTransaction(); bool commitTransaction(); diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index aca83545..aad84624 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -504,6 +504,8 @@ bool TQMYSQLDriver::open( const TQString& db, optionFlags |= CLIENT_ODBC; else if ( opt == "CLIENT_SSL" ) optionFlags |= CLIENT_SSL; + else if ( opt == "MYSQL_OPT_RECONNECT" ) + optionFlags |= MYSQL_OPT_RECONNECT; else tqWarning( "TQMYSQLDriver::open: Unknown connect option '%s'", (*it).latin1() ); } @@ -544,6 +546,21 @@ void TQMYSQLDriver::close() } } +bool TQMYSQLDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + if (mysql_ping( d->mysql )) { + return TRUE; + } + else { + setLastError( qMakeError("Unable to execute ping", TQSqlError::Statement, d ) ); + return FALSE; + } +} + TQSqlQuery TQMYSQLDriver::createQuery() const { return TQSqlQuery( new TQMYSQLResult( this ) ); diff --git a/src/sql/drivers/mysql/qsql_mysql.h b/src/sql/drivers/mysql/qsql_mysql.h index 6b1daef3..e4646256 100644 --- a/src/sql/drivers/mysql/qsql_mysql.h +++ b/src/sql/drivers/mysql/qsql_mysql.h @@ -100,6 +100,7 @@ public: const TQString & host = TQString::null, int port = -1 ); void close(); + bool ping(); TQSqlQuery createQuery() const; TQStringList tables( const TQString& user ) const; TQSqlIndex primaryIndex( const TQString& tablename ) const; diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 40739b36..3bedbb8c 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -1490,6 +1490,13 @@ void TQODBCDriver::close() setOpenError( FALSE ); } +bool TQODBCDriver::ping() +{ + // FIXME + // Implement ping if supported + return TRUE; +} + void TQODBCDriver::cleanup() { SQLRETURN r; diff --git a/src/sql/drivers/odbc/qsql_odbc.h b/src/sql/drivers/odbc/qsql_odbc.h index 0ce01703..619212d4 100644 --- a/src/sql/drivers/odbc/qsql_odbc.h +++ b/src/sql/drivers/odbc/qsql_odbc.h @@ -128,6 +128,7 @@ public: const TQString & host = TQString::null, int port = -1 ); void close(); + bool ping(); TQSqlQuery createQuery() const; TQStringList tables( const TQString& user ) const; TQSqlRecord record( const TQString& tablename ) const; diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 033c69f3..8e2c02ad 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -679,6 +679,29 @@ void TQPSQLDriver::close() } } +bool TQPSQLDriver::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", TQSqlError::Statement, d ) ); + return FALSE; + } + } + return TRUE; +} + TQSqlQuery TQPSQLDriver::createQuery() const { return TQSqlQuery( new TQPSQLResult( this, d ) ); diff --git a/src/sql/drivers/psql/qsql_psql.h b/src/sql/drivers/psql/qsql_psql.h index dd1ddc71..6f9c4f5f 100644 --- a/src/sql/drivers/psql/qsql_psql.h +++ b/src/sql/drivers/psql/qsql_psql.h @@ -98,6 +98,7 @@ public: const TQString & host = TQString::null, int port = -1 ); void close(); + bool ping(); TQSqlQuery createQuery() const; TQStringList tables( const TQString& user ) const; TQSqlIndex primaryIndex( const TQString& tablename ) const; diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index ece3b9ee..92a66c72 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -352,6 +352,17 @@ void TQSQLiteDriver::close() } } +bool TQSQLiteDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + TQSqlQuery TQSQLiteDriver::createQuery() const { return TQSqlQuery(new TQSQLiteResult(this)); diff --git a/src/sql/drivers/sqlite/qsql_sqlite.h b/src/sql/drivers/sqlite/qsql_sqlite.h index ff05ede6..b90662c0 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.h +++ b/src/sql/drivers/sqlite/qsql_sqlite.h @@ -72,6 +72,7 @@ public: const TQString & host, int port ) { return open (db, user, password, host, port, TQString()); } void close(); + bool ping(); TQSqlQuery createQuery() const; bool beginTransaction(); bool commitTransaction(); diff --git a/src/sql/drivers/sqlite3/qsql_sqlite3.cpp b/src/sql/drivers/sqlite3/qsql_sqlite3.cpp index a756c7da..4d79cb4e 100644 --- a/src/sql/drivers/sqlite3/qsql_sqlite3.cpp +++ b/src/sql/drivers/sqlite3/qsql_sqlite3.cpp @@ -336,6 +336,17 @@ void TQSQLite3Driver::close() } } +bool TQSQLite3Driver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + TQSqlQuery TQSQLite3Driver::createQuery() const { return TQSqlQuery(new TQSQLite3Result(this)); diff --git a/src/sql/drivers/sqlite3/qsql_sqlite3.h b/src/sql/drivers/sqlite3/qsql_sqlite3.h index 4d79176a..facd85a1 100644 --- a/src/sql/drivers/sqlite3/qsql_sqlite3.h +++ b/src/sql/drivers/sqlite3/qsql_sqlite3.h @@ -72,6 +72,7 @@ public: const TQString & host, int port ) { return open (db, user, password, host, port, TQString()); } void close(); + bool ping(); TQSqlQuery createQuery() const; bool beginTransaction(); bool commitTransaction(); diff --git a/src/sql/ntqsqldatabase.h b/src/sql/ntqsqldatabase.h index 2423fd2c..b44735e6 100644 --- a/src/sql/ntqsqldatabase.h +++ b/src/sql/ntqsqldatabase.h @@ -95,6 +95,7 @@ public: bool open(); bool open( const TQString& user, const TQString& password ); void close(); + bool ping(); bool isOpen() const; bool isOpenError() const; TQStringList tables() const; diff --git a/src/sql/ntqsqldriver.h b/src/sql/ntqsqldriver.h index 5da90309..09c74b24 100644 --- a/src/sql/ntqsqldriver.h +++ b/src/sql/ntqsqldriver.h @@ -98,6 +98,7 @@ public: const TQString & host = TQString::null, int port = -1 ) = 0; virtual void close() = 0; + virtual bool ping() = 0; virtual TQSqlQuery createQuery() const = 0; // ### remove for 4.0 diff --git a/src/sql/qsqldatabase.cpp b/src/sql/qsqldatabase.cpp index 606adb9f..cc38f86f 100644 --- a/src/sql/qsqldatabase.cpp +++ b/src/sql/qsqldatabase.cpp @@ -144,6 +144,7 @@ public: return FALSE; } void close() {} + bool ping() { return TRUE; } TQSqlQuery createQuery() const { return TQSqlQuery( new TQNullResult(this) ); } }; @@ -795,6 +796,15 @@ void TQSqlDatabase::close() d->driver->close(); } +/*! + Sends a ping to the database server. +*/ + +bool TQSqlDatabase::ping() +{ + return d->driver->ping(); +} + /*! Returns TRUE if the database connection is currently open; otherwise returns FALSE.