Skip to content

Commit

Permalink
fix #35026 fix MSSQL connection on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and nyalldawson committed Oct 1, 2020
1 parent 9c9b070 commit 09f84eb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/providers/mssql/qgsmssqlconnection.cpp
Expand Up @@ -25,6 +25,7 @@
#include <QSqlQuery>
#include <QSet>
#include <QCoreApplication>
#include <QFile>

int QgsMssqlConnection::sConnectionId = 0;
QMutex QgsMssqlConnection::sMutex{ QMutex::Recursive };
Expand Down Expand Up @@ -97,6 +98,16 @@ QSqlDatabase QgsMssqlConnection::getDatabase( const QString &service, const QStr
{
#ifdef Q_OS_WIN
connectionString = "driver={SQL Server}";
#elif defined (Q_OS_MAC)
QString freeTDSDriver( QCoreApplication::applicationDirPath().append( "/lib/libtdsodbc.so" ) );
if ( QFile::exists( freeTDSDriver ) )
{
connectionString = QStringLiteral( "driver=%1;port=1433;TDS_Version=auto" ).arg( freeTDSDriver );
}
else
{
connectionString = QStringLiteral( "driver={FreeTDS};port=1433;TDS_Version=auto" );
}
#else
// It seems that FreeTDS driver by default uses an ancient TDS protocol version (4.2) to communicate with MS SQL
// which was causing various data corruption errors, for example:
Expand Down

0 comments on commit 09f84eb

Please sign in to comment.