diff options
-rw-r--r-- | src/sql/drivers/ibase/qsql_ibase.cpp | 11 | ||||
-rw-r--r-- | src/sql/drivers/ibase/qsql_ibase.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 17 | ||||
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 7 | ||||
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/psql/qsql_psql.cpp | 23 | ||||
-rw-r--r-- | src/sql/drivers/psql/qsql_psql.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 11 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.h | 1 | ||||
-rw-r--r-- | src/sql/drivers/sqlite3/qsql_sqlite3.cpp | 11 | ||||
-rw-r--r-- | src/sql/drivers/sqlite3/qsql_sqlite3.h | 1 | ||||
-rw-r--r-- | src/sql/qsqldatabase.cpp | 10 | ||||
-rw-r--r-- | src/sql/qsqldatabase.h | 1 | ||||
-rw-r--r-- | src/sql/qsqldriver.h | 1 |
15 files changed, 98 insertions, 0 deletions
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 6954ef8..a280712 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -848,6 +848,17 @@ void QIBaseDriver::close() } } +bool QIBaseDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + QSqlQuery QIBaseDriver::createQuery() const { return QSqlQuery(new QIBaseResult(this)); diff --git a/src/sql/drivers/ibase/qsql_ibase.h b/src/sql/drivers/ibase/qsql_ibase.h index 563f509..d27a567 100644 --- a/src/sql/drivers/ibase/qsql_ibase.h +++ b/src/sql/drivers/ibase/qsql_ibase.h @@ -94,6 +94,7 @@ public: const QString & host, int port ) { return open (db, user, password, host, port, QString()); } void close(); + bool ping(); QSqlQuery 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 7cfe0a7..f1d48d4 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -504,6 +504,8 @@ bool QMYSQLDriver::open( const QString& db, optionFlags |= CLIENT_ODBC; else if ( opt == "CLIENT_SSL" ) optionFlags |= CLIENT_SSL; + else if ( opt == "MYSQL_OPT_RECONNECT" ) + optionFlags |= MYSQL_OPT_RECONNECT; else qWarning( "QMYSQLDriver::open: Unknown connect option '%s'", (*it).latin1() ); } @@ -544,6 +546,21 @@ void QMYSQLDriver::close() } } +bool QMYSQLDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + if (mysql_ping( d->mysql )) { + return TRUE; + } + else { + setLastError( qMakeError("Unable to execute ping", QSqlError::Statement, d ) ); + return FALSE; + } +} + QSqlQuery QMYSQLDriver::createQuery() const { return QSqlQuery( new QMYSQLResult( this ) ); diff --git a/src/sql/drivers/mysql/qsql_mysql.h b/src/sql/drivers/mysql/qsql_mysql.h index ff8ace6..e5633dc 100644 --- a/src/sql/drivers/mysql/qsql_mysql.h +++ b/src/sql/drivers/mysql/qsql_mysql.h @@ -100,6 +100,7 @@ public: const QString & host = QString::null, int port = -1 ); void close(); + bool ping(); QSqlQuery createQuery() const; QStringList tables( const QString& user ) const; QSqlIndex primaryIndex( const QString& tablename ) const; diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 46c5a6c..9b095e7 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -1490,6 +1490,13 @@ void QODBCDriver::close() setOpenError( FALSE ); } +bool QODBCDriver::ping() +{ + // FIXME + // Implement ping if supported + return TRUE; +} + void QODBCDriver::cleanup() { SQLRETURN r; diff --git a/src/sql/drivers/odbc/qsql_odbc.h b/src/sql/drivers/odbc/qsql_odbc.h index 67285c8..18a39a1 100644 --- a/src/sql/drivers/odbc/qsql_odbc.h +++ b/src/sql/drivers/odbc/qsql_odbc.h @@ -128,6 +128,7 @@ public: const QString & host = QString::null, int port = -1 ); void close(); + bool ping(); QSqlQuery createQuery() const; QStringList tables( const QString& user ) const; QSqlRecord record( const QString& tablename ) const; 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 ) ); diff --git a/src/sql/drivers/psql/qsql_psql.h b/src/sql/drivers/psql/qsql_psql.h index fd9cbe6..b0e4f8c 100644 --- a/src/sql/drivers/psql/qsql_psql.h +++ b/src/sql/drivers/psql/qsql_psql.h @@ -98,6 +98,7 @@ public: const QString & host = QString::null, int port = -1 ); void close(); + bool ping(); QSqlQuery createQuery() const; QStringList tables( const QString& user ) const; QSqlIndex primaryIndex( const QString& tablename ) const; diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index f8c7ffa..fea2a63 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -352,6 +352,17 @@ void QSQLiteDriver::close() } } +bool QSQLiteDriver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + QSqlQuery QSQLiteDriver::createQuery() const { return QSqlQuery(new QSQLiteResult(this)); diff --git a/src/sql/drivers/sqlite/qsql_sqlite.h b/src/sql/drivers/sqlite/qsql_sqlite.h index f3b9192..1e3f84b 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.h +++ b/src/sql/drivers/sqlite/qsql_sqlite.h @@ -72,6 +72,7 @@ public: const QString & host, int port ) { return open (db, user, password, host, port, QString()); } void close(); + bool ping(); QSqlQuery 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 0bd20d9..42fc1aa 100644 --- a/src/sql/drivers/sqlite3/qsql_sqlite3.cpp +++ b/src/sql/drivers/sqlite3/qsql_sqlite3.cpp @@ -336,6 +336,17 @@ void QSQLite3Driver::close() } } +bool QSQLite3Driver::ping() +{ + if ( !isOpen() ) { + return FALSE; + } + + // FIXME + // Implement ping if available + return TRUE; +} + QSqlQuery QSQLite3Driver::createQuery() const { return QSqlQuery(new QSQLite3Result(this)); diff --git a/src/sql/drivers/sqlite3/qsql_sqlite3.h b/src/sql/drivers/sqlite3/qsql_sqlite3.h index e92022f..5694f83 100644 --- a/src/sql/drivers/sqlite3/qsql_sqlite3.h +++ b/src/sql/drivers/sqlite3/qsql_sqlite3.h @@ -72,6 +72,7 @@ public: const QString & host, int port ) { return open (db, user, password, host, port, QString()); } void close(); + bool ping(); QSqlQuery createQuery() const; bool beginTransaction(); bool commitTransaction(); diff --git a/src/sql/qsqldatabase.cpp b/src/sql/qsqldatabase.cpp index 8a4f885..9a16d1c 100644 --- a/src/sql/qsqldatabase.cpp +++ b/src/sql/qsqldatabase.cpp @@ -144,6 +144,7 @@ public: return FALSE; } void close() {} + bool ping() { return TRUE; } QSqlQuery createQuery() const { return QSqlQuery( new QNullResult(this) ); } }; @@ -796,6 +797,15 @@ void QSqlDatabase::close() } /*! + Sends a ping to the database server. +*/ + +bool QSqlDatabase::ping() +{ + return d->driver->ping(); +} + +/*! Returns TRUE if the database connection is currently open; otherwise returns FALSE. */ diff --git a/src/sql/qsqldatabase.h b/src/sql/qsqldatabase.h index fb07513..c605f58 100644 --- a/src/sql/qsqldatabase.h +++ b/src/sql/qsqldatabase.h @@ -95,6 +95,7 @@ public: bool open(); bool open( const QString& user, const QString& password ); void close(); + bool ping(); bool isOpen() const; bool isOpenError() const; QStringList tables() const; diff --git a/src/sql/qsqldriver.h b/src/sql/qsqldriver.h index 4115bc6..959ebc3 100644 --- a/src/sql/qsqldriver.h +++ b/src/sql/qsqldriver.h @@ -98,6 +98,7 @@ public: const QString & host = QString::null, int port = -1 ) = 0; virtual void close() = 0; + virtual bool ping() = 0; virtual QSqlQuery createQuery() const = 0; // ### remove for 4.0 |