Skip to content
Permalink
Browse files

Rework query and its parameters in QgsHanaFeatureIterator

  • Loading branch information
mrylov committed Dec 21, 2020
1 parent 32b71fc commit fb46ff3fe0617fbae64eab38afae7193cd693fd5
Showing with 16 additions and 9 deletions.
  1. +14 −9 src/providers/hana/qgshanafeatureiterator.cpp
  2. +2 −0 src/providers/hana/qgshanafeatureiterator.h
@@ -91,6 +91,7 @@ QgsHanaFeatureIterator::QgsHanaFeatureIterator(
try
{
mSqlQuery = buildSqlQuery( request );
mSqlQueryParams = buildSqlQueryParameters();

rewind();
}
@@ -111,15 +112,7 @@ bool QgsHanaFeatureIterator::rewind()
return false;

mResultSet.reset();
if ( !( mFilterRect.isNull() || mFilterRect.isEmpty() ) && mSource->isSpatial() && mHasGeometryColumn )
{
QgsRectangle filterRect = getFilterRect();
QString ll = QStringLiteral( "POINT(%1 %2)" ).arg( QString::number( filterRect.xMinimum() ), QString::number( filterRect.yMinimum() ) );
QString ur = QStringLiteral( "POINT(%1 %2)" ).arg( QString::number( filterRect.xMaximum() ), QString::number( filterRect.yMaximum() ) );
mResultSet = mConnection->executeQuery( mSqlQuery, { ll, mSource->mSrid, ur, mSource->mSrid } );
}
else
mResultSet = mConnection->executeQuery( mSqlQuery );
mResultSet = mConnection->executeQuery( mSqlQuery, mSqlQueryParams );

return true;
}
@@ -429,6 +422,18 @@ QString QgsHanaFeatureIterator::buildSqlQuery( const QgsFeatureRequest &request
return sql;
}

QVariantList QgsHanaFeatureIterator::buildSqlQueryParameters( ) const
{
if ( !( mFilterRect.isNull() || mFilterRect.isEmpty() ) && mSource->isSpatial() && mHasGeometryColumn )
{
QgsRectangle filterRect = getFilterRect();
QString ll = QStringLiteral( "POINT(%1 %2)" ).arg( QString::number( filterRect.xMinimum() ), QString::number( filterRect.yMinimum() ) );
QString ur = QStringLiteral( "POINT(%1 %2)" ).arg( QString::number( filterRect.xMaximum() ), QString::number( filterRect.yMaximum() ) );
return { ll, mSource->mSrid, ur, mSource->mSrid };
}
return QVariantList();
}

QgsHanaFeatureSource::QgsHanaFeatureSource( const QgsHanaProvider *p )
: mDatabaseVersion( p->mDatabaseVersion )
, mUri( p->mUri )
@@ -75,6 +75,7 @@ class QgsHanaFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsHa
bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;

QString buildSqlQuery( const QgsFeatureRequest &request );
QVariantList buildSqlQueryParameters( ) const;
QString getBBOXFilter() const;
QgsRectangle getFilterRect() const;

@@ -83,6 +84,7 @@ class QgsHanaFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsHa
QgsHanaConnectionRef mConnection;
QgsHanaResultSetRef mResultSet;
QString mSqlQuery;
QVariantList mSqlQueryParams;
QgsRectangle mFilterRect;
const QgsRectangle mSrsExtent;
QgsAttributeList mAttributesToFetch;

0 comments on commit fb46ff3

Please sign in to comment.
You can’t perform that action at this time.