Skip to content

Commit e491acb

Browse files
committed
Merge pull request #680 from ddanielvaz/master
Fix #7822. Export to Spatialite is really slow, compared to commandline ogr2ogr
2 parents c8d3fa7 + 9a0be04 commit e491acb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/core/qgsvectorfilewriter.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,16 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
801801

802802
writer->startRender( layer );
803803

804+
// enabling transaction on databases that support it
805+
bool transactionsEnabled = true;
806+
OGRLayerH ogrCurrentLayer = writer->getLayer();
807+
808+
if ( OGRERR_NONE != OGR_L_StartTransaction(ogrCurrentLayer) )
809+
{
810+
QgsDebugMsg("Error when trying to enable transactions on OGRLayer.");
811+
transactionsEnabled = false;
812+
}
813+
804814
// write all features
805815
while ( fit.nextFeature( fet ) )
806816
{
@@ -862,6 +872,14 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
862872
n++;
863873
}
864874

875+
if ( transactionsEnabled )
876+
{
877+
if ( OGRERR_NONE != OGR_L_CommitTransaction(ogrCurrentLayer) )
878+
{
879+
QgsDebugMsg("Error while commiting transaction on OGRLayer.");
880+
}
881+
}
882+
865883
writer->stopRender( layer );
866884
delete writer;
867885

src/core/qgsvectorfilewriter.h

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class CORE_EXPORT QgsVectorFileWriter
154154

155155
double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
156156
void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
157+
158+
/**Returns OGRLayer used to begin and commit transactions on database*/
159+
OGRLayerH getLayer() { return mLayer; }
157160

158161
protected:
159162
//! @note not available in python bindings

0 commit comments

Comments
 (0)