Skip to content

Commit

Permalink
postgres provider:
Browse files Browse the repository at this point in the history
- fix primary key detection, if column is behind geometry column
- add support for varchar length limits
  • Loading branch information
jef-n committed Feb 14, 2012
1 parent 54b2cd2 commit 659abb8
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1096,9 +1096,22 @@ bool QgsPostgresProvider::loadFields()
}
}
}
else if ( fieldTypeName == "varchar" )
{
fieldType = QVariant::String;

QRegExp re( "character varying\\((\\d+)\\)" );
if ( re.exactMatch( formattedFieldType ) )
{
fieldSize = re.cap( 1 ).toInt();
}
else
{
fieldSize = -1;
}
}
else if ( fieldTypeName == "text" ||
fieldTypeName == "bpchar" ||
fieldTypeName == "varchar" ||
fieldTypeName == "bool" ||
fieldTypeName == "geometry" ||
fieldTypeName == "money" ||
Expand Down Expand Up @@ -1449,20 +1462,20 @@ bool QgsPostgresProvider::determinePrimaryKey()
{
QString name = res.PQgetvalue( i, 0 );

int j;
for ( j = 0; j < mAttributeFields.size() && mAttributeFields[j].name() != name; j++ )
;
int idx = mAttributeFields.key( name, -1 );

if ( j == mAttributeFields.size() )
if ( idx < 0 )
{
QgsDebugMsg( "Skipping " + name );
continue;
}

if ( isInt && mAttributeFields[j].type() != QVariant::Int && mAttributeFields[j].type() != QVariant::LongLong )
if ( isInt &&
mAttributeFields[idx].type() != QVariant::Int &&
mAttributeFields[idx].type() != QVariant::LongLong )
isInt = false;

mPrimaryKeyAttrs << j;
mPrimaryKeyAttrs << idx;
}

mPrimaryKeyType = ( mPrimaryKeyAttrs.size() == 1 && isInt ) ? pktInt : pktFidMap;
Expand Down

0 comments on commit 659abb8

Please sign in to comment.