@@ -82,6 +82,8 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
82
82
OGRFieldType ogrType = OFTString; // default to string
83
83
int ogrWidth = field.length ();
84
84
int ogrPrecision = field.precision ();
85
+ if ( ogrPrecision > 0 )
86
+ ogrWidth += 1 ;
85
87
switch ( field.type () )
86
88
{
87
89
case QVariant::LongLong:
@@ -789,6 +791,11 @@ void QgsOgrProvider::loadFields()
789
791
}
790
792
}
791
793
794
+ int width = OGR_Fld_GetWidth ( fldDef );
795
+ int prec = OGR_Fld_GetPrecision ( fldDef );
796
+ if ( prec > 0 )
797
+ width -= 1 ;
798
+
792
799
mAttributeFields .append (
793
800
QgsField (
794
801
name,
@@ -798,8 +805,9 @@ void QgsOgrProvider::loadFields()
798
805
#else
799
806
mEncoding ->toUnicode ( OGR_GetFieldTypeName ( ogrType ) ),
800
807
#endif
801
- OGR_Fld_GetWidth ( fldDef ),
802
- OGR_Fld_GetPrecision ( fldDef ) ) );
808
+ width, prec
809
+ )
810
+ );
803
811
}
804
812
}
805
813
}
@@ -1142,7 +1150,10 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1142
1150
}
1143
1151
1144
1152
OGRFieldDefnH fielddefn = OGR_Fld_Create ( mEncoding ->fromUnicode ( iter->name () ).constData (), type );
1145
- OGR_Fld_SetWidth ( fielddefn, iter->length () );
1153
+ int width = iter->length ();
1154
+ if ( iter->precision () )
1155
+ width += 1 ;
1156
+ OGR_Fld_SetWidth ( fielddefn, width );
1146
1157
OGR_Fld_SetPrecision ( fielddefn, iter->precision () );
1147
1158
1148
1159
if ( OGR_L_CreateField ( ogrLayer, fielddefn, true ) != OGRERR_NONE )
@@ -2171,6 +2182,8 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
2171
2182
2172
2183
int width = fields.size () > 1 ? fields[1 ].toInt () : -1 ;
2173
2184
int precision = fields.size () > 2 ? fields[2 ].toInt () : -1 ;
2185
+ if ( precision > 0 )
2186
+ width += 1 ;
2174
2187
2175
2188
OGRFieldDefnH field;
2176
2189
if ( fields[0 ] == " Real" )
0 commit comments