Skip to content

Commit

Permalink
Fix: unable to drop a view in HANA
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored and nyalldawson committed May 4, 2021
1 parent f7da4f4 commit cd2865a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
33 changes: 13 additions & 20 deletions src/providers/hana/qgshanaproviderconnection.cpp
Expand Up @@ -21,7 +21,6 @@
#include "qgshanaresultset.h"
#include "qgshanasettings.h"
#include "qgshanautils.h"
#include "qgsapplication.h"
#include "qgsexception.h"
#include "qgsmessagelog.h"
#include "qgssettings.h"
Expand Down Expand Up @@ -150,13 +149,6 @@ void QgsHanaProviderConnection::setCapabilities()
Capability::Schemas | Capability::Tables | Capability::TableExists;
}

void QgsHanaProviderConnection::dropTable( const QString &schema, const QString &name ) const
{
executeSqlStatement( QStringLiteral( "DROP TABLE %1.%2" )
.arg( QgsHanaUtils::quotedIdentifier( schema ),
QgsHanaUtils::quotedIdentifier( name ) ) );
}

void QgsHanaProviderConnection::createVectorTable( const QString &schema,
const QString &name,
const QgsFields &fields,
Expand Down Expand Up @@ -196,7 +188,7 @@ void QgsHanaProviderConnection::createVectorTable( const QString &schema,

QString QgsHanaProviderConnection::tableUri( const QString &schema, const QString &name ) const
{
const auto tableInfo { table( schema, name ) };
const TableProperty tableInfo { table( schema, name ) };

QgsDataSourceUri dsUri( uri() );
dsUri.setTable( name );
Expand All @@ -208,23 +200,26 @@ QString QgsHanaProviderConnection::tableUri( const QString &schema, const QStrin
void QgsHanaProviderConnection::dropVectorTable( const QString &schema, const QString &name ) const
{
checkCapability( Capability::DropVectorTable );
dropTable( schema, name );
const TableProperty tableInfo = table( schema, name );
if ( tableInfo.flags().testFlag( TableFlag::View ) )
executeSqlStatement( QStringLiteral( "DROP VIEW %1.%2" )
.arg( QgsHanaUtils::quotedIdentifier( schema ),
QgsHanaUtils::quotedIdentifier( name ) ) );
else
executeSqlStatement( QStringLiteral( "DROP TABLE %1.%2" )
.arg( QgsHanaUtils::quotedIdentifier( schema ),
QgsHanaUtils::quotedIdentifier( name ) ) );
}

void QgsHanaProviderConnection::renameTable( const QString &schema, const QString &name, const QString &newName ) const
void QgsHanaProviderConnection::renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const
{
checkCapability( Capability::RenameVectorTable );
executeSqlStatement( QStringLiteral( "RENAME TABLE %1.%2 TO %1.%3" )
.arg( QgsHanaUtils::quotedIdentifier( schema ),
QgsHanaUtils::quotedIdentifier( name ),
QgsHanaUtils::quotedIdentifier( newName ) ) );
}

void QgsHanaProviderConnection::renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const
{
checkCapability( Capability::RenameVectorTable );
renameTable( schema, name, newName );
}

void QgsHanaProviderConnection::createSchema( const QString &name ) const
{
checkCapability( Capability::CreateSchema );
Expand Down Expand Up @@ -263,12 +258,10 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsHanaProviderConnection::ex
if ( feedback && feedback->isCanceled() )
return QueryResult( std::make_shared<QgsHanaEmptyProviderResultIterator>() );

bool isQuery = false;

try
{
odbc::PreparedStatementRef stmt = conn->prepareStatement( sql );
isQuery = stmt->getMetaDataUnicode()->getColumnCount() > 0;
bool isQuery = stmt->getMetaDataUnicode()->getColumnCount() > 0;
if ( isQuery )
{
QgsHanaResultSetRef rs = conn->executeQuery( sql );
Expand Down
2 changes: 0 additions & 2 deletions src/providers/hana/qgshanaproviderconnection.h
Expand Up @@ -78,8 +78,6 @@ class QgsHanaProviderConnection : public QgsAbstractDatabaseProviderConnection
private:
void executeSqlStatement( const QString &sql ) const;
void setCapabilities();
void dropTable( const QString &schema, const QString &name ) const;
void renameTable( const QString &schema, const QString &name, const QString &newName ) const;
QList<QgsAbstractDatabaseProviderConnection::TableProperty> tablesWithFilter( const QString &schema,
const TableFlags &flags = TableFlags(), const std::function<bool( const QgsHanaLayerProperty &layer )> &layerFilter = nullptr ) const;
};
Expand Down

0 comments on commit cd2865a

Please sign in to comment.