Skip to content
Permalink
Browse files

Implement encodeUri and decodeUri, fixes #39759

  • Loading branch information
rduivenvoorde committed Nov 6, 2020
1 parent f6e6149 commit cf2df8d247568260b5a2128f145ddac89862476c
Showing with 87 additions and 0 deletions.
  1. +84 −0 src/providers/oracle/qgsoracleprovider.cpp
  2. +3 −0 src/providers/oracle/qgsoracleprovider.h
@@ -3807,4 +3807,88 @@ QGISEXTERN QgsProviderGuiMetadata *providerGuiMetadataFactory()
}
#endif

QVariantMap QgsOracleProviderMetadata::decodeUri( const QString &uri ) const
{
const QgsDataSourceUri dsUri { uri };
QVariantMap uriParts;

if ( ! dsUri.database().isEmpty() )
uriParts[ QStringLiteral( "dbname" ) ] = dsUri.database();
if ( ! dsUri.host().isEmpty() )
uriParts[ QStringLiteral( "host" ) ] = dsUri.host();
if ( ! dsUri.port().isEmpty() )
uriParts[ QStringLiteral( "port" ) ] = dsUri.port();
if ( ! dsUri.service().isEmpty() )
uriParts[ QStringLiteral( "service" ) ] = dsUri.service();
if ( ! dsUri.username().isEmpty() )
uriParts[ QStringLiteral( "username" ) ] = dsUri.username();
if ( ! dsUri.password().isEmpty() )
uriParts[ QStringLiteral( "password" ) ] = dsUri.password();
if ( ! dsUri.authConfigId().isEmpty() )
uriParts[ QStringLiteral( "authcfg" ) ] = dsUri.authConfigId();
if ( dsUri.wkbType() != QgsWkbTypes::Type::Unknown )
uriParts[ QStringLiteral( "type" ) ] = dsUri.wkbType();
if ( uri.contains( QStringLiteral( "selectatid=" ), Qt::CaseSensitivity::CaseInsensitive ) )
uriParts[ QStringLiteral( "selectatid" ) ] = ! dsUri.selectAtIdDisabled();
if ( ! dsUri.table().isEmpty() )
uriParts[ QStringLiteral( "table" ) ] = dsUri.table();
if ( ! dsUri.schema().isEmpty() )
uriParts[ QStringLiteral( "schema" ) ] = dsUri.schema();
if ( ! dsUri.keyColumn().isEmpty() )
uriParts[ QStringLiteral( "key" ) ] = dsUri.keyColumn();
if ( ! dsUri.srid().isEmpty() )
uriParts[ QStringLiteral( "srid" ) ] = dsUri.srid();
if ( uri.contains( QStringLiteral( "estimatedmetadata=" ), Qt::CaseSensitivity::CaseInsensitive ) )
uriParts[ QStringLiteral( "estimatedmetadata" ) ] = dsUri.useEstimatedMetadata();
if ( uri.contains( QStringLiteral( "sslmode=" ), Qt::CaseSensitivity::CaseInsensitive ) )
uriParts[ QStringLiteral( "sslmode" ) ] = dsUri.sslMode();
if ( ! dsUri.sql().isEmpty() )
uriParts[ QStringLiteral( "sql" ) ] = dsUri.sql();
if ( ! dsUri.geometryColumn().isEmpty() )
uriParts[ QStringLiteral( "geometrycolumn" ) ] = dsUri.geometryColumn();
return uriParts;
}

QString QgsOracleProviderMetadata::encodeUri( const QVariantMap &parts ) const
{
QgsDataSourceUri dsUri;
if ( parts.contains( QStringLiteral( "dbname" ) ) )
dsUri.setDatabase( parts.value( QStringLiteral( "dbname" ) ).toString() );
if ( parts.contains( QStringLiteral( "host" ) ) )
dsUri.setParam( QStringLiteral( "host" ), parts.value( QStringLiteral( "host" ) ).toString() );
if ( parts.contains( QStringLiteral( "port" ) ) )
dsUri.setParam( QStringLiteral( "port" ), parts.value( QStringLiteral( "port" ) ).toString() );
if ( parts.contains( QStringLiteral( "service" ) ) )
dsUri.setParam( QStringLiteral( "service" ), parts.value( QStringLiteral( "service" ) ).toString() );
if ( parts.contains( QStringLiteral( "username" ) ) )
dsUri.setUsername( parts.value( QStringLiteral( "username" ) ).toString() );
if ( parts.contains( QStringLiteral( "password" ) ) )
dsUri.setPassword( parts.value( QStringLiteral( "password" ) ).toString() );
if ( parts.contains( QStringLiteral( "authcfg" ) ) )
dsUri.setAuthConfigId( parts.value( QStringLiteral( "authcfg" ) ).toString() );
if ( parts.contains( QStringLiteral( "type" ) ) )
dsUri.setParam( QStringLiteral( "type" ), QgsWkbTypes::displayString( static_cast<QgsWkbTypes::Type>( parts.value( QStringLiteral( "type" ) ).toInt() ) ) );
if ( parts.contains( QStringLiteral( "selectatid" ) ) )
dsUri.setParam( QStringLiteral( "selectatid" ), parts.value( QStringLiteral( "selectatid" ) ).toString() );
if ( parts.contains( QStringLiteral( "table" ) ) )
dsUri.setTable( parts.value( QStringLiteral( "table" ) ).toString() );
if ( parts.contains( QStringLiteral( "schema" ) ) )
dsUri.setSchema( parts.value( QStringLiteral( "schema" ) ).toString() );
if ( parts.contains( QStringLiteral( "key" ) ) )
dsUri.setParam( QStringLiteral( "key" ), parts.value( QStringLiteral( "key" ) ).toString() );
if ( parts.contains( QStringLiteral( "srid" ) ) )
dsUri.setSrid( parts.value( QStringLiteral( "srid" ) ).toString() );
if ( parts.contains( QStringLiteral( "estimatedmetadata" ) ) )
dsUri.setParam( QStringLiteral( "estimatedmetadata" ), parts.value( QStringLiteral( "estimatedmetadata" ) ).toString() );
if ( parts.contains( QStringLiteral( "sslmode" ) ) )
dsUri.setParam( QStringLiteral( "sslmode" ), QgsDataSourceUri::encodeSslMode( static_cast<QgsDataSourceUri::SslMode>( parts.value( QStringLiteral( "sslmode" ) ).toInt( ) ) ) );
if ( parts.contains( QStringLiteral( "sql" ) ) )
dsUri.setSql( parts.value( QStringLiteral( "sql" ) ).toString() );
if ( parts.contains( QStringLiteral( "checkPrimaryKeyUnicity" ) ) )
dsUri.setParam( QStringLiteral( "checkPrimaryKeyUnicity" ), parts.value( QStringLiteral( "checkPrimaryKeyUnicity" ) ).toString() );
if ( parts.contains( QStringLiteral( "geometrycolumn" ) ) )
dsUri.setGeometryColumn( parts.value( QStringLiteral( "geometrycolumn" ) ).toString() );
return dsUri.uri( false );
}

// vim: set sw=2
@@ -417,6 +417,9 @@ class QgsOracleProviderMetadata final: public QgsProviderMetadata
QList<QgsDataItemProvider *> dataItemProviders() const override;

QgsTransaction *createTransaction( const QString &connString ) override;

QVariantMap decodeUri( const QString &uri ) const override;
QString encodeUri( const QVariantMap &parts ) const override;
};

#ifdef HAVE_GUI

0 comments on commit cf2df8d

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