Skip to content

Commit

Permalink
minor pg provider fix: oid==0 is invalid
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13424 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 5, 2010
1 parent 60eb44d commit 4a507e4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ bool QgsPostgresProvider::loadFields()
QString fieldElem = QString::fromUtf8( PQgetvalue( oidResult, 0, 2 ) );
int fieldSize = QString::fromUtf8( PQgetvalue( oidResult, 0, 3 ) ).toInt();

if ( tableoid >= 0 )
if ( tableoid > 0 )
{
sql = QString( "SELECT attnum FROM pg_attribute WHERE attrelid=%1 AND attname=%2" )
.arg( tableoid ).arg( quotedValue( fieldName ) );
Expand Down Expand Up @@ -2940,7 +2940,7 @@ bool QgsPostgresProvider::deduceEndian()
for ( i = 0; i < PQnfields( res ); i++ )
{
int tableoid = PQftable( res, i );
if ( tableoid >= 0 )
if ( tableoid > 0 )
{
oidValue = QString::number( tableoid );
break;
Expand Down Expand Up @@ -3016,31 +3016,31 @@ bool QgsPostgresProvider::getGeometryDetails()
Result result = connectionRO->PQexec( sql );
if ( PGRES_TUPLES_OK == PQresultStatus( result ) )
{
Oid tableOid = PQftable( result, 0 );
Oid tableoid = PQftable( result, 0 );
int column = PQftablecol( result, 0 );

result = connectionRO->PQexec( sql );
if ( tableOid >= 0 && PGRES_TUPLES_OK == PQresultStatus( result ) )
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 );
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 ( 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 );
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;
}
else
{
schemaName = mSchemaName;
tableName = mTableName;
}
}
}
}
Expand Down

0 comments on commit 4a507e4

Please sign in to comment.