Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Allow newer format strings for destination paths, accept…
… output strings for mssql, oracle, ... providers
  • Loading branch information
nyalldawson committed Mar 26, 2020
1 parent 03fd0f6 commit 4547ce6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -602,16 +602,26 @@ QString QgsProcessingUtils::stringToPythonLiteral( const QString &string )
void QgsProcessingUtils::parseDestinationString( QString &destination, QString &providerKey, QString &uri, QString &layerName, QString &format, QMap<QString, QVariant> &options, bool &useWriter, QString &extension )
{
extension.clear();
QRegularExpression splitRx( QStringLiteral( "^(.{3,}?):(.*)$" ) );
QRegularExpressionMatch match = splitRx.match( destination );
if ( match.hasMatch() )
bool matched = decodeProviderKeyAndUri( destination, providerKey, uri );

if ( !matched )
{
QRegularExpression splitRx( QStringLiteral( "^(.{3,}?):(.*)$" ) );
QRegularExpressionMatch match = splitRx.match( destination );
if ( match.hasMatch() )
{
providerKey = match.captured( 1 );
uri = match.captured( 2 );
matched = true;
}
}

if ( matched )
{
providerKey = match.captured( 1 );
if ( providerKey == QStringLiteral( "postgis" ) ) // older processing used "postgis" instead of "postgres"
{
providerKey = QStringLiteral( "postgres" );
}
uri = match.captured( 2 );
if ( providerKey == QLatin1String( "ogr" ) )
{
QgsDataSourceUri dsUri( uri );
Expand Down
15 changes: 15 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -1629,6 +1629,21 @@ void TestQgsProcessing::parseDestinationString()
QVERIFY( !useWriter );
QVERIFY( extension.isEmpty() );

// newer format
destination = QStringLiteral( "postgres://dbname='db' host=DBHOST port=5432 table=\"calcs\".\"output\" (geom) sql=" );
QgsProcessingUtils::parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
QCOMPARE( providerKey, QStringLiteral( "postgres" ) );
QCOMPARE( uri, QStringLiteral( "dbname='db' host=DBHOST port=5432 table=\"calcs\".\"output\" (geom) sql=" ) );
QVERIFY( !useWriter );
QVERIFY( extension.isEmpty() );
//mssql
destination = QStringLiteral( "mssql://dbname='db' host=DBHOST port=5432 table=\"calcs\".\"output\" (geom) sql=" );
QgsProcessingUtils::parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
QCOMPARE( providerKey, QStringLiteral( "mssql" ) );
QCOMPARE( uri, QStringLiteral( "dbname='db' host=DBHOST port=5432 table=\"calcs\".\"output\" (geom) sql=" ) );
QVERIFY( !useWriter );
QVERIFY( extension.isEmpty() );

// full uri shp output
options.clear();
destination = QStringLiteral( "ogr:d:/test.shp" );
Expand Down

0 comments on commit 4547ce6

Please sign in to comment.