diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-10-13 10:09:19 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-10-13 10:09:20 +0200 |
commit | 57fead6100c69128ef6cc483b78ba91e477e8851 (patch) | |
tree | 241d145d647fedd587fe850a6c1b7d0dffbd6f68 /src/sql/drivers/mysql/qsql_mysql.cpp | |
parent | a2f6ece27f95eb7cb9940af6ba734d4ba52bf4cb (diff) | |
parent | 6542161d5c698d461a11f0e5ca6cc2a00d33a824 (diff) |
Merge remote-tracking branch 'origin/5.5.1' into 5.5
Change-Id: I2942591e1c1ca86ce0f6476e0a5c3033cdf861ee
Diffstat (limited to 'src/sql/drivers/mysql/qsql_mysql.cpp')
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index d901008e00..8ac7f765e2 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -1282,19 +1282,21 @@ bool QMYSQLDriver::open(const QString& db, if (writeTimeout != 0) mysql_options(d->mysql, MYSQL_OPT_WRITE_TIMEOUT, &writeTimeout); #endif - if (mysql_real_connect(d->mysql, - host.isNull() ? static_cast<const char *>(0) - : host.toLocal8Bit().constData(), - user.isNull() ? static_cast<const char *>(0) - : user.toLocal8Bit().constData(), - password.isNull() ? static_cast<const char *>(0) - : password.toLocal8Bit().constData(), - db.isNull() ? static_cast<const char *>(0) - : db.toLocal8Bit().constData(), - (port > -1) ? port : 0, - unixSocket.isNull() ? static_cast<const char *>(0) - : unixSocket.toLocal8Bit().constData(), - optionFlags)) { + MYSQL *mysql = mysql_real_connect(d->mysql, + host.isNull() ? static_cast<const char *>(0) + : host.toLocal8Bit().constData(), + user.isNull() ? static_cast<const char *>(0) + : user.toLocal8Bit().constData(), + password.isNull() ? static_cast<const char *>(0) + : password.toLocal8Bit().constData(), + db.isNull() ? static_cast<const char *>(0) + : db.toLocal8Bit().constData(), + (port > -1) ? port : 0, + unixSocket.isNull() ? static_cast<const char *>(0) + : unixSocket.toLocal8Bit().constData(), + optionFlags); + + if (mysql == d->mysql) { if (!db.isEmpty() && mysql_select_db(d->mysql, db.toLocal8Bit().constData())) { setLastError(qMakeError(tr("Unable to open database '%1'").arg(db), QSqlError::ConnectionError, d)); mysql_close(d->mysql); @@ -1305,12 +1307,17 @@ bool QMYSQLDriver::open(const QString& db, if (reconnect) mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect); #endif + } else { + setLastError(qMakeError(tr("Unable to connect"), + QSqlError::ConnectionError, d)); + mysql_close(d->mysql); + d->mysql = NULL; + setOpenError(true); + return false; } } else { - setLastError(qMakeError(tr("Unable to connect"), - QSqlError::ConnectionError, d)); - mysql_close(d->mysql); - d->mysql = NULL; + setLastError(qMakeError(tr("Failed to allocated data"), + QSqlError::UnknownError, d)); setOpenError(true); return false; } |