Skip to content

Commit b6c3bc0

Browse files
author
jef
committed
postgres provider update:
- 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/qgis@11703 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a73f1cf commit b6c3bc0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,18 @@ void QgsPostgresProvider::loadFields()
907907
fieldSize = -1;
908908
}
909909
else if ( fieldTypeName == "text" ||
910-
fieldTypeName == "char" ||
911910
fieldTypeName == "bpchar" ||
912911
fieldTypeName == "varchar" ||
913912
fieldTypeName == "bool" ||
914913
fieldTypeName == "geometry" ||
915914
fieldTypeName == "money" ||
916915
fieldTypeName.startsWith( "time" ) ||
917916
fieldTypeName.startsWith( "date" ) )
917+
{
918+
fieldType = QVariant::String;
919+
fieldSize = -1;
920+
}
921+
else if ( fieldTypeName == "char" )
918922
{
919923
fieldType = QVariant::String;
920924
}
@@ -1382,6 +1386,11 @@ bool QgsPostgresProvider::uniqueData( QString schemaName,
13821386
.arg( quotedIdentifier( schemaName ) )
13831387
.arg( quotedIdentifier( tableName ) );
13841388

1389+
if ( !sqlWhereClause.isEmpty() )
1390+
{
1391+
sql += " where " + sqlWhereClause;
1392+
}
1393+
13851394
Result unique = connectionRO->PQexec( sql );
13861395

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

25072516
void QgsPostgresProvider::setSubsetString( QString theSQL )
25082517
{
2518+
QString prevWhere = sqlWhereClause;
2519+
25092520
sqlWhereClause = theSQL;
2521+
2522+
if( !uniqueData( mSchemaName, mTableName, primaryKey ) )
2523+
{
2524+
sqlWhereClause = prevWhere;
2525+
return;
2526+
}
2527+
25102528
// Update datasource uri too
25112529
mUri.setSql( theSQL );
25122530
// Update yet another copy of the uri. Why are there 3 copies of the

0 commit comments

Comments
 (0)