Showing with 47 additions and 34 deletions.
  1. +2 −2 src/core/raster/qgsrasterblock.cpp
  2. +0 −3 src/mapserver/qgswfsserver.cpp
  3. +45 −28 src/providers/postgres/qgspostgresconn.cpp
  4. +0 −1 src/providers/wfs/qgswfsprovider.cpp
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ bool QgsRasterBlock::isNoDataValue( double value ) const

double QgsRasterBlock::value( size_t index ) const
{
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
if ( index >= ( size_t )mWidth*mHeight )
{
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return mNoDataValue;
Expand Down Expand Up @@ -282,7 +282,7 @@ QRgb QgsRasterBlock::color( int row, int column ) const

bool QgsRasterBlock::isNoData( size_t index )
{
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
if ( index >= ( size_t )mWidth*mHeight )
{
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return true; // we consider no data if outside
Expand Down
3 changes: 0 additions & 3 deletions src/mapserver/qgswfsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,6 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
{
// Create feature for this layer
QgsFeature* f = new QgsFeature();
unsigned char* wkb = 0;
int wkbSize = 0;
QGis::WkbType currentType;

QDomElement featureElem = featNodes.at( l ).toElement();

Expand Down
73 changes: 45 additions & 28 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,53 +298,67 @@ QStringList QgsPostgresConn::pkCandidates( QString schemaName, QString viewName
bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables )
{
int nColumns = 0;
int nGTables = 0;
int foundInTables = 0;
QgsPostgresResult result;
QgsPostgresLayerProperty layerProperty;

QgsDebugMsg( "Entering." );

mLayersSupported.clear();

// TODO: query topology.layer too !

for ( int i = 0; i < 2; i++ )
for ( int i = 0; i < 3; i++ )
{
QString gtableName, columnName;
QString sql, tableName, schemaName, columnName, typeName, sridName, gtableName;

if ( i == 0 )
{
tableName = "l.f_table_name";
schemaName = "l.f_table_schema";
columnName = "l.f_geometry_column";
typeName = "upper(l.type)";
sridName = "l.srid";
gtableName = "geometry_columns";
columnName = "f_geometry_column";
}
else if ( i == 1 )
{
tableName = "l.f_table_name";
schemaName = "l.f_table_schema";
columnName = "l.f_geography_column";
typeName = "upper(l.type)";
sridName = "l.srid";
gtableName = "geography_columns";
columnName = "f_geography_column";
}
else if ( i == 2 )
{
schemaName = "l.schema_name";
tableName = "l.table_name";
columnName = "l.feature_column";
typeName = "CASE "
"WHEN l.feature_type = 1 THEN 'MULTIPOINT' "
"WHEN l.feature_type = 2 THEN 'MULTILINESTRING' "
"WHEN l.feature_type = 3 THEN 'MULTIPOLYGON' "
"WHEN l.feature_type = 4 THEN 'GEOMETRYCOLLECTION' "
"END AS type";
sridName = "(SELECT srid FROM topology.topology t WHERE l.topology_id=t.id)";
gtableName = "topology.layer";
}

// The following query returns only tables that exist and the user has SELECT privilege on.
// Can't use regclass here because table must exist, else error occurs.
QString sql = QString( "SELECT "
"f_table_name,"
"f_table_schema,"
"%2,"
"upper(type),"
"srid,"
"pg_class.relkind"
" FROM "
"%1,pg_class,pg_namespace"
" WHERE relname=f_table_name"
" AND f_table_schema=nspname"
" AND pg_namespace.oid=pg_class.relnamespace"
" AND has_schema_privilege(pg_namespace.nspname,'usage')"
" AND has_table_privilege('\"'||pg_namespace.nspname||'\".\"'||pg_class.relname||'\"','select')" // user has select privilege
).arg( gtableName ).arg( columnName );
sql = QString( "SELECT %1,%2,%3,%4,c.relkind"
" FROM %5 l,pg_class c,pg_namespace n"
" WHERE c.relname=%1"
" AND %2=n.nspname"
" AND n.oid=c.relnamespace"
" AND has_schema_privilege(n.nspname,'usage')"
" AND has_table_privilege('\"'||n.nspname||'\".\"'||c.relname||'\"','select')" // user has select privilege
)
.arg( tableName ).arg( schemaName ).arg( columnName ).arg( typeName ).arg( gtableName );

if ( searchPublicOnly )
sql += " AND f_table_schema='public'";
sql += " AND n.nspname='public'";

sql += QString( " ORDER BY f_table_schema,f_table_name,%1" ).arg( columnName );
sql += QString( " ORDER BY n.nspname,c.relname,%1" ).arg( columnName );

QgsDebugMsg( "getting table info: " + sql );
result = PQexec( sql, i == 0 );
Expand All @@ -354,8 +368,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
continue;
}

nGTables++;

for ( int idx = 0; idx < result.PQntuples(); idx++ )
{
QString tableName = result.PQgetvalue( idx, 0 );
Expand Down Expand Up @@ -384,6 +396,8 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
mLayersSupported << layerProperty;
nColumns++;
}

foundInTables |= 1 << i;
}

if ( nColumns == 0 )
Expand Down Expand Up @@ -420,12 +434,15 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
{
sql += " AND (pg_namespace.nspname,pg_class.relname,pg_attribute.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geometry_column FROM geometry_columns)";

if ( nGTables > 1 )
if ( foundInTables & 1 )
{
sql += " AND (pg_namespace.nspname,pg_class.relname,pg_attribute.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geography_column FROM geography_columns)";
}

// TODO: handle this for the topogeometry case (once we lookup topology.layer)
if ( foundInTables & 2 )
{
sql += " AND (pg_namespace.nspname,pg_class.relname,pg_attribute.attname) NOT IN (SELECT schema_name,table_name,feature_column FROM topology.layer)";
}
}

sql += " AND pg_class.relkind IN ('v','r')"; // only from views and relations (tables)
Expand Down
1 change: 0 additions & 1 deletion src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,6 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
QgsFeature* f = 0;
unsigned char* wkb = 0;
int wkbSize = 0;
QGis::WkbType currentType;
mFeatureCount = 0;

for ( int i = 0; i < featureTypeNodeList.size(); ++i )
Expand Down