@@ -1096,9 +1096,22 @@ bool QgsPostgresProvider::loadFields()
10961096 }
10971097 }
10981098 }
1099+ else if ( fieldTypeName == " varchar" )
1100+ {
1101+ fieldType = QVariant::String;
1102+
1103+ QRegExp re ( " character varying\\ ((\\ d+)\\ )" );
1104+ if ( re.exactMatch ( formattedFieldType ) )
1105+ {
1106+ fieldSize = re.cap ( 1 ).toInt ();
1107+ }
1108+ else
1109+ {
1110+ fieldSize = -1 ;
1111+ }
1112+ }
10991113 else if ( fieldTypeName == " text" ||
11001114 fieldTypeName == " bpchar" ||
1101- fieldTypeName == " varchar" ||
11021115 fieldTypeName == " bool" ||
11031116 fieldTypeName == " geometry" ||
11041117 fieldTypeName == " money" ||
@@ -1449,20 +1462,20 @@ bool QgsPostgresProvider::determinePrimaryKey()
14491462 {
14501463 QString name = res.PQgetvalue ( i, 0 );
14511464
1452- int j;
1453- for ( j = 0 ; j < mAttributeFields .size () && mAttributeFields [j].name () != name; j++ )
1454- ;
1465+ int idx = mAttributeFields .key ( name, -1 );
14551466
1456- if ( j == mAttributeFields . size () )
1467+ if ( idx < 0 )
14571468 {
14581469 QgsDebugMsg ( " Skipping " + name );
14591470 continue ;
14601471 }
14611472
1462- if ( isInt && mAttributeFields [j].type () != QVariant::Int && mAttributeFields [j].type () != QVariant::LongLong )
1473+ if ( isInt &&
1474+ mAttributeFields [idx].type () != QVariant::Int &&
1475+ mAttributeFields [idx].type () != QVariant::LongLong )
14631476 isInt = false ;
14641477
1465- mPrimaryKeyAttrs << j ;
1478+ mPrimaryKeyAttrs << idx ;
14661479 }
14671480
14681481 mPrimaryKeyType = ( mPrimaryKeyAttrs .size () == 1 && isInt ) ? pktInt : pktFidMap;
0 commit comments