Skip to content

Commit

Permalink
More detailed warnings when HANA driver not found
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored and nyalldawson committed Jan 16, 2021
1 parent bbd433a commit df2c9ff
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
28 changes: 24 additions & 4 deletions src/providers/hana/qgshanadriver.cpp
Expand Up @@ -19,6 +19,7 @@

#include <QDir>
#include <QFileInfo>
#include <QLibrary>

#include "odbc/Connection.h"
#include "odbc/Environment.h"
Expand Down Expand Up @@ -69,18 +70,37 @@ QgsHanaDriver::~QgsHanaDriver()
QgsDebugCall;
}

ConnectionRef QgsHanaDriver::createConnection()
{
return mEnv->createConnection();
}

const QString &QgsHanaDriver::driver() const
{
return mDriver;
}

QgsHanaDriver *QgsHanaDriver::instance()
{
static QgsHanaDriver instance;
return &instance;
}

ConnectionRef QgsHanaDriver::createConnection()
bool QgsHanaDriver::isInstalled( const QString &name )
{
return mEnv->createConnection();
EnvironmentRef env = Environment::create();
return env->isDriverInstalled( name.toStdString().c_str() );
}

const QString &QgsHanaDriver::driver() const
bool QgsHanaDriver::isValidPath( const QString &path )
{
return mDriver;
if ( !QLibrary::isLibrary( path ) )
return false;

QLibrary lib( path );
if ( !lib.load() )
return false;
bool ret = lib.resolve( "SQLConnect" ) != nullptr;
lib.unload();
return ret;
}
2 changes: 2 additions & 0 deletions src/providers/hana/qgshanadriver.h
Expand Up @@ -32,6 +32,8 @@ class QgsHanaDriver
const QString &driver() const;

static QgsHanaDriver *instance();
static bool isInstalled( const QString &name );
static bool isValidPath( const QString &path );

protected:
Q_DISABLE_COPY( QgsHanaDriver )
Expand Down
39 changes: 36 additions & 3 deletions src/providers/hana/qgshananewconnection.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgshanasettings.h"
#include "qgssettings.h"

#include <QFileInfo>
#include <QInputDialog>
#include <QMessageBox>

Expand Down Expand Up @@ -56,6 +57,17 @@ QgsHanaNewConnection::QgsHanaNewConnection(
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsHanaNewConnection::showHelp );

txtDriver->setText( QgsHanaDriver::instance()->driver() );
#if defined(Q_OS_WIN)
txtDriver->setToolTip( tr( "The name of the HANA ODBC driver.\r\n\r\n"
"The HANA ODBC driver is a part of the SAP HANA Client,\r\n"
"which can be found at https://tools.hana.ondemand.com/#hanatools." ) );
#else
txtDriver->setToolTip( tr( "The name or path to the HANA ODBC driver.\r\n\r\n"
"If the driver is registered in odbcinst.ini, enter the driver's name.\r\n"
"Otherwise, enter the path to the driver (libodbcHDB.so).\r\n\r\n"
"The HANA ODBC driver is a part of the SAP HANA Client,\r\n"
"which can be found at https://tools.hana.ondemand.com/#hanatools." ) );
#endif

cbxCryptoProvider->addItem( QStringLiteral( "openssl" ), QStringLiteral( "openssl" ) );
cbxCryptoProvider->addItem( QStringLiteral( "commoncrypto" ), QStringLiteral( "commoncrypto" ) );
Expand Down Expand Up @@ -296,9 +308,7 @@ void QgsHanaNewConnection::updateControlsFromSettings( const QgsHanaSettings &se
void QgsHanaNewConnection::testConnection()
{
QString warningMsg;
if ( txtDriver->text().isEmpty() )
warningMsg = tr( "Driver name has not been specified." );
else if ( txtHost->text().isEmpty() )
if ( txtHost->text().isEmpty() )
warningMsg = tr( "Host name has not been specified." );
else if ( rbtnMultipleContainers->isChecked() && rbtnTenantDatabase->isChecked() &&
txtTenantDatabaseName->text().isEmpty() )
Expand All @@ -309,6 +319,29 @@ void QgsHanaNewConnection::testConnection()
warningMsg = tr( "Password has not been specified." );
else if ( txtIdentifier->text().isEmpty() )
warningMsg = tr( "Identifier has not been specified." );
else
{
QString driver = txtDriver->text();
if ( driver.isEmpty() )
warningMsg = tr( "Driver name/path has not been specified." );
else
{
if ( !QgsHanaDriver::isInstalled( driver ) )
{
#if defined(Q_OS_WIN)
warningMsg = tr( "Driver with name '%1' is not installed." ).arg( driver );
#else
if ( !QgsHanaDriver::isValidPath( driver ) )
{
if ( QFileInfo::exists( driver ) )
warningMsg = tr( "Specified driver '%1' cannot be used to connect to HANA." ).arg( driver );
else
warningMsg = tr( "Driver with name/path '%1' was not found." ).arg( driver );
}
#endif
}
}
}

if ( !warningMsg.isEmpty() )
{
Expand Down

0 comments on commit df2c9ff

Please sign in to comment.