oracle provider: allow switching workspaces through property

(cherry picked from commit 2dc448dfb8c568c20e69fc9e3955e5df63d9a880)
This commit is contained in:
Juergen E. Fischer 2016-11-16 23:48:59 +01:00
parent 33ee514b5d
commit 6638569074
2 changed files with 41 additions and 1 deletions

View File

@ -207,6 +207,35 @@ QgsOracleProvider::~QgsOracleProvider()
disconnectDb();
}
QString QgsOracleProvider::getWorkspace() const
{
return mUri.param( "dbworkspace" );
}
void QgsOracleProvider::setWorkspace( const QString &workspace )
{
QgsDataSourceUri prevUri( mUri );
disconnectDb();
if ( workspace.isEmpty() )
mUri.removeParam( "dbworkspace" );
else
mUri.setParam( "dbworkspace", workspace );
mConnection = QgsOracleConn::connectDb( mUri );
if ( !mConnection )
{
mUri = prevUri;
QgsDebugMsg( QString( "restoring previous uri:%1" ).arg( mUri.uri() ) );
mConnection = QgsOracleConn::connectDb( mUri );
}
else
{
setDataSourceUri( mUri.uri() );
}
}
QgsAbstractFeatureSource *QgsOracleProvider::featureSource() const
{
return new QgsOracleFeatureSource( this );
@ -2381,7 +2410,7 @@ bool QgsOracleProvider::getGeometryDetails()
}
if ( exec( qry, QString( mUseEstimatedMetadata
? "SELECT DISTINCT gtype FROM (SELECT t.%1.sdo_gtype AS gtype FROM %2 t WHERE t.%1 IS NOT NULL AND rownum<1000) WHERE rownum<=2"
? "SELECT DISTINCT gtype FROM (SELECT t.%1.sdo_gtype AS gtype FROM %2 t WHERE t.%1 IS NOT NULL AND rownum<100) WHERE rownum<=2"
: "SELECT DISTINCT t.%1.sdo_gtype FROM %2 t WHERE t.%1 IS NOT NULL AND rownum<=2" ).arg( quotedIdentifier( geomCol ) ).arg( mQuery ) ) )
{
if ( qry.next() )

View File

@ -56,6 +56,7 @@ enum QgsOraclePrimaryKeyType
class QgsOracleProvider : public QgsVectorDataProvider
{
Q_OBJECT
Q_PROPERTY( QString workspace READ getWorkspace WRITE setWorkspace )
public:
@ -283,6 +284,16 @@ class QgsOracleProvider : public QgsVectorDataProvider
*/
virtual bool isSaveAndLoadStyleToDBSupported() const override { return true; }
/**
* Switch to oracle workspace
*/
void setWorkspace( const QString &workspace );
/**
* Retrieve oracle workspace name
*/
QString getWorkspace() const;
private:
QString whereClause( QgsFeatureId featureId ) const;
QString pkParamWhereClause() const;