Skip to content
Permalink
Browse files

oracle provider: fix subquery support (fixes #10694)

  • Loading branch information
jef-n committed Jun 24, 2014
1 parent abcca5a commit 10d0ac04bf11fbf6ca2a0f46771098149d616251
Showing with 14 additions and 22 deletions.
  1. +14 −22 src/providers/oracle/qgsoracleprovider.cpp
@@ -720,7 +720,7 @@ bool QgsOracleProvider::loadFields()
if ( field.name() == mGeometryColumn )
continue;

if ( !types.contains( field.name() ) )
if ( !mIsQuery && !types.contains( field.name() ) )
continue;

mAttributeFields.append( QgsField( field.name(), field.type(), types.value( field.name() ), field.length(), field.precision(), comments.value( field.name() ) ) );
@@ -816,24 +816,6 @@ bool QgsOracleProvider::hasSufficientPermsAndCapabilities()
return false;
}

// get a new alias for the subquery
int index = 0;
QString alias;
QRegExp regex;
do
{
alias = QString( "subQuery_%1" ).arg( QString::number( index++ ) );
QString pattern = QString( "(\\\"?)%1\\1" ).arg( QRegExp::escape( alias ) );
regex.setPattern( pattern );
regex.setCaseSensitivity( Qt::CaseInsensitive );
}
while ( mQuery.contains( regex ) );

// convert the custom query into a subquery
mQuery = QString( "%1 AS %2" )
.arg( mQuery )
.arg( quotedIdentifier( alias ) );

if ( !exec( qry, QString( "SELECT * FROM %1 WHERE 1=0" ).arg( mQuery ) ) )
{
QgsMessageLog::logMessage( tr( "Unable to execute the query.\nThe error message from the database was:\n%1.\nSQL: %2" )
@@ -953,7 +935,11 @@ bool QgsOracleProvider::determinePrimaryKey()
QString primaryKey = mUri.keyColumn();
int idx = fieldNameIndex( mUri.keyColumn() );

if ( idx >= 0 && ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) )
if ( idx >= 0 && (
mAttributeFields[idx].type() == QVariant::Int ||
mAttributeFields[idx].type() == QVariant::LongLong ||
mAttributeFields[idx].type() == QVariant::Double
) )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
@@ -1505,7 +1491,7 @@ bool QgsOracleProvider::addAttributes( const QList<QgsField> &attributes )
returnvalue = false;
}

if( !loadFields() )
if ( !loadFields() )
{
QgsMessageLog::logMessage( tr( "Could not reload fields." ), tr( "Oracle" ) );
}
@@ -1568,7 +1554,7 @@ bool QgsOracleProvider::deleteAttributes( const QgsAttributeIds& ids )
returnvalue = false;
}

if( !loadFields() )
if ( !loadFields() )
{
QgsMessageLog::logMessage( tr( "Could not reload fields." ), tr( "Oracle" ) );
}
@@ -2096,6 +2082,12 @@ bool QgsOracleProvider::getGeometryDetails()
QGis::WkbType detectedType = QGis::WKBUnknown;
mSpatialIndex = QString::null;

if ( mIsQuery )
{
detectedSrid = mSrid;
detectedType = mRequestedGeomType;
}

if ( !ownerName.isEmpty() )
{
if ( exec( qry, QString( "SELECT srid FROM mdsys.all_sdo_geom_metadata WHERE owner=%1 AND table_name=%2 AND column_name=%3" )

0 comments on commit 10d0ac0

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