Skip to content

Commit 4e8357f

Browse files
committedNov 16, 2016
oracle provider: allow switching workspaces through property
1 parent 1eb8fe5 commit 4e8357f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
 

‎src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,35 @@ QgsOracleProvider::~QgsOracleProvider()
209209
disconnectDb();
210210
}
211211

212+
QString QgsOracleProvider::getWorkspace() const
213+
{
214+
return mUri.param( "dbworkspace" );
215+
}
216+
217+
void QgsOracleProvider::setWorkspace( const QString &workspace )
218+
{
219+
QgsDataSourceURI prevUri( mUri );
220+
221+
disconnectDb();
222+
223+
if ( workspace.isEmpty() )
224+
mUri.removeParam( "dbworkspace" );
225+
else
226+
mUri.setParam( "dbworkspace", workspace );
227+
228+
mConnection = QgsOracleConn::connectDb( mUri );
229+
if ( !mConnection )
230+
{
231+
mUri = prevUri;
232+
QgsDebugMsg( QString( "restoring previous uri:%1" ).arg( mUri.uri() ) );
233+
mConnection = QgsOracleConn::connectDb( mUri );
234+
}
235+
else
236+
{
237+
setDataSourceUri( mUri.uri() );
238+
}
239+
}
240+
212241
QgsAbstractFeatureSource *QgsOracleProvider::featureSource() const
213242
{
214243
return new QgsOracleFeatureSource( this );
@@ -2325,7 +2354,7 @@ bool QgsOracleProvider::getGeometryDetails()
23252354
}
23262355

23272356
if ( exec( qry, QString( mUseEstimatedMetadata
2328-
? "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"
2357+
? "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"
23292358
: "SELECT DISTINCT t.%1.sdo_gtype FROM %2 t WHERE t.%1 IS NOT NULL AND rownum<=2" ).arg( quotedIdentifier( geomCol ) ).arg( mQuery ) ) )
23302359
{
23312360
if ( qry.next() )

‎src/providers/oracle/qgsoracleprovider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum QgsOraclePrimaryKeyType
5454
class QgsOracleProvider : public QgsVectorDataProvider
5555
{
5656
Q_OBJECT
57+
Q_PROPERTY( QString workspace READ getWorkspace WRITE setWorkspace )
5758

5859
public:
5960

@@ -281,6 +282,16 @@ class QgsOracleProvider : public QgsVectorDataProvider
281282
*/
282283
virtual bool isSaveAndLoadStyleToDBSupported() override { return true; }
283284

285+
/**
286+
* Switch to oracle workspace
287+
*/
288+
void setWorkspace( const QString &workspace );
289+
290+
/**
291+
* Retrieve oracle workspace name
292+
*/
293+
QString getWorkspace() const;
294+
284295
private:
285296
QString whereClause( QgsFeatureId featureId ) const;
286297
QString pkParamWhereClause() const;

0 commit comments

Comments
 (0)
Please sign in to comment.