Skip to content
Permalink
Browse files

Implement QgsHanaProviderConnection::table

  • Loading branch information
mrylov authored and nyalldawson committed Apr 7, 2021
1 parent ec339d2 commit 62801fab77b00aeea7b777f7bde32a13b32b5df6
@@ -434,7 +434,8 @@ QgsCoordinateReferenceSystem QgsHanaConnection::getCrs( int srid )
QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayers(
const QString &schemaName,
bool allowGeometrylessTables,
bool userTablesOnly )
bool userTablesOnly,
const std::function<bool( const QString &name )> &layerFilter )
{
const QString schema = mUri.schema().isEmpty() ? schemaName : mUri.schema();
const QString sqlSchemaFilter = QStringLiteral(
@@ -468,7 +469,6 @@ QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayers(
"(SELECT VIEW_OID AS VIEW_OID_2, COMMENTS AS VIEW_COMMENTS FROM SYS.VIEWS) "
"ON VIEW_OID = VIEW_OID_2" );


QMultiHash<QPair<QString, QString>, QgsHanaLayerProperty> layers;

auto addLayers = [&]( const QString & sql, bool isView )
@@ -482,6 +482,8 @@ QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayers(
QgsHanaLayerProperty layer;
layer.schemaName = rsLayers->getString( 1 );
layer.tableName = rsLayers->getString( 2 );
if ( layerFilter != nullptr && !layerFilter( layer.tableName ) )
continue;
QString geomColumnType = rsLayers->getString( 4 );
bool isGeometryColumn = ( geomColumnType == QLatin1String( "ST_GEOMETRY" ) || geomColumnType == QLatin1String( "ST_POINT" ) );
layer.geometryColName = isGeometryColumn ? rsLayers->getString( 3 ) : QString();
@@ -540,9 +542,10 @@ QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayers(
QVector<QgsHanaLayerProperty> QgsHanaConnection::getLayersFull(
const QString &schemaName,
bool allowGeometrylessTables,
bool userTablesOnly )
bool userTablesOnly,
const std::function<bool( const QString &name )> &layerFilter )
{
QVector<QgsHanaLayerProperty> layers = getLayers( schemaName, allowGeometrylessTables, userTablesOnly );
QVector<QgsHanaLayerProperty> layers = getLayers( schemaName, allowGeometrylessTables, userTablesOnly, layerFilter );
// We cannot use a range-based for loop as layers are modified in readLayerInfo.
for ( int i = 0; i < layers.size(); ++i )
readLayerInfo( layers[i] );
@@ -59,11 +59,13 @@ class QgsHanaConnection : public QObject
QVector<QgsHanaLayerProperty> getLayers(
const QString &schemaName,
bool allowGeometrylessTables,
bool userTablesOnly = true );
bool userTablesOnly = true,
const std::function<bool( const QString &name )> &layerFilter = nullptr );
QVector<QgsHanaLayerProperty> getLayersFull(
const QString &schemaName,
bool allowGeometrylessTables,
bool userTablesOnly = true );
bool userTablesOnly = true,
const std::function<bool( const QString &name )> &layerFilter = nullptr );
void readLayerInfo( QgsHanaLayerProperty &layerProperty );
QVector<QgsHanaSchemaProperty> getSchemas( const QString &ownerName );
QStringList getLayerPrimaryKey( const QString &schemaName, const QString &tableName );
@@ -309,7 +309,9 @@ void QgsHanaProviderConnection::executeSqlStatement( const QString &sql ) const
}
}

QList<QgsHanaProviderConnection::TableProperty> QgsHanaProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
QList<QgsAbstractDatabaseProviderConnection::TableProperty> QgsHanaProviderConnection::tablesWithFilter(
const QString &schema,
const TableFlags &flags, const std::function<bool( const QString &name )> &tableFilter ) const
{
checkCapability( Capability::Tables );

@@ -323,7 +325,7 @@ QList<QgsHanaProviderConnection::TableProperty> QgsHanaProviderConnection::table
try
{
const bool aspatial { ! flags || flags.testFlag( TableFlag::Aspatial ) };
const QVector<QgsHanaLayerProperty> layers = conn->getLayersFull( schema, aspatial, false );
const QVector<QgsHanaLayerProperty> layers = conn->getLayersFull( schema, aspatial, false, tableFilter );
tables.reserve( layers.size() );
for ( const QgsHanaLayerProperty &layerInfo : layers )
{
@@ -373,6 +375,24 @@ QList<QgsHanaProviderConnection::TableProperty> QgsHanaProviderConnection::table
return tables;
}

QgsAbstractDatabaseProviderConnection::TableProperty QgsHanaProviderConnection::table( const QString &schema, const QString &table ) const
{
auto tableFilter = [&table]( const QString & name )
{
return name == table;
};
const QList<QgsAbstractDatabaseProviderConnection::TableProperty> constTables { tablesWithFilter( schema, TableFlags(), tableFilter ) };
if ( constTables.empty() )
throw QgsProviderConnectionException( QObject::tr( "Table '%1' was not found in schema '%2'" )
.arg( table, schema ) );
return constTables[0];
}

QList<QgsHanaProviderConnection::TableProperty> QgsHanaProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
{
return tablesWithFilter( schema, flags );
}

QStringList QgsHanaProviderConnection::schemas( ) const
{
checkCapability( Capability::Schemas );
@@ -65,6 +65,7 @@ class QgsHanaProviderConnection : public QgsAbstractDatabaseProviderConnection
void dropSchema( const QString &name, bool force = false ) const override;
void renameSchema( const QString &name, const QString &newName ) const override;
QueryResult execSql( const QString &sql, QgsFeedback *feedback = nullptr ) const override;
QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const override;
QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema,
const TableFlags &flags = TableFlags() ) const override;
QStringList schemas( ) const override;
@@ -78,6 +79,8 @@ class QgsHanaProviderConnection : public QgsAbstractDatabaseProviderConnection
void setCapabilities();
void dropTable( const QString &schema, const QString &name ) const;
void renameTable( const QString &schema, const QString &name, const QString &newName ) const;
QList<QgsAbstractDatabaseProviderConnection::TableProperty> tablesWithFilter( const QString &schema,
const TableFlags &flags = TableFlags(), const std::function<bool( const QString &name )> &tableFilter = nullptr ) const;
};

#endif // QGSHANAPROVIDERCONNECTION_H
@@ -29,7 +29,6 @@

#include "odbc/Types.h"


class QgsHanaUtils
{
public:

0 comments on commit 62801fa

Please sign in to comment.