Skip to content
Permalink
Browse files
Implement createSqlVectorLayer, sqlDictionary, sqlOptions functions i…
…n QgsHanaProviderConnection (ps 3)
  • Loading branch information
mrylov authored and nyalldawson committed Oct 27, 2021
1 parent a5c51b8 commit 3a7d8555e7ed44874848d5bb1a35e3b26ccf7d7a
@@ -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() )
@@ -290,7 +302,6 @@ QStringList QgsHanaPrimaryKeyUtils::parseUriKey( const QString &key )
i++;
Q_ASSERT( key[i] == '"' );
i++;
col.clear();
continue;
}
}
@@ -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 );
};

@@ -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
@@ -633,7 +633,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "AUTOCOMMIT" ),
QStringLiteral( "AUTOMATIC" ),
QStringLiteral( "AUTOMERGE" ),
QStringLiteral( "AVG" ),
QStringLiteral( "AXIS" ),
QStringLiteral( "BACKINT" ),
QStringLiteral( "BACKUP" ),
@@ -762,7 +761,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "COPY" ),
QStringLiteral( "COREFILE" ),
QStringLiteral( "CORRELATION" ),
QStringLiteral( "COUNT" ),
QStringLiteral( "COVERAGE" ),
QStringLiteral( "CPBTREE" ),
QStringLiteral( "CPU" ),
@@ -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" ),
@@ -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" ),
@@ -1243,7 +1239,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "MATCHED" ),
QStringLiteral( "MATCHES" ),
QStringLiteral( "MATCHING" ),
QStringLiteral( "MAX" ),
QStringLiteral( "MAXITERATIONS" ),
QStringLiteral( "MAXVALUE" ),
QStringLiteral( "MB" ),
@@ -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" ),
@@ -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" ),
@@ -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" ),
@@ -1665,7 +1656,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "SUBTOTAL" ),
QStringLiteral( "SUBTYPE" ),
QStringLiteral( "SUCCESSFUL" ),
QStringLiteral( "SUM" ),
QStringLiteral( "SUPPORT" ),
QStringLiteral( "SUSPEND" ),
QStringLiteral( "SYNC" ),
@@ -1808,7 +1798,6 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
QStringLiteral( "VALIDATION" ),
QStringLiteral( "VALUE" ),
QStringLiteral( "VALUES" ),
QStringLiteral( "VAR" ),
QStringLiteral( "VARBINARY" ),
QStringLiteral( "VARCHAR" ),
QStringLiteral( "VARCHAR1" ),
@@ -16,6 +16,7 @@
***************************************************************************/
#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
#include "qgshanaprimarykeys.h"
#include "qgshanatablemodel.h"
#include "qgshanasettings.h"
#include "qgshanautils.h"
@@ -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 )
@@ -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 );

0 comments on commit 3a7d855

Please sign in to comment.