Skip to content
Permalink
Browse files

oracle provider:

* retrieve comment of materialized views (implements #10063)
* use detected srid (fixes #10091)
* initialize mUseEstimatedMetadata (fixes #10092)
* also consider username in temporary saved credentials (fixes #10093)
  • Loading branch information
jef-n committed Apr 19, 2014
1 parent 8fe53c0 commit 3978bff44709dd251f1739b441a5934f06653011
Showing with 70 additions and 23 deletions.
  1. +57 −19 src/providers/oracle/qgsoracleconn.cpp
  2. +13 −4 src/providers/oracle/qgsoracleprovider.cpp
@@ -76,14 +76,21 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri )
QString username = uri.username();
QString password = uri.password();

QString realm( database );
if ( !username.isEmpty() )
realm.prepend( username + "@" );

while ( !mDatabase.open() )
{
bool ok = QgsCredentials::instance()->get( database, username, password, mDatabase.lastError().text() );
bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() );
if ( !ok )
break;

if ( !username.isEmpty() )
{
uri.setUsername( username );
realm = username + "@" + database;
}

if ( !password.isEmpty() )
uri.setPassword( password );
@@ -94,7 +101,7 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri )
}

if ( mDatabase.isOpen() )
QgsCredentials::instance()->put( database, username, password );
QgsCredentials::instance()->put( realm, username, password );
}

if ( !mDatabase.isOpen() )
@@ -377,12 +384,35 @@ void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, b
where = layerProperty.sql;
}

QGis::WkbType detectedType = layerProperty.types.value( 0, QGis::WKBUnknown );
int detectedSrid = layerProperty.srids.value( 0, -1 );

Q_ASSERT( detectedType == QGis::WKBUnknown || detectedSrid <= 0 );

QSqlQuery qry( mDatabase );
QString sql = QString( "SELECT DISTINCT t.%1.SDO_GTYPE,t.%1.SDO_SRID FROM %2 t WHERE NOT t.%1 IS NULL%3" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( where.isEmpty() ? "" : QString( " AND (%1)" ).arg( where ) );
if ( !exec( qry, sql ) )
int idx = 0;
QString sql = "SELECT DISTINCT ";
if ( detectedType == QGis::WKBUnknown )
{
sql += "t.%1.SDO_GTYPE";
if ( detectedSrid <= 0 )
{
sql += ",";
idx = 1;
}
}

if ( detectedSrid <= 0 )
{
sql += "t.%1.SDO_SRID";
}

sql += " FROM %2 t WHERE NOT t.%1 IS NULL%3";

if ( !exec( qry, sql
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( where.isEmpty() ? "" : QString( " AND (%1)" ).arg( where ) ) ) )
{
QgsMessageLog::logMessage( tr( "SQL:%1\nerror:%2\n" )
.arg( qry.lastQuery() )
@@ -397,19 +427,28 @@ void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, b
QSet<int> srids;
while ( qry.next() )
{
QGis::WkbType type = wkbTypeFromDatabase( qry.value( 0 ).toInt() );
if ( type == QGis::WKBUnknown )
if ( detectedType == QGis::WKBUnknown )
{
QgsMessageLog::logMessage( tr( "Unsupported geometry type %1 in %2.%3.%4 ignored" )
.arg( qry.value( 0 ).toInt() )
.arg( layerProperty.ownerName ).arg( layerProperty.tableName ).arg( layerProperty.geometryColName ),
tr( "Oracle" ) );
continue;
QGis::WkbType type = wkbTypeFromDatabase( qry.value( 0 ).toInt() );
if ( type == QGis::WKBUnknown )
{
QgsMessageLog::logMessage( tr( "Unsupported geometry type %1 in %2.%3.%4 ignored" )
.arg( qry.value( 0 ).toInt() )
.arg( layerProperty.ownerName ).arg( layerProperty.tableName ).arg( layerProperty.geometryColName ),
tr( "Oracle" ) );
continue;
}
QgsDebugMsg( QString( "add type %1" ).arg( type ) );
layerProperty.types << type;
}
else
{
layerProperty.types << detectedType;
}
QgsDebugMsg( QString( "add type %1" ).arg( type ) );
layerProperty.types << type;
layerProperty.srids << ( qry.value( 1 ).isNull() ? 0 : qry.value( 1 ).toInt() );
srids << ( qry.value( 1 ).isNull() ? 0 : qry.value( 1 ).toInt() );

int srid = detectedSrid != -1 ? detectedSrid : ( qry.value( idx ).isNull() ? -1 : qry.value( idx ).toInt() );
layerProperty.srids << srid;
srids << srid;
}

qry.finish();
@@ -466,7 +505,6 @@ QString QgsOracleConn::databaseTypeFilter( QString alias, QString geomCol, QGis:
return QString::null;
}


QGis::WkbType QgsOracleConn::wkbTypeFromDatabase( int gtype )
{
QgsDebugMsg( QString( "entering %1" ).arg( gtype ) );
@@ -66,6 +66,7 @@ QgsOracleProvider::QgsOracleProvider( QString const & uri )
mSqlWhereClause = mUri.sql();
mSrid = mUri.srid().toInt();
mRequestedGeomType = mUri.wkbType();
mUseEstimatedMetadata = mUri.useEstimatedMetadata();

mConnection = QgsOracleConn::connectDb( mUri.connectionInfo() );
if ( !mConnection )
@@ -545,6 +546,13 @@ bool QgsOracleProvider::loadFields()
{
if ( qry.next() )
mDataComment = qry.value( 0 ).toString();
else if ( exec( qry, QString( "SELECT comments FROM all_mview_comments WHERE owner=%1 AND mview_name=%2" )
.arg( quotedValue( mOwnerName ) )
.arg( quotedValue( mTableName ) ) ) )
{
if ( qry.next() )
mDataComment = qry.value( 0 ).toString();
}
}
else
{
@@ -2133,12 +2141,14 @@ bool QgsOracleProvider::getGeometryDetails()
}
}

if ( detectedType == QGis::WKBUnknown )
if ( detectedType == QGis::WKBUnknown || detectedSrid <= 0 )
{
QgsOracleLayerProperty layerProperty;
layerProperty.ownerName = ownerName;
layerProperty.tableName = tableName;
layerProperty.geometryColName = mGeometryColumn;
layerProperty.types << detectedType;
layerProperty.srids << detectedSrid;

QString delim = "";

@@ -2959,9 +2969,6 @@ QGISEXTERN bool deleteLayer( const QString& uri, QString& errCause )
return true;
}

// vim: set sw=2 :


// ----------


@@ -3014,3 +3021,5 @@ QVariant QgsOracleSharedData::lookupKey( QgsFeatureId featureId )
return it.value();
return QVariant();
}

// vim: set sw=2 :

0 comments on commit 3978bff

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