Skip to content

Commit

Permalink
fix #2681
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13406 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 28, 2010
1 parent 20904e6 commit 7b48ca7
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3003,27 +3003,67 @@ bool QgsPostgresProvider::getGeometryDetails()
Result result;
QString sql;

if ( !isQuery )
QString schemaName = mSchemaName;
QString tableName = mTableName;
QString geomCol = geometryColumn;

if ( isQuery )
{
sql = QString( "select type,srid from geometry_columns"
" where f_table_name=%1 and f_geometry_column=%2 and f_table_schema=%3" )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( geometryColumn ) )
.arg( quotedValue( mSchemaName ) );
sql = QString( "select %1 from %2 limit 0" ).arg( quotedIdentifier( geometryColumn ) ).arg( mQuery );

QgsDebugMsg( "Getting geometry column: " + sql );

Result result = connectionRO->PQexec( sql );
if ( PGRES_TUPLES_OK == PQresultStatus( result ) )
{
Oid tableOid = PQftable( result, 0 );
int column = PQftablecol( result, 0 );

QgsDebugMsg( "geometry column query returned " + QString::number( PQntuples( result ) ) );
result = connectionRO->PQexec( sql );
if ( tableOid >= 0 && PGRES_TUPLES_OK == PQresultStatus( result ) )
{
sql = QString( "SELECT pg_namespace.nspname,pg_class.relname FROM pg_class,pg_namespace WHERE pg_class.relnamespace=pg_namespace.oid AND pg_class.oid=%1" ).arg( tableOid );
result = connectionRO->PQexec( sql );

if ( PQntuples( result ) > 0 )
{
fType = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );
srid = QString::fromUtf8( PQgetvalue( result, 0, 1 ) );
if ( PGRES_TUPLES_OK == PQresultStatus( result ) && 1 == PQntuples( result ) )
{
schemaName = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );
tableName = QString::fromUtf8( PQgetvalue( result, 0, 1 ) );

sql = QString( "SELECT attname FROM pg_attribute WHERE attrelid=%1 AND attnum=%2" ).arg( tableOid ).arg( column );
result = connectionRO->PQexec( sql );
if ( PGRES_TUPLES_OK == PQresultStatus( result ) && 1 == PQntuples( result ) )
{
geomCol = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );
}
else
{
schemaName = mSchemaName;
tableName = mTableName;
}
}
}
}
}

sql = QString( "select type,srid from geometry_columns"
" where f_table_name=%1 and f_geometry_column=%2 and f_table_schema=%3" )
.arg( quotedValue( tableName ) )
.arg( quotedValue( geomCol ) )
.arg( quotedValue( schemaName ) );

QgsDebugMsg( "Getting geometry column: " + sql );

result = connectionRO->PQexec( sql );

QgsDebugMsg( "geometry column query returned " + QString::number( PQntuples( result ) ) );

if ( PQntuples( result ) > 0 )
{
fType = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );
srid = QString::fromUtf8( PQgetvalue( result, 0, 1 ) );
}

if ( srid.isEmpty() || fType.isEmpty() )
{
// Didn't find what we need in the geometry_columns table, so
Expand Down

0 comments on commit 7b48ca7

Please sign in to comment.