Skip to content
Permalink
Browse files

postgres provider: fix lookup of aliased columns

  • Loading branch information
jef-n committed May 5, 2014
1 parent 9d05631 commit 18ac13c9227e7187f3b75156e1ac5c584f8048fa
Showing with 10 additions and 12 deletions.
  1. +10 −12 src/providers/postgres/qgspostgresprovider.cpp
@@ -637,6 +637,7 @@ bool QgsPostgresProvider::loadFields()
int fieldPrec = -1;
QString fieldComment( "" );
int tableoid = result.PQftable( i );
int attnum = result.PQftablecol( i );

sql = QString( "SELECT typname,typtype,typelem,typlen FROM pg_type WHERE oid=%1" ).arg( typOid );
// just oid; needs more work to support array type
@@ -652,22 +653,19 @@ bool QgsPostgresProvider::loadFields()
QString formattedFieldType;
if ( tableoid > 0 )
{
sql = QString( "SELECT attnum,pg_catalog.format_type(atttypid,atttypmod) FROM pg_attribute WHERE attrelid=%1 AND attname=%2" )
.arg( tableoid ).arg( quotedValue( fieldName ) );
sql = QString( "SELECT pg_catalog.format_type(atttypid,atttypmod) FROM pg_attribute WHERE attrelid=%1 AND attnum=%2" )
.arg( tableoid ).arg( quotedValue( attnum ) );

QgsPostgresResult tresult = mConnectionRO->PQexec( sql );
QString attnum = tresult.PQgetvalue( 0, 0 );
formattedFieldType = tresult.PQgetvalue( 0, 1 );
if ( tresult.PQntuples() > 0 )
formattedFieldType = tresult.PQgetvalue( 0, 0 );

if ( !attnum.isEmpty() )
{
sql = QString( "SELECT description FROM pg_description WHERE objoid=%1 AND objsubid=%2" )
.arg( tableoid ).arg( attnum );
sql = QString( "SELECT description FROM pg_description WHERE objoid=%1 AND objsubid=%2" )
.arg( tableoid ).arg( attnum );

tresult = mConnectionRO->PQexec( sql );
if ( tresult.PQntuples() > 0 )
fieldComment = tresult.PQgetvalue( 0, 0 );
}
tresult = mConnectionRO->PQexec( sql );
if ( tresult.PQntuples() > 0 )
fieldComment = tresult.PQgetvalue( 0, 0 );
}

QVariant::Type fieldType;

0 comments on commit 18ac13c

Please sign in to comment.
You can’t perform that action at this time.