Skip to content

Commit

Permalink
oracle provider: allow switching workspaces through property
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 16, 2016
1 parent 1eb8fe5 commit 4e8357f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/providers/oracle/qgsoracleprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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 );
Expand Down Expand Up @@ -2325,7 +2354,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() )
Expand Down
11 changes: 11 additions & 0 deletions src/providers/oracle/qgsoracleprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum QgsOraclePrimaryKeyType
class QgsOracleProvider : public QgsVectorDataProvider
{
Q_OBJECT
Q_PROPERTY( QString workspace READ getWorkspace WRITE setWorkspace )

public:

Expand Down Expand Up @@ -281,6 +282,16 @@ class QgsOracleProvider : public QgsVectorDataProvider
*/
virtual bool isSaveAndLoadStyleToDBSupported() 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;
Expand Down

0 comments on commit 4e8357f

Please sign in to comment.