Skip to content

Commit

Permalink
Implement createSqlVectorLayer, sqlDictionary, sqlOptions functions i…
Browse files Browse the repository at this point in the history
…n QgsHanaProviderConnection (ps 3)
  • Loading branch information
mrylov authored and nyalldawson committed Oct 27, 2021
1 parent a5c51b8 commit 3a7d855
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
13 changes: 12 additions & 1 deletion src/providers/hana/qgshanaprimarykeys.cpp
Expand Up @@ -258,6 +258,18 @@ QString QgsHanaPrimaryKeyUtils::buildWhereClause( const QgsFeatureIds &featureId
return QString(); //avoid warning
}

QString QgsHanaPrimaryKeyUtils::buildUriKey( const QStringList &columns )
{
QString ret;
for ( auto i = 0; i < columns.size(); ++i )
{
ret += QgsHanaUtils::quotedIdentifier( columns[i] );
if ( i != columns.size() - 1 )
ret += ',';
}
return ret;
}

QStringList QgsHanaPrimaryKeyUtils::parseUriKey( const QString &key )
{
if ( key.isEmpty() )
Expand Down Expand Up @@ -290,7 +302,6 @@ QStringList QgsHanaPrimaryKeyUtils::parseUriKey( const QString &key )
i++;
Q_ASSERT( key[i] == '"' );
i++;
col.clear();
continue;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/hana/qgshanaprimarykeys.h
Expand Up @@ -66,6 +66,7 @@ class QgsHanaPrimaryKeyUtils
const QList<int> &pkAttrs, QgsHanaPrimaryKeyContext &primaryKeyCntx );
static QString buildWhereClause( const QgsFeatureIds &featureIds, const QgsFields &fields, QgsHanaPrimaryKeyType pkType,
const QList<int> &pkAttrs, QgsHanaPrimaryKeyContext &primaryKeyCntx );
static QString buildUriKey( const QStringList &columns );
static QStringList parseUriKey( const QString &key );
};

Expand Down
13 changes: 1 addition & 12 deletions src/providers/hana/qgshanaproviderconnection.cpp
Expand Up @@ -492,7 +492,7 @@ QgsVectorLayer *QgsHanaProviderConnection::createSqlVectorLayer( const SqlVector

if ( ! options.primaryKeyColumns.isEmpty() )
{
tUri.setKeyColumn( options.primaryKeyColumns.join( ',' ) );
tUri.setKeyColumn( QgsHanaPrimaryKeyUtils::buildUriKey( options.primaryKeyColumns ) );
tUri.setTable( QStringLiteral( "(%1)" ).arg( options.sql ) );
}
else
Expand Down Expand Up @@ -633,7 +633,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "AUTOCOMMIT" ),
QStringLiteral( "AUTOMATIC" ),
QStringLiteral( "AUTOMERGE" ),
QStringLiteral( "AVG" ),
QStringLiteral( "AXIS" ),
QStringLiteral( "BACKINT" ),
QStringLiteral( "BACKUP" ),
Expand Down Expand Up @@ -762,7 +761,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "COPY" ),
QStringLiteral( "COREFILE" ),
QStringLiteral( "CORRELATION" ),
QStringLiteral( "COUNT" ),
QStringLiteral( "COVERAGE" ),
QStringLiteral( "CPBTREE" ),
QStringLiteral( "CPU" ),
Expand Down Expand Up @@ -1010,7 +1008,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "FINALIZE" ),
QStringLiteral( "FINISH" ),
QStringLiteral( "FIRST" ),
QStringLiteral( "FIRST_VALUE" ),
QStringLiteral( "FLAG" ),
QStringLiteral( "FLAGS" ),
QStringLiteral( "FLATTEN" ),
Expand Down Expand Up @@ -1181,7 +1178,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "LANGUAGE" ),
QStringLiteral( "LAST" ),
QStringLiteral( "LAST_DAY" ),
QStringLiteral( "LAST_VALUE" ),
QStringLiteral( "LATENCY" ),
QStringLiteral( "LATERAL" ),
QStringLiteral( "LAYOUT" ),
Expand Down Expand Up @@ -1243,7 +1239,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "MATCHED" ),
QStringLiteral( "MATCHES" ),
QStringLiteral( "MATCHING" ),
QStringLiteral( "MAX" ),
QStringLiteral( "MAXITERATIONS" ),
QStringLiteral( "MAXVALUE" ),
QStringLiteral( "MB" ),
Expand All @@ -1260,7 +1255,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "METADATA" ),
QStringLiteral( "MIGRATE" ),
QStringLiteral( "MIME" ),
QStringLiteral( "MIN" ),
QStringLiteral( "MIN_ROWS_FOR_PARTITIONING" ),
QStringLiteral( "MINING" ),
QStringLiteral( "MINOR" ),
Expand Down Expand Up @@ -1318,7 +1312,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "NOW" ),
QStringLiteral( "NOWAIT" ),
QStringLiteral( "NTEXT" ),
QStringLiteral( "NTH_VALUE" ),
QStringLiteral( "NTILE" ),
QStringLiteral( "NULL" ),
QStringLiteral( "NULLABLE" ),
Expand Down Expand Up @@ -1642,12 +1635,10 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "STATEMENT_NAME" ),
QStringLiteral( "STATIC" ),
QStringLiteral( "STATISTICS" ),
QStringLiteral( "STDDEV" ),
QStringLiteral( "STOP" ),
QStringLiteral( "STORAGE" ),
QStringLiteral( "STORE" ),
QStringLiteral( "STRING" ),
QStringLiteral( "STRING_AGG" ),
QStringLiteral( "STRIP" ),
QStringLiteral( "STRUCTURED" ),
QStringLiteral( "STRUCTUREDPRIVILEGE" ),
Expand All @@ -1665,7 +1656,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "SUBTOTAL" ),
QStringLiteral( "SUBTYPE" ),
QStringLiteral( "SUCCESSFUL" ),
QStringLiteral( "SUM" ),
QStringLiteral( "SUPPORT" ),
QStringLiteral( "SUSPEND" ),
QStringLiteral( "SYNC" ),
Expand Down Expand Up @@ -1808,7 +1798,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "VALIDATION" ),
QStringLiteral( "VALUE" ),
QStringLiteral( "VALUES" ),
QStringLiteral( "VAR" ),
QStringLiteral( "VARBINARY" ),
QStringLiteral( "VARCHAR" ),
QStringLiteral( "VARCHAR1" ),
Expand Down
12 changes: 5 additions & 7 deletions src/providers/hana/qgshanatablemodel.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/
#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
#include "qgshanaprimarykeys.h"
#include "qgshanatablemodel.h"
#include "qgshanasettings.h"
#include "qgshanautils.h"
Expand Down Expand Up @@ -320,15 +321,12 @@ QString QgsHanaTableModel::layerURI( const QModelIndex &index, const QString &co
QString schemaName = index.sibling( index.row(), DbtmSchema ).data( Qt::DisplayRole ).toString();
QString tableName = index.sibling( index.row(), DbtmTable ).data( Qt::DisplayRole ).toString();

QStringList pkColumns = qgis::setToList( pkColumnsSelected );

QgsHanaSettings settings( connName, true );
settings.setKeyColumns( schemaName, tableName, qgis::setToList( pkColumnsSelected ) );
settings.setKeyColumns( schemaName, tableName, pkColumns );
settings.save();

QStringList pkColumns;
pkColumns.reserve( pkColumnsSelected.size() );
for ( const QString &column : pkColumnsSelected )
pkColumns << QgsHanaUtils::quotedIdentifier( column );

QString geomColumnName;
QString srid;
if ( wkbType != QgsWkbTypes::NoGeometry )
Expand All @@ -346,7 +344,7 @@ QString QgsHanaTableModel::layerURI( const QModelIndex &index, const QString &co
QString sql = index.sibling( index.row(), DbtmSql ).data( Qt::DisplayRole ).toString();

QgsDataSourceUri uri( connInfo );
uri.setDataSource( schemaName, tableName, geomColumnName, sql, pkColumns.join( ',' ) );
uri.setDataSource( schemaName, tableName, geomColumnName, sql, QgsHanaPrimaryKeyUtils::buildUriKey( pkColumns ) );
uri.setWkbType( wkbType );
uri.setSrid( srid );
uri.disableSelectAtId( !selectAtId );
Expand Down

0 comments on commit 3a7d855

Please sign in to comment.