HANA: improve error message by unknown types

This commit is contained in:
Maxim Rylov 2021-09-23 08:34:57 +02:00 committed by Nyall Dawson
parent 3d55a14553
commit b07e37390e
4 changed files with 5 additions and 17 deletions

View File

@ -175,6 +175,8 @@ public:
static constexpr int TypeTime = 92; static constexpr int TypeTime = 92;
/// Year, month, day, hour, minute, and second fields. /// Year, month, day, hour, minute, and second fields.
static constexpr int TypeTimestamp = 93; static constexpr int TypeTimestamp = 93;
/// Unknown data type.
static constexpr int Unknown = 0;
/// Variable length binary data. /// Variable length binary data.
static constexpr int VarBinary = -3; static constexpr int VarBinary = -3;
/// Variable-length character string. /// Variable-length character string.

View File

@ -826,6 +826,8 @@ void QgsHanaConnection::readTableFields( const QString &schemaName, const QStrin
field.name = rsColumns->getString( 4/*COLUMN_NAME*/ ); field.name = rsColumns->getString( 4/*COLUMN_NAME*/ );
field.type = rsColumns->getShort( 5/*DATA_TYPE*/ ); field.type = rsColumns->getShort( 5/*DATA_TYPE*/ );
field.typeName = rsColumns->getString( 6/*TYPE_NAME*/ ); field.typeName = rsColumns->getString( 6/*TYPE_NAME*/ );
if ( field.type == SQLDataTypes::Unknown )
throw QgsHanaException( QString( "Type of the column '%1' is unknown" ).arg( field.name ) );
field.size = rsColumns->getInt( 7/*COLUMN_SIZE*/ ); field.size = rsColumns->getInt( 7/*COLUMN_SIZE*/ );
field.precision = static_cast<int>( rsColumns->getShort( 9/*DECIMAL_DIGITS*/ ) ); field.precision = static_cast<int>( rsColumns->getShort( 9/*DECIMAL_DIGITS*/ ) );
field.isSigned = field.type == SQLDataTypes::SmallInt || field.type == SQLDataTypes::Integer || field.isSigned = field.type == SQLDataTypes::SmallInt || field.type == SQLDataTypes::Integer ||

View File

@ -439,7 +439,7 @@ QgsFields QgsHanaProviderConnection::fields( const QString &schema, const QStrin
} }
catch ( const QgsHanaException &ex ) catch ( const QgsHanaException &ex )
{ {
throw QgsProviderConnectionException( QObject::tr( "Could not retrieve fields: %1, %2" ).arg( uri(), ex.what() ) ); throw QgsProviderConnectionException( QObject::tr( "Could not retrieve fields: %1" ).arg( ex.what() ) );
} }
} }
@ -475,19 +475,6 @@ QList<QgsVectorDataProvider::NativeType> QgsHanaProviderConnection::nativeTypes(
return types; return types;
} }
QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions QgsHanaProviderConnection::sqlOptions( const QString &layerSource )
{
SqlVectorLayerOptions options;
const QgsDataSourceUri uri( layerSource );
options.primaryKeyColumns = uri.keyColumn().split( ',' );
options.disableSelectAtId = uri.selectAtIdDisabled();
options.geometryColumn = uri.geometryColumn();
options.filter = uri.sql();
const QString trimmedTable { uri.table().trimmed() };
options.sql = trimmedTable.startsWith( '(' ) ? trimmedTable.mid( 1 ).chopped( 1 ) : QStringLiteral( "SELECT * FROM %1" ).arg( uri.quotedTablename() );
return options;
}
QVariantList QgsHanaEmptyProviderResultIterator::nextRowPrivate() QVariantList QgsHanaEmptyProviderResultIterator::nextRowPrivate()
{ {
return QVariantList(); return QVariantList();

View File

@ -78,9 +78,6 @@ class QgsHanaProviderConnection : public QgsAbstractDatabaseProviderConnection
void remove( const QString &name ) const override; void remove( const QString &name ) const override;
QIcon icon() const override; QIcon icon() const override;
QList<QgsVectorDataProvider::NativeType> nativeTypes() const override; QList<QgsVectorDataProvider::NativeType> nativeTypes() const override;
//QgsVectorLayer *createSqlVectorLayer( const SqlVectorLayerOptions &options ) const override;
//QMultiMap<Qgis::SqlKeywordCategory, QStringList> sqlDictionary() override;
SqlVectorLayerOptions sqlOptions( const QString &layerSource ) override;
private: private:
QgsHanaConnectionRef createConnection() const; QgsHanaConnectionRef createConnection() const;