Skip to content
Permalink
Browse files

[FEATURE] oracle provider: basic support for Oracle Workspace Manager

(switches to a given workspace on connect)
  • Loading branch information...
jef-n committed Mar 21, 2016
1 parent fb9d60d commit d161612bd216d36dc23ab2307636cf1bc0a36192
@@ -496,6 +496,7 @@ QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringLis
el.setAttribute( "port", settings.value( path + "/port", "" ).toString() );
el.setAttribute( "database", settings.value( path + "/database", "" ).toString() );
el.setAttribute( "dboptions", settings.value( path + "/dboptions", "" ).toString() );
el.setAttribute( "dbworkspace", settings.value( path + "/dbworkspace", "" ).toString() );
el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() );
el.setAttribute( "userTablesOnly", settings.value( path + "/userTablesOnly", "0" ).toString() );
el.setAttribute( "geometryColumnsOnly", settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
@@ -940,6 +941,7 @@ void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc,
settings.setValue( "/port", child.attribute( "port" ) );
settings.setValue( "/database", child.attribute( "database" ) );
settings.setValue( "/dboptions", child.attribute( "dboptions" ) );
settings.setValue( "/dbworkspace", child.attribute( "dbworkspace" ) );
settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) );
settings.setValue( "/userTablesOnly", child.attribute( "userTablesOnly" ) );
settings.setValue( "/geometryColumnsOnly", child.attribute( "geometryColumnsOnly" ) );
@@ -41,10 +41,14 @@ void QgsOracleColumnTypeThread::run()
mStopped = false;

QgsDataSourceURI uri = QgsOracleConn::connUri( mName );
QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( uri.connectionInfo() );
QString conninfo = uri.connectionInfo();
if ( uri.hasParam( "dbworkspace" ) )
conninfo += " dbworkspace=" + uri.param( "dbworkspace" );

QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( conninfo );
if ( !conn )
{
QgsDebugMsg( "Connection failed - " + uri.connectionInfo() );
QgsDebugMsg( "Connection failed - " + conninfo );
mStopped = true;
return;
}
@@ -34,6 +34,8 @@ const int QgsOracleConn::sGeomTypeSelectLimit = 100;
QgsOracleConn *QgsOracleConn::connectDb( QgsDataSourceURI uri )
{
QString conninfo = uri.connectionInfo();
if ( uri.hasParam( "dbworkspace" ) )
conninfo += " dbworkspace=" + uri.param( "dbworkspace" );

if ( sConnections.contains( conninfo ) )
{
@@ -68,6 +70,7 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri )
mDatabase = QSqlDatabase::addDatabase( "QOCISPATIAL", QString( "oracle%1" ).arg( snConnections++ ) );
mDatabase.setDatabaseName( database );
QString options = uri.hasParam( "dboptions" ) ? uri.param( "dboptions" ) : "OCI_ATTR_PREFETCH_ROWS=1000";
QString workspace = uri.hasParam( "dbworkspace" ) ? uri.param( "dbworkspace" ) : QString::null;
mDatabase.setConnectOptions( options );
mDatabase.setUserName( uri.username() );
mDatabase.setPassword( uri.password() );
@@ -118,6 +121,19 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri )
mRef = 0;
return;
}

if ( !workspace.isNull() )
{
QSqlQuery qry( mDatabase );

if ( !qry.exec( QString( "BEGIN\nDBMS_WM.GotoWorkspace(%1);\nEND;" ).arg( quotedValue( workspace ) ) ) )
{
mDatabase.close();
QgsMessageLog::logMessage( tr( "Could not with to workspace %1 [%2]" ).arg( workspace, qry.lastError().databaseText() ), tr( "Oracle" ) );
mRef = 0;
return;
}
}
}

QgsOracleConn::~QgsOracleConn()
@@ -713,6 +729,10 @@ QgsDataSourceURI QgsOracleConn::connUri( QString theConnName )
{
uri.setParam( "dboptions", settings.value( key + "/dboptions" ).toString() );
}
if ( !settings.value( key + "/dbworkspace" ).toString().isEmpty() )
{
uri.setParam( "dbworkspace", settings.value( key + "/dbworkspace" ).toString() );
}

return uri;
}
@@ -46,6 +46,7 @@ QgsOracleNewConnection::QgsOracleNewConnection( QWidget *parent, const QString&
}
txtPort->setText( port );
txtOptions->setText( settings.value( key + "/dboptions" ).toString() );
txtWorkspace->setText( settings.value( key + "/dbworkspace" ).toString() );
cb_userTablesOnly->setChecked( settings.value( key + "/userTablesOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
@@ -128,6 +129,7 @@ void QgsOracleNewConnection::accept()
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/dboptions", txtOptions->text() );
settings.setValue( baseKey + "/dbworkspace", txtWorkspace->text() );

QDialog::accept();
}
@@ -138,6 +140,8 @@ void QgsOracleNewConnection::on_btnConnect_clicked()
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
if ( !txtOptions->text().isEmpty() )
uri.setParam( "dboptions", txtOptions->text() );
if ( !txtWorkspace->text().isEmpty() )
uri.setParam( "dbworkspace", txtWorkspace->text() );

QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( uri.connectionInfo() );

@@ -235,6 +235,23 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QLineEdit" name="txtWorkspace">
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="TextLabel3_4">
<property name="text">
<string>Workspace</string>
</property>
<property name="buddy">
<cstring>txtPassword</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -249,6 +266,7 @@
<tabstop>txtUsername</tabstop>
<tabstop>txtPassword</tabstop>
<tabstop>txtOptions</tabstop>
<tabstop>txtWorkspace</tabstop>
<tabstop>chkStoreUsername</tabstop>
<tabstop>chkStorePassword</tabstop>
<tabstop>btnConnect</tabstop>

0 comments on commit d161612

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