Skip to content

Commit

Permalink
HANA layers are not listed due to a view with a dropped table
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored and nyalldawson committed May 17, 2021
1 parent 92c7ccd commit 8e4de4b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/providers/hana/qgshanacolumntypethread.cpp
Expand Up @@ -68,7 +68,8 @@ void QgsHanaColumnTypeThread::run()
.arg( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName ) );
conn->readLayerInfo( layerProperty );

emit setLayerType( layerProperty );
if ( layerProperty.isValid )
emit setLayerType( layerProperty );
}
}
catch ( const QgsHanaException &ex )
Expand Down
15 changes: 12 additions & 3 deletions src/providers/hana/qgshanaconnection.cpp
Expand Up @@ -687,9 +687,18 @@ QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayersFull(

void QgsHanaConnection::readLayerInfo( QgsHanaLayerProperty &layerProperty )
{
layerProperty.srid = getColumnSrid( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName );
layerProperty.type = getColumnGeometryType( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName );
layerProperty.pkCols = getPrimaryKeyCandidates( layerProperty );
try
{
layerProperty.srid = getColumnSrid( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName );
layerProperty.type = getColumnGeometryType( layerProperty.schemaName, layerProperty.tableName, layerProperty.geometryColName );
layerProperty.pkCols = getPrimaryKeyCandidates( layerProperty );
layerProperty.isValid = true;
}
catch ( const QgsHanaException &ex )
{
layerProperty.errorMessage = ex.what();
QgsMessageLog::logMessage( QgsHanaUtils::formatErrorMessage( ex.what() ), tr( "SAP HANA" ) );
}
}

void QgsHanaConnection::readQueryFields( const QString &schemaName, const QString &sql,
Expand Down
13 changes: 11 additions & 2 deletions src/providers/hana/qgshanadataitems.cpp
Expand Up @@ -318,7 +318,16 @@ QVector<QgsDataItem *> QgsHanaSchemaItem::createChildren()

items.reserve( layers.size() );
for ( const QgsHanaLayerProperty &layerInfo : layers )
items.append( createLayer( layerInfo ) );
{
if ( layerInfo.isValid )
items.append( createLayer( layerInfo ) );
else
{
QgsErrorItem *itemInvalidLayer = new QgsErrorItem( this, layerInfo.defaultName(), mPath + "/error" );
itemInvalidLayer->setToolTip( layerInfo.errorMessage );
items.append( itemInvalidLayer );
}
}
}
catch ( const QgsHanaException &ex )
{
Expand All @@ -337,7 +346,7 @@ QgsHanaLayerItem *QgsHanaSchemaItem::createLayer( const QgsHanaLayerProperty &la
QString tip = layerProperty.isView ? QStringLiteral( "View" ) : QStringLiteral( "Table" );

QgsLayerItem::LayerType layerType = QgsLayerItem::TableLayer;
if ( !layerProperty.geometryColName.isEmpty() && layerProperty.isValid() )
if ( !layerProperty.geometryColName.isEmpty() && layerProperty.isGeometryValid() )
{
tip += tr( "\n%1 as %2" ).arg( layerProperty.geometryColName,
QgsWkbTypes::displayString( layerProperty.type ) );
Expand Down
4 changes: 3 additions & 1 deletion src/providers/hana/qgshanatablemodel.h
Expand Up @@ -41,6 +41,8 @@ struct QgsHanaLayerProperty
QString sql;
bool isView = false;
bool isUnique = false;
bool isValid = false;
QString errorMessage;

QString defaultName() const
{
Expand All @@ -50,7 +52,7 @@ struct QgsHanaLayerProperty
return ret;
}

bool isValid() const { return type != QgsWkbTypes::Unknown && srid >= 0; }
bool isGeometryValid() const { return type != QgsWkbTypes::Unknown && srid >= 0; }
};

class QIcon;
Expand Down

0 comments on commit 8e4de4b

Please sign in to comment.