mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[OGR provider] Make addAttributes() return the requested field type, precision and width so as to make QgsVectorLayerEditBuffer::commitChanges() API
Fixes #15614
This commit is contained in:
parent
7d2098cdf4
commit
bb9c75b394
@ -1348,10 +1348,12 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
|
|||||||
|
|
||||||
bool returnvalue = true;
|
bool returnvalue = true;
|
||||||
|
|
||||||
QMap< QString, QVariant::Type > mapFieldTypesToPatch;
|
QMap< QString, QgsField > mapFieldNameToOriginalField;
|
||||||
|
|
||||||
for ( QList<QgsField>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter )
|
for ( QList<QgsField>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter )
|
||||||
{
|
{
|
||||||
|
mapFieldNameToOriginalField[ iter->name()] = *iter;
|
||||||
|
|
||||||
OGRFieldType type;
|
OGRFieldType type;
|
||||||
|
|
||||||
switch ( iter->type() )
|
switch ( iter->type() )
|
||||||
@ -1367,7 +1369,6 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
|
|||||||
type = OFTInteger64;
|
type = OFTInteger64;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mapFieldTypesToPatch[ iter->name()] = iter->type();
|
|
||||||
type = OFTReal;
|
type = OFTReal;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1410,13 +1411,23 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
|
|||||||
}
|
}
|
||||||
loadFields();
|
loadFields();
|
||||||
|
|
||||||
// Patch field type in case of Integer64->Real mapping so that QVariant::LongLong
|
// The check in QgsVectorLayerEditBuffer::commitChanges() is questionable with
|
||||||
// is still returned to the caller
|
// real-world drivers that might only be able to satisfy request only partially.
|
||||||
for ( QMap< QString, QVariant::Type >::const_iterator it = mapFieldTypesToPatch.begin(); it != mapFieldTypesToPatch.end(); ++it )
|
// So to avoid erroring out, patch field type, width and precision to match
|
||||||
|
// what was requested.
|
||||||
|
// For example in case of Integer64->Real mapping so that QVariant::LongLong is
|
||||||
|
// still returned to the caller
|
||||||
|
// Or if a field width was specified but not strictly enforced by the driver (#15614)
|
||||||
|
for ( QMap< QString, QgsField >::const_iterator it = mapFieldNameToOriginalField.begin();
|
||||||
|
it != mapFieldNameToOriginalField.end(); ++it )
|
||||||
{
|
{
|
||||||
int idx = mAttributeFields.lookupField( it.key() );
|
int idx = mAttributeFields.lookupField( it.key() );
|
||||||
if ( idx >= 0 )
|
if ( idx >= 0 )
|
||||||
mAttributeFields[ idx ].setType( *it );
|
{
|
||||||
|
mAttributeFields[ idx ].setType( it->type() );
|
||||||
|
mAttributeFields[ idx ].setLength( it->length() );
|
||||||
|
mAttributeFields[ idx ].setPrecision( it->precision() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue;
|
return returnvalue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user