summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/mysql
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2016-02-21 15:46:41 -0600
committerSlávek Banko <[email protected]>2016-02-27 01:15:25 +0100
commit9c08980957eb98fc699b4141f0ef2bff2555168c (patch)
tree75d9d986ae8994a16c6a39193b45407d53f3a852 /src/sql/drivers/mysql
parentdc2dea07f70096f5a771b17a63f4c4f5fe8a809c (diff)
downloadqt3-9c08980957eb98fc699b4141f0ef2bff2555168c.tar.gz
qt3-9c08980957eb98fc699b4141f0ef2bff2555168c.zip
Properly handle MySQL reconnection option
(cherry picked from commit 9fe256ac6ce302572f46bad25f52092fdf9e63c5)
Diffstat (limited to 'src/sql/drivers/mysql')
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index f1d48d4..4b576d9 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -466,7 +466,7 @@ bool QMYSQLDriver::open( const QString& db,
if ( isOpen() )
close();
- unsigned int optionFlags = 0;
+ unsigned int clientOptionFlags = 0;
QStringList raw = QStringList::split( ';', connOpts );
QStringList opts;
@@ -487,38 +487,44 @@ bool QMYSQLDriver::open( const QString& db,
opts << tmp;
}
}
-
+
+ if (!(d->mysql = mysql_init((MYSQL*) 0))) {
+ setLastError( qMakeError( "Unable to connect", QSqlError::Connection, d ) );
+ mysql_close( d->mysql );
+ setOpenError( TRUE );
+ return FALSE;
+ }
+
for ( it = opts.begin(); it != opts.end(); ++it ) {
QString opt( (*it).upper() );
if ( opt == "CLIENT_COMPRESS" )
- optionFlags |= CLIENT_COMPRESS;
+ clientOptionFlags |= CLIENT_COMPRESS;
else if ( opt == "CLIENT_FOUND_ROWS" )
- optionFlags |= CLIENT_FOUND_ROWS;
+ clientOptionFlags |= CLIENT_FOUND_ROWS;
else if ( opt == "CLIENT_IGNORE_SPACE" )
- optionFlags |= CLIENT_IGNORE_SPACE;
+ clientOptionFlags |= CLIENT_IGNORE_SPACE;
else if ( opt == "CLIENT_INTERACTIVE" )
- optionFlags |= CLIENT_INTERACTIVE;
+ clientOptionFlags |= CLIENT_INTERACTIVE;
else if ( opt == "CLIENT_NO_SCHEMA" )
- optionFlags |= CLIENT_NO_SCHEMA;
+ clientOptionFlags |= CLIENT_NO_SCHEMA;
else if ( opt == "CLIENT_ODBC" )
- optionFlags |= CLIENT_ODBC;
+ clientOptionFlags |= CLIENT_ODBC;
else if ( opt == "CLIENT_SSL" )
- optionFlags |= CLIENT_SSL;
+ clientOptionFlags |= CLIENT_SSL;
else if ( opt == "MYSQL_OPT_RECONNECT" )
- optionFlags |= MYSQL_OPT_RECONNECT;
+ mysql_options(d->mysql, MYSQL_OPT_RECONNECT, NULL);
else
qWarning( "QMYSQLDriver::open: Unknown connect option '%s'", (*it).latin1() );
}
- if ( (d->mysql = mysql_init((MYSQL*) 0)) &&
- mysql_real_connect( d->mysql,
+ if ( mysql_real_connect( d->mysql,
host,
user,
password,
db.isNull() ? QString("") : db,
(port > -1) ? port : 0,
NULL,
- optionFlags ) )
+ clientOptionFlags ) )
{
if ( !db.isEmpty() && mysql_select_db( d->mysql, db )) {
setLastError( qMakeError("Unable open database '" + db + "'", QSqlError::Connection, d ) );