Skip to content

Commit

Permalink
postgres provider update:
Browse files Browse the repository at this point in the history
- only use typlen for char fields
- use subset string when checking for key uniqueness and recheck in setSubsetString() (fixes #1933)


git-svn-id: http://svn.osgeo.org/qgis/trunk@11703 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 22, 2009
1 parent d6735d1 commit b950808
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -907,14 +907,18 @@ void QgsPostgresProvider::loadFields()
fieldSize = -1;
}
else if ( fieldTypeName == "text" ||
fieldTypeName == "char" ||
fieldTypeName == "bpchar" ||
fieldTypeName == "varchar" ||
fieldTypeName == "bool" ||
fieldTypeName == "geometry" ||
fieldTypeName == "money" ||
fieldTypeName.startsWith( "time" ) ||
fieldTypeName.startsWith( "date" ) )
{
fieldType = QVariant::String;
fieldSize = -1;
}
else if ( fieldTypeName == "char" )
{
fieldType = QVariant::String;
}
Expand Down Expand Up @@ -1382,6 +1386,11 @@ bool QgsPostgresProvider::uniqueData( QString schemaName,
.arg( quotedIdentifier( schemaName ) )
.arg( quotedIdentifier( tableName ) );

if ( !sqlWhereClause.isEmpty() )
{
sql += " where " + sqlWhereClause;
}

Result unique = connectionRO->PQexec( sql );

if ( PQntuples( unique ) == 1 && QString::fromUtf8( PQgetvalue( unique, 0, 0 ) ).startsWith( "t" ) )
Expand Down Expand Up @@ -2506,7 +2515,16 @@ int QgsPostgresProvider::capabilities() const

void QgsPostgresProvider::setSubsetString( QString theSQL )
{
QString prevWhere = sqlWhereClause;

sqlWhereClause = theSQL;

if( !uniqueData( mSchemaName, mTableName, primaryKey ) )
{
sqlWhereClause = prevWhere;
return;
}

// Update datasource uri too
mUri.setSql( theSQL );
// Update yet another copy of the uri. Why are there 3 copies of the
Expand Down

0 comments on commit b950808

Please sign in to comment.