Skip to content
Permalink
Browse files
Implement createSqlVectorLayer, sqlDictionary, sqlOptions functions i…
…n QgsHanaProviderConnection (part 2)
  • Loading branch information
mrylov authored and nyalldawson committed Oct 27, 2021
1 parent c58278c commit a5c51b86fbe72d1a4606754051cfda91ee8c3cc0
Showing with 62 additions and 53 deletions.
  1. +52 −52 src/providers/hana/qgshanaprimarykeys.cpp
  2. +1 −0 src/providers/hana/qgshanaprimarykeys.h
  3. +9 −1 src/providers/hana/qgshanaproviderconnection.cpp
@@ -38,58 +38,6 @@ namespace
{
return x <= ( ( INT32PK_OFFSET ) / 2 ) ? x : -( INT32PK_OFFSET - x );
}

QStringList parseUriKey( const QString &key )
{
if ( key.isEmpty() )
return QStringList();

QStringList cols;

// remove quotes from key list
if ( key.startsWith( '"' ) && key.endsWith( '"' ) )
{
int i = 1;
QString col;
while ( i < key.size() )
{
if ( key[i] == '"' )
{
if ( i + 1 < key.size() && key[i + 1] == '"' )
{
i++;
}
else
{
cols << col;
col.clear();

if ( ++i == key.size() )
break;

Q_ASSERT( key[i] == ',' );
i++;
Q_ASSERT( key[i] == '"' );
i++;
col.clear();
continue;
}
}

col += key[i++];
}
}
else if ( key.contains( ',' ) )
{
cols = key.split( ',' );
}
else
{
cols << key;
}

return cols;
}
}

QgsFeatureId QgsHanaPrimaryKeyContext::lookupFid( const QVariantList &v )
@@ -309,3 +257,55 @@ QString QgsHanaPrimaryKeyUtils::buildWhereClause( const QgsFeatureIds &featureId

return QString(); //avoid warning
}

QStringList QgsHanaPrimaryKeyUtils::parseUriKey( const QString &key )
{
if ( key.isEmpty() )
return QStringList();

QStringList cols;

// remove quotes from key list
if ( key.startsWith( '"' ) && key.endsWith( '"' ) )
{
int i = 1;
QString col;
while ( i < key.size() )
{
if ( key[i] == '"' )
{
if ( i + 1 < key.size() && key[i + 1] == '"' )
{
i++;
}
else
{
cols << col;
col.clear();

if ( ++i == key.size() )
break;

Q_ASSERT( key[i] == ',' );
i++;
Q_ASSERT( key[i] == '"' );
i++;
col.clear();
continue;
}
}

col += key[i++];
}
}
else if ( key.contains( ',' ) )
{
cols = key.split( ',' );
}
else
{
cols << key;
}

return cols;
}
@@ -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 QStringList parseUriKey( const QString &key );
};


@@ -17,6 +17,7 @@
#include "qgshanaproviderconnection.h"
#include "qgshanaconnectionpool.h"
#include "qgshanaexception.h"
#include "qgshanaprimarykeys.h"
#include "qgshanaprovider.h"
#include "qgshanaresultset.h"
#include "qgshanasettings.h"
@@ -525,7 +526,7 @@ QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions QgsHanaProviderConn
{
SqlVectorLayerOptions options;
const QgsDataSourceUri tUri( layerSource );
options.primaryKeyColumns = tUri.keyColumn().split( ',' );
options.primaryKeyColumns = QgsHanaPrimaryKeyUtils::parseUriKey( tUri.keyColumn() );
options.disableSelectAtId = tUri.selectAtIdDisabled();
options.geometryColumn = tUri.geometryColumn();
options.filter = tUri.sql();
@@ -1863,17 +1864,24 @@ QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsHanaProviderConnection::sqlD
Qgis::SqlKeywordCategory::Aggregate,
{
QStringLiteral( "AUTO_CORR" ),
QStringLiteral( "AVG" ),
QStringLiteral( "CORR" ),
QStringLiteral( "CORR_SPEARMAN" ),
QStringLiteral( "COUNT" ),
QStringLiteral( "CROSS_CORR" ),
QStringLiteral( "DFT" ),
QStringLiteral( "FIRST_VALUE" ),
QStringLiteral( "LAST_VALUE" ),
QStringLiteral( "MAX" ),
QStringLiteral( "MEDIAN" ),
QStringLiteral( "MIN" ),
QStringLiteral( "NTH_VALUE" ),
QStringLiteral( "STDDEV" ),
QStringLiteral( "STDDEV_POP" ),
QStringLiteral( "STDDEV_SAMP" ),
QStringLiteral( "STRING_AGG" ),
QStringLiteral( "SUM" ),
QStringLiteral( "VAR" ),
QStringLiteral( "VAR_POP" ),
QStringLiteral( "VAR_SAMP" ),
}

0 comments on commit a5c51b8

Please sign in to comment.