Skip to content
Permalink
Browse files

Fix HANA crash in UI components

  • Loading branch information
mrylov authored and nyalldawson committed Feb 11, 2021
1 parent e9de56a commit 8d08e3f6ba92f55f12c81042b882892051ce854e
@@ -17,8 +17,8 @@
#include "qgshanacolumntypethread.h"
#include "qgshanaconnection.h"
#include "qgshanaconnectionpool.h"
#include "qgshanaexception.h"
#include "qgshanautils.h"
#include "qgsmessagelog.h"
#include "qgslogger.h"

QgsHanaColumnTypeThread::QgsHanaColumnTypeThread( const QString &connName, const QgsDataSourceUri &uri, bool allowGeometrylessTables, bool userTablesOnly )
@@ -37,35 +37,43 @@ void QgsHanaColumnTypeThread::run()
QgsHanaConnectionRef conn( mUri );
if ( conn.isNull() )
{
QgsDebugMsg( "Connection failed: " + mUri.connectionInfo( false ) );
mErrorMessage = tr( "Connection failed: %1" ).arg( mUri.connectionInfo( false ) );
return;
}

emit progressMessage( tr( "Retrieving tables of %1." ).arg( mConnectionName ) );
QVector<QgsHanaLayerProperty> layerProperties = conn->getLayers(
mUri.schema(),
mAllowGeometrylessTables,
mUserTablesOnly );

if ( layerProperties.isEmpty() )
return;
try
{
QVector<QgsHanaLayerProperty> layerProperties = conn->getLayers(
mUri.schema(),
mAllowGeometrylessTables,
mUserTablesOnly );

const int totalLayers = layerProperties.size();
if ( layerProperties.isEmpty() )
return;

emit progress( 0, totalLayers );
const int totalLayers = layerProperties.size();

for ( int i = 0; i < totalLayers; ++i )
{
if ( isInterruptionRequested() )
break;
emit progress( 0, totalLayers );

QgsHanaLayerProperty &layerProperty = layerProperties[i];
emit progress( i, totalLayers );
emit progressMessage( tr( "Scanning column %1.%2.%3…" )
.arg( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName ) );
conn->readLayerInfo( layerProperty );
for ( int i = 0; i < totalLayers; ++i )
{
if ( isInterruptionRequested() )
break;

emit setLayerType( layerProperty );
QgsHanaLayerProperty &layerProperty = layerProperties[i];
emit progress( i, totalLayers );
emit progressMessage( tr( "Scanning column %1.%2.%3…" )
.arg( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName ) );
conn->readLayerInfo( layerProperty );

emit setLayerType( layerProperty );
}
}
catch ( const QgsHanaException &ex )
{
mErrorMessage = ex.what();
}

emit progress( 0, 0 );
@@ -34,6 +34,8 @@ class QgsHanaColumnTypeThread : public QThread
// by emitting the setLayerType() signal.
void run() override;

const QString &errorMessage() const { return mErrorMessage; }

signals:
void setLayerType( QgsHanaLayerProperty layerProperty );
void progress( int layerIndex, int layersCount );
@@ -44,6 +46,7 @@ class QgsHanaColumnTypeThread : public QThread
const QgsDataSourceUri mUri;
const bool mAllowGeometrylessTables;
const bool mUserTablesOnly;
QString mErrorMessage;
};

#endif // QGSHANACOLUMNTYPETHREAD_H
@@ -310,13 +310,22 @@ QVector<QgsDataItem *> QgsHanaSchemaItem::createChildren()
return items;
}

QgsHanaSettings settings( mConnectionName, true );
const QVector<QgsHanaLayerProperty> layers = conn->getLayersFull( mSchemaName,
settings.allowGeometrylessTables(), settings.userTablesOnly() );
try
{
QgsHanaSettings settings( mConnectionName, true );
const QVector<QgsHanaLayerProperty> layers = conn->getLayersFull( mSchemaName,
settings.allowGeometrylessTables(), settings.userTablesOnly() );

items.reserve( layers.size() );
for ( const QgsHanaLayerProperty &layerInfo : layers )
items.append( createLayer( layerInfo ) );
items.reserve( layers.size() );
for ( const QgsHanaLayerProperty &layerInfo : layers )
items.append( createLayer( layerInfo ) );
}
catch ( const QgsHanaException &ex )
{
QgsErrorItem *itemError = new QgsErrorItem( this, tr( "Server error occurred" ), mPath + "/error" );
itemError->setToolTip( ex.what() );
items.append( itemError );
}

setName( mSchemaName );

@@ -602,9 +602,12 @@ void QgsHanaSourceSelect::finishList()

void QgsHanaSourceSelect::columnThreadFinished()
{
QString errorMsg = mColumnTypeThread->errorMessage();
mColumnTypeThread.reset( nullptr );
QgsProxyProgressTask *task = mColumnTypeTask.release();
task->finalize( true );
task->finalize( errorMsg.isEmpty() );
if ( !errorMsg.isEmpty() )
pushMessage( tr( "Failed to retrieve tables for %1" ).arg( mConnectionName ), errorMsg, Qgis::MessageLevel::Warning );

btnConnect->setText( tr( "Connect" ) );

0 comments on commit 8d08e3f

Please sign in to comment.