Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 29, 2015
1 parent 8f33dc4 commit 38961dc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 38961dc

Please sign in to comment.