Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix compiler and code layout warnings in HANA provider
  • Loading branch information
Maksim Rylov authored and mrylov committed Dec 7, 2020
1 parent acc7a93 commit 34df7fe
Show file tree
Hide file tree
Showing 15 changed files with 485 additions and 466 deletions.
1 change: 1 addition & 0 deletions src/providers/hana/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ SET (HANA_MOC_HDRS
qgshanaconnectionpool.h
qgshanadataitems.h
qgshanaprovider.h
qgshanaresultset.h
qgshanatablemodel.h
)

Expand Down
12 changes: 9 additions & 3 deletions src/providers/hana/qgshanaexception.h
Expand Up @@ -29,11 +29,17 @@ class QgsHanaException final : public QException
{
}

void raise() const override { throw *this; }
void raise() const override { throw *this; }

QgsHanaException *clone() const override { return new QgsHanaException( *this ); }
QgsHanaException *clone() const override
{
return new QgsHanaException( *this );
}

char const *what() const noexcept override { return mMessage.c_str(); }
char const *what() const noexcept override
{
return mMessage.c_str();
}

private:
std::string mMessage;
Expand Down
37 changes: 19 additions & 18 deletions src/providers/hana/qgshanaexpressioncompiler.cpp
Expand Up @@ -20,7 +20,8 @@
#include "qgssqlexpressioncompiler.h"

QgsHanaExpressionCompiler::QgsHanaExpressionCompiler( QgsHanaFeatureSource *source )
: QgsSqlExpressionCompiler( source->mFields, QgsSqlExpressionCompiler::IntegerDivisionResultsInInteger | QgsSqlExpressionCompiler::NoNullInBooleanLogic)
: QgsSqlExpressionCompiler( source->mFields, QgsSqlExpressionCompiler::IntegerDivisionResultsInInteger |
QgsSqlExpressionCompiler::NoNullInBooleanLogic )
, mGeometryColumn( source->mGeometryColumn )
{
}
Expand Down Expand Up @@ -99,7 +100,7 @@ QgsSqlExpressionCompiler::Result QgsHanaExpressionCompiler::compileNode(

QString funcName = fd->name();
if ( funcName.isEmpty() )
break;
break;

if ( funcName == QLatin1String( "$geometry" ) )
{
Expand All @@ -108,25 +109,25 @@ QgsSqlExpressionCompiler::Result QgsHanaExpressionCompiler::compileNode(
}
else if ( funcName.toLower() == QLatin1String( "log10" ) )
{
return Fail;
return Fail;
}
else if ( funcName.toLower() == QLatin1String( "pi" ) )
{
result = "3.141592653589793238";
return Complete;
result = "3.141592653589793238";
return Complete;
}
}
break;
case QgsExpressionNode::ntLiteral:
{
const QgsExpressionNodeLiteral *n = static_cast<const QgsExpressionNodeLiteral *>( node );

switch( n->value().type() )
switch ( n->value().type() )
{
case QVariant::Bool:
case QVariant::Bool:
result = n->value().toBool() ? "(1=1)" : "(1=0)";
return Complete;
default:
default:
break;
}
}
Expand All @@ -147,10 +148,10 @@ QgsSqlExpressionCompiler::Result QgsHanaExpressionCompiler::compileNode(
switch ( binOp->op() )
{
case QgsExpressionNodeBinaryOperator::boMod:
result = QStringLiteral( "MOD(%1,%2)" ).arg( opLeft, opRight );
compileResult = ( resLeft == Partial || resRight == Partial ) ? Partial : Complete;
QgsDebugMsg( QStringLiteral( "MOD compile status: %1" ).arg( compileResult ) + "; " + result );
return compileResult;
result = QStringLiteral( "MOD(%1,%2)" ).arg( opLeft, opRight );
compileResult = ( resLeft == Partial || resRight == Partial ) ? Partial : Complete;
QgsDebugMsg( QStringLiteral( "MOD compile status: %1" ).arg( compileResult ) + "; " + result );
return compileResult;

case QgsExpressionNodeBinaryOperator::boPow:
result = QStringLiteral( "POWER(%1,%2)" ).arg( opLeft, opRight );
Expand Down Expand Up @@ -196,12 +197,12 @@ QgsSqlExpressionCompiler::Result QgsHanaExpressionCompiler::compileNode(
}
}
break;
default:
break;
}
}
break;
default:
default:
break;
}
}
break;
default:
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/hana/qgshanaexpressioncompiler.h
Expand Up @@ -29,11 +29,11 @@ class QgsHanaExpressionCompiler : public QgsSqlExpressionCompiler
protected:
QString quotedIdentifier( const QString &identifier ) override;
QString quotedValue( const QVariant &value, bool &ok ) override;
Result compileNode( const QgsExpressionNode *node, QString &str ) override;
QString sqlFunctionFromFunctionName( const QString &fnName ) const override;
QString castToReal( const QString &value ) const override;
QString castToInt( const QString &value ) const override;
QString castToText( const QString &value ) const override;
Result compileNode( const QgsExpressionNode *node, QString &str ) override;

private:
QString mGeometryColumn;
Expand Down
114 changes: 57 additions & 57 deletions src/providers/hana/qgshanafeatureiterator.cpp
Expand Up @@ -34,12 +34,12 @@ using namespace odbc;

static QString andWhereClauses( const QString &c1, const QString &c2 )
{
if ( c1.isEmpty() )
return c2;
if ( c2.isEmpty() )
return c1;
if ( c1.isEmpty() )
return c2;
if ( c2.isEmpty() )
return c1;

return QStringLiteral( "(%1) AND (%2)" ).arg( c1, c2 );
return QStringLiteral( "(%1) AND (%2)" ).arg( c1, c2 );
}

QgsHanaFeatureIterator::QgsHanaFeatureIterator(
Expand All @@ -50,8 +50,6 @@ QgsHanaFeatureIterator::QgsHanaFeatureIterator(
, mConnRef( source->mUri )
, mSrsExtent( source->mSrsExtent )
, mFidColumn( source->mFidColumn )
, mHasAttributes( false )
, mHasGeometryColumn( false )
{
mClosed = true;

Expand Down Expand Up @@ -82,7 +80,7 @@ QgsHanaFeatureIterator::QgsHanaFeatureIterator(
mClosed = false;
rewind();
}
catch ( const odbc::Exception& ex)
catch ( const odbc::Exception &ex )
{
QgsDebugMsg( ex.what() );
iteratorClosed();
Expand All @@ -102,7 +100,7 @@ bool QgsHanaFeatureIterator::rewind()

mResultSet.reset();
PreparedStatementRef stmt = mConnRef->getNativeRef()->prepareStatement( mSqlStatement.toStdString().c_str() );
mResultSet = QgsHanaResultSet::create(stmt);
mResultSet = QgsHanaResultSet::create( stmt );
return true;
}

Expand Down Expand Up @@ -136,10 +134,10 @@ bool QgsHanaFeatureIterator::fetchFeature( QgsFeature &feature )
// Read feature id
if ( !mFidColumn.isEmpty() )
{
QVariant id = mResultSet->getValue(paramIndex);
feature.setId( id.toLongLong() );
feature.setAttribute( 0, id );
++paramIndex;
QVariant id = mResultSet->getValue( paramIndex );
feature.setId( id.toLongLong() );
feature.setAttribute( 0, id );
++paramIndex;
}
else
{
Expand All @@ -149,21 +147,21 @@ bool QgsHanaFeatureIterator::fetchFeature( QgsFeature &feature )
// Read attributes
if ( mHasAttributes )
{
Q_FOREACH(int idx, mAttributesToFetch)
Q_FOREACH ( int idx, mAttributesToFetch )
{
feature.setAttribute( idx, mResultSet->getValue(paramIndex ));
feature.setAttribute( idx, mResultSet->getValue( paramIndex ) );
++paramIndex;
}
}

// Read geometry
if ( mHasGeometryColumn )
{
QgsGeometry geom = mResultSet->getGeometry(paramIndex);
if (!geom.isNull())
feature.setGeometry( geom );
QgsGeometry geom = mResultSet->getGeometry( paramIndex );
if ( !geom.isNull() )
feature.setGeometry( geom );
else
feature.clearGeometry();
feature.clearGeometry();
}
else
{
Expand Down Expand Up @@ -229,7 +227,7 @@ QString QgsHanaFeatureIterator::buildSQLStatement( const QgsFeatureRequest &requ
#if 0
mOrderByCompiled = true;

if (QgsSettings().value( QStringLiteral( "qgis/compileExpressions" ), true ).toBool() )
if ( QgsSettings().value( QStringLiteral( "qgis/compileExpressions" ), true ).toBool() )
{
const auto constOrderBy = request.orderBy();
for ( const QgsFeatureRequest::OrderByClause &clause : constOrderBy )
Expand Down Expand Up @@ -268,27 +266,27 @@ QString QgsHanaFeatureIterator::buildSQLStatement( const QgsFeatureRequest &requ
QgsAttributeList attrs = ( subsetOfAttributes ) ?
request.subsetOfAttributes() : mSource->mFields.allAttributesList();

if (subsetOfAttributes)
if ( subsetOfAttributes )
{
// Ensure that all attributes required for expression filter are fetched
if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
//ensure that all fields required for filter expressions are prepared
QSet<int> attributeIndexes = request.filterExpression()->referencedAttributeIndexes( mSource->mFields );
attributeIndexes += attrs.toSet();
attrs = attributeIndexes.toList();
}
// Ensure that all attributes required for expression filter are fetched
if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
//ensure that all fields required for filter expressions are prepared
QSet<int> attributeIndexes = request.filterExpression()->referencedAttributeIndexes( mSource->mFields );
attributeIndexes += attrs.toSet();
attrs = attributeIndexes.toList();
}

if ( !mRequest.orderBy().isEmpty() )
if ( !mRequest.orderBy().isEmpty() )
{
// Ensure that all attributes required for order by are fetched
const auto usedAttributeIndices = mRequest.orderBy().usedAttributeIndices( mSource->mFields );
for ( int attrIndex : usedAttributeIndices )
{
// Ensure that all attributes required for order by are fetched
const auto usedAttributeIndices = mRequest.orderBy().usedAttributeIndices( mSource->mFields );
for ( int attrIndex : usedAttributeIndices )
{
if ( !attrs.contains( attrIndex ) )
attrs << attrIndex;
}
if ( !attrs.contains( attrIndex ) )
attrs << attrIndex;
}
}
}

Q_FOREACH ( int i, attrs )
Expand Down Expand Up @@ -323,12 +321,12 @@ QString QgsHanaFeatureIterator::buildSQLStatement( const QgsFeatureRequest &requ

if ( sqlFields.isEmpty() )
{
sqlFields = "*";
sqlFields = "*";
}
else
{
if ( sqlFields.endsWith( ',' ) )
sqlFields.truncate( sqlFields.length() - 1 );
if ( sqlFields.endsWith( ',' ) )
sqlFields.truncate( sqlFields.length() - 1 );
}

QString sql = QStringLiteral( "SELECT %1 FROM %2.%3" ).arg(
Expand All @@ -339,30 +337,32 @@ QString QgsHanaFeatureIterator::buildSQLStatement( const QgsFeatureRequest &requ
QString sqlFilter;
// Set spatial filter
if ( !( filterRect.isNull() || filterRect.isEmpty() ) && mSource->isSpatial() && mHasGeometryColumn )
{
sqlFilter = getBBOXFilter( filterRect, QgsHanaUtils::toHANAVersion( mConnRef->getDatabaseVersion() ) );
}

// Set fid filter
if (!mFidColumn.isEmpty())
if ( !mFidColumn.isEmpty() )
{
if ( request.filterType() == QgsFeatureRequest::FilterFid )
if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
QString inClause = QStringLiteral( " %1 = %2" ).arg(
QgsHanaUtils::quotedIdentifier( mFidColumn ), FID_TO_STRING( request.filterFid() ) );
sqlFilter = andWhereClauses( sqlFilter, inClause );
}
else if ( request.filterType() == QgsFeatureRequest::FilterFids && !mRequest.filterFids().isEmpty() )
{
QString delim;
QString inClause = QStringLiteral( "%1 IN (" ).arg( QgsHanaUtils::quotedIdentifier( mFidColumn ) );
Q_FOREACH ( QgsFeatureId featureId, mRequest.filterFids() )
{
QString inClause = QStringLiteral( " %1 = %2" ).arg(
QgsHanaUtils::quotedIdentifier( mFidColumn ), FID_TO_STRING( request.filterFid() ) );
sqlFilter = andWhereClauses( sqlFilter, inClause );
inClause += delim + FID_TO_STRING( featureId );
delim = ',';
}
else if ( request.filterType() == QgsFeatureRequest::FilterFids && !mRequest.filterFids().isEmpty() )
{
QString delim;
QString inClause = QStringLiteral( "%1 IN (" ).arg( QgsHanaUtils::quotedIdentifier( mFidColumn ) );
Q_FOREACH ( QgsFeatureId featureId, mRequest.filterFids() )
{
inClause += delim + FID_TO_STRING( featureId );
delim = ',';
}
inClause.append( ')' );
inClause.append( ')' );

sqlFilter = andWhereClauses( sqlFilter, inClause );
}
sqlFilter = andWhereClauses( sqlFilter, inClause );
}
}

//IMPORTANT - this MUST be the last clause added
Expand Down
6 changes: 3 additions & 3 deletions src/providers/hana/qgshanafeatureiterator.h
Expand Up @@ -79,13 +79,13 @@ class QgsHanaFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsHa
private:
QgsHanaConnectionRef mConnRef;
QgsHanaResultSetRef mResultSet;
QString mSqlStatement;
QgsCoordinateTransform mTransform;
QString mSqlStatement = QString( "" );
QgsRectangle mFilterRect;
QgsRectangle mSrsExtent;
QgsAttributeList mAttributesToFetch;
QString mFidColumn;
bool mHasAttributes;
QgsCoordinateTransform mTransform;
bool mHasAttributes = false;
bool mHasGeometryColumn = false;
bool mExpressionCompiled = false;
bool mOrderByCompiled = false;
Expand Down

0 comments on commit 34df7fe

Please sign in to comment.