summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2014-09-03 18:37:06 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2014-09-03 18:37:06 -0500
commit7b43eed24a592feae9b6ba8fa338fb9737bf089f (patch)
tree64290972b342da11439be46b3658983151f4bec0 /src/sql/drivers
parent4de369738339e5755968b1bcbae0baa515917386 (diff)
downloadqt3-7b43eed24a592feae9b6ba8fa338fb9737bf089f.tar.gz
qt3-7b43eed24a592feae9b6ba8fa338fb9737bf089f.zip
Add ability to set reconnect flag on MySQL connections
Add database server ping method to SQL classes
Diffstat (limited to 'src/sql/drivers')
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.cpp11
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.h1
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp17
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.h1
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp7
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.h1
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp23
-rw-r--r--src/sql/drivers/psql/qsql_psql.h1
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.cpp11
-rw-r--r--src/sql/drivers/sqlite/qsql_sqlite.h1
-rw-r--r--src/sql/drivers/sqlite3/qsql_sqlite3.cpp11
-rw-r--r--src/sql/drivers/sqlite3/qsql_sqlite3.h1
12 files changed, 86 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();