Skip to content
Permalink
Browse files

Fix: unable to drop a view in HANA

  • Loading branch information
mrylov authored and nyalldawson committed Apr 7, 2021
1 parent bddfb94 commit d6388d7d24ba9ef0845e19f5e0e280c40a900a28
Showing with 13 additions and 22 deletions.
  1. +13 −20 src/providers/hana/qgshanaproviderconnection.cpp
  2. +0 −2 src/providers/hana/qgshanaproviderconnection.h
@@ -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"
@@ -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,
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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;
};

0 comments on commit d6388d7

Please sign in to comment.