Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
oracle provider: fix subquery support (fixes #10694)
  • Loading branch information
jef-n committed Jun 24, 2014
1 parent abcca5a commit 10d0ac0
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -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() ) ) );
Expand Down Expand Up @@ -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" )
Expand Down Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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" ) );
}
Expand Down Expand Up @@ -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" ) );
}
Expand Down Expand Up @@ -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" )
Expand Down

0 comments on commit 10d0ac0

Please sign in to comment.