Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fixes #39620 : Saving processing results in a database
(cherry picked from commit f5d9154)
- Loading branch information
|
@@ -832,9 +832,11 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs |
|
|
|
|
|
// use destination string as layer name (eg "postgis:..." ) |
|
|
if ( !layerName.isEmpty() ) |
|
|
{ |
|
|
uri += QStringLiteral( "|layername=%1" ).arg( layerName ); |
|
|
// update destination to generated URI |
|
|
destination = uri; |
|
|
// update destination to generated URI |
|
|
destination = uri; |
|
|
} |
|
|
|
|
|
return new QgsProcessingFeatureSink( exporter.release(), destination, context, true ); |
|
|
} |
|
|
|
@@ -2014,6 +2014,21 @@ void TestQgsProcessing::createFeatureSink() |
|
|
QCOMPARE( layer->featureCount(), 2L ); |
|
|
QVERIFY( layer->getFeatures().nextFeature( f ) ); |
|
|
QCOMPARE( f.attribute( "my_field" ).toString(), QStringLiteral( "val2" ) ); |
|
|
|
|
|
// save to database |
|
|
destination = "postgres://dbname='qgis_test' service='qgis_test' table=\"public\".\"test_feature_sink\" (geom)"; |
|
|
sink.reset( QgsProcessingUtils::createFeatureSink( destination, context, fields, QgsWkbTypes::Polygon, QgsCoordinateReferenceSystem::fromEpsgId( 3111 ) ) ); |
|
|
QVERIFY( sink.get() ); |
|
|
f = QgsFeature( fields ); |
|
|
f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "Polygon((0 0, 0 1, 1 1, 1 0, 0 0 ))" ) ) ); |
|
|
f.setAttributes( QgsAttributes() << "val" ); |
|
|
QVERIFY( sink->addFeature( f ) ); |
|
|
sink.reset( nullptr ); |
|
|
layer = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( destination, context, true ) ); |
|
|
QVERIFY( layer && layer->isValid() ); |
|
|
QCOMPARE( layer->wkbType(), QgsWkbTypes::Polygon ); |
|
|
QVERIFY( layer->getFeatures().nextFeature( f ) ); |
|
|
QCOMPARE( f.attribute( "my_field" ).toString(), QStringLiteral( "val" ) ); |
|
|
} |
|
|
|
|
|
void TestQgsProcessing::source() |
|
|