Skip to content

Commit

Permalink
Postgres and Oracle: Use trust datasource config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Sep 9, 2020
1 parent 45e9ecb commit 760347c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -81,6 +81,10 @@ QgsOracleProvider::QgsOracleProvider( QString const &uri, const ProviderOptions
mSrid = mUri.srid().toInt();
mRequestedGeomType = mUri.wkbType();
mUseEstimatedMetadata = mUri.useEstimatedMetadata();
if ( mReadFlags & QgsDataProvider::FlagTrustDataSource )
{
mUseEstimatedMetadata = true;
}
mIncludeGeoAttributes = mUri.hasParam( "includegeoattributes" ) ? mUri.param( "includegeoattributes" ) == "true" : false;

QgsOracleConn *conn = connectionRO();
Expand Down Expand Up @@ -2566,6 +2570,13 @@ bool QgsOracleProvider::getGeometryDetails()
return true;
}

// Trust the datasource config means that we used requested geometry type and srid
if ( mReadFlags & QgsDataProvider::FlagTrustDataSource )
{
mDetectedGeomType = mRequestedGeomType;
return true;
}

QString ownerName = mOwnerName;
QString tableName = mTableName;
QString geomCol = mGeometryColumn;
Expand Down
65 changes: 63 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -122,17 +122,22 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri, const ProviderOpti
mRequestedSrid = mUri.srid();
mRequestedGeomType = mUri.wkbType();

if ( mUri.hasParam( QStringLiteral( "checkPrimaryKeyUnicity" ) ) )
const QString checkUnicityKey { QStringLiteral( "checkPrimaryKeyUnicity" ) };
if ( mUri.hasParam( checkUnicityKey ) )
{

if ( mUri.param( QStringLiteral( "checkPrimaryKeyUnicity" ) ).compare( QLatin1String( "0" ) ) == 0 )
if ( mUri.param( checkUnicityKey ).compare( QLatin1String( "0" ) ) == 0 )
{
mCheckPrimaryKeyUnicity = false;
}
else
{
mCheckPrimaryKeyUnicity = true;
}
if ( mReadFlags & QgsDataProvider::FlagTrustDataSource )
{
mCheckPrimaryKeyUnicity = false;
}
}

if ( mSchemaName.isEmpty() && mTableName.startsWith( '(' ) && mTableName.endsWith( ')' ) )
Expand All @@ -157,6 +162,10 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri, const ProviderOpti
}

mUseEstimatedMetadata = mUri.useEstimatedMetadata();
if ( mReadFlags & QgsDataProvider::FlagTrustDataSource )
{
mUseEstimatedMetadata = true;
}
mSelectAtIdDisabled = mUri.selectAtIdDisabled();

QgsDebugMsgLevel( QStringLiteral( "Connection info is %1" ).arg( mUri.connectionInfo( false ) ), 2 );
Expand Down Expand Up @@ -3735,6 +3744,58 @@ bool QgsPostgresProvider::getGeometryDetails()
QString geomCol = mGeometryColumn;
QString geomColType;

// Trust the datasource config means that we used requested geometry type and srid
// We only need to get the spatial column type
if ( ( mReadFlags & QgsDataProvider::FlagTrustDataSource ) &&
mRequestedGeomType != QgsWkbTypes::Unknown &&
!mRequestedSrid.isEmpty() )
{
if ( mIsQuery )
{
sql = QStringLiteral(
"SELECT t.typname FROM pg_type t inner join (SELECT pg_typeof(%1) typeof FROM %2 LIMIT 1) g ON oid = g.typeof"
).arg( quotedIdentifier( geomCol ), mQuery );
}
else
{
sql = QStringLiteral(
"SELECT t.typname FROM pg_type t inner join (SELECT pg_typeof(%1) typeof FROM %2.%3 LIMIT 1) g ON oid = g.typeof"
).arg( quotedIdentifier( geomCol ),
quotedValue( schemaName ),
quotedValue( tableName ) );
}
QgsDebugMsgLevel( QStringLiteral( "Getting the spatial column type: %1" ).arg( sql ), 2 );

result = connectionRO()->PQexec( sql );
if ( PGRES_TUPLES_OK == result.PQresultStatus() )
{
geomColType = result.PQgetvalue( 0, 0 );

// Get spatial col type
if ( geomColType == QLatin1String( "geometry" ) )
mSpatialColType = SctGeometry;
else if ( geomColType == QLatin1String( "geography" ) )
mSpatialColType = SctGeography;
else if ( geomColType == QLatin1String( "topogeometry" ) )
mSpatialColType = SctTopoGeometry;
else if ( geomColType == QLatin1String( "pcpatch" ) )
mSpatialColType = SctPcPatch;
else
mSpatialColType = SctNone;

// Use requested geometry type and srid
mDetectedGeomType = mRequestedGeomType;
mDetectedSrid = mRequestedSrid;
mValid = true;
return true;
}
else
{
mValid = false;
return false;
}
}

if ( mIsQuery )
{
sql = QStringLiteral( "SELECT %1 FROM %2 LIMIT 0" ).arg( quotedIdentifier( mGeometryColumn ), mQuery );
Expand Down

0 comments on commit 760347c

Please sign in to comment.