Skip to content
Permalink
Browse files
save spatialite as: create integer column from qlonglong if it fits (f…
…ixes #12325; followup b736317)
  • Loading branch information
jef-n committed Jun 14, 2015
1 parent 19b6b04 commit 6e55fbe1495e5a3d2a1ba3181a71543e026edc1a
Showing with 17 additions and 1 deletion.
  1. +17 −1 src/core/qgsvectorfilewriter.cpp
@@ -1866,6 +1866,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
}

QGis::WkbType wkbType = layer->wkbType();
QgsFields fields = skipAttributeCreation ? QgsFields() : layer->pendingFields();

if ( layer->providerType() == "ogr" && layer->dataProvider() )
{
@@ -1898,9 +1899,24 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
}
}
}
else if ( layer->providerType() == "spatialite" )
{
for ( int i = 0; i < fields.size(); i++ )
{
if ( fields[i].type() == QVariant::LongLong )
{
QVariant min = layer->minimumValue( i );
QVariant max = layer->maximumValue( i );
if ( qMax( qAbs( min.toLongLong() ), qAbs( max.toLongLong() ) ) < INT_MAX )
{
fields[i].setType( QVariant::Int );
}
}
}
}

QgsVectorFileWriter* writer =
new QgsVectorFileWriter( fileName, fileEncoding, skipAttributeCreation ? QgsFields() : layer->pendingFields(), wkbType, outputCRS, driverName, datasourceOptions, layerOptions, newFilename, symbologyExport );
new QgsVectorFileWriter( fileName, fileEncoding, fields, wkbType, outputCRS, driverName, datasourceOptions, layerOptions, newFilename, symbologyExport );
writer->setSymbologyScaleDenominator( symbologyScale );

if ( newFilename )

0 comments on commit 6e55fbe

Please sign in to comment.