Skip to content
Permalink
Browse files

Postgres and Oracle: Use trust datasource config flag

  • Loading branch information
rldhont committed Sep 9, 2020
1 parent 45e9ecb commit 760347c3b6a95129db677a1915d90190779eaad5
Showing with 74 additions and 2 deletions.
  1. +11 −0 src/providers/oracle/qgsoracleprovider.cpp
  2. +63 −2 src/providers/postgres/qgspostgresprovider.cpp
@@ -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();
@@ -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;
@@ -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( ')' ) )
@@ -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 );
@@ -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 );

0 comments on commit 760347c

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