Skip to content
Permalink
Browse files

save spatialite as: create integer column from qlonglong if it fits (f…

…ixes #12325; followup b736317)

(cherry picked from commit 6e55fbe)
  • Loading branch information
jef-n committed Jun 14, 2015
1 parent 8f33dc4 commit 38961dc742758e326c58e28a25a27c4120e381a8
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 38961dc

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