Skip to content

Commit 10d0ac0

Browse files
committedJun 24, 2014
oracle provider: fix subquery support (fixes #10694)
1 parent abcca5a commit 10d0ac0

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed
 

‎src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ bool QgsOracleProvider::loadFields()
720720
if ( field.name() == mGeometryColumn )
721721
continue;
722722

723-
if ( !types.contains( field.name() ) )
723+
if ( !mIsQuery && !types.contains( field.name() ) )
724724
continue;
725725

726726
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()
816816
return false;
817817
}
818818

819-
// get a new alias for the subquery
820-
int index = 0;
821-
QString alias;
822-
QRegExp regex;
823-
do
824-
{
825-
alias = QString( "subQuery_%1" ).arg( QString::number( index++ ) );
826-
QString pattern = QString( "(\\\"?)%1\\1" ).arg( QRegExp::escape( alias ) );
827-
regex.setPattern( pattern );
828-
regex.setCaseSensitivity( Qt::CaseInsensitive );
829-
}
830-
while ( mQuery.contains( regex ) );
831-
832-
// convert the custom query into a subquery
833-
mQuery = QString( "%1 AS %2" )
834-
.arg( mQuery )
835-
.arg( quotedIdentifier( alias ) );
836-
837819
if ( !exec( qry, QString( "SELECT * FROM %1 WHERE 1=0" ).arg( mQuery ) ) )
838820
{
839821
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()
953935
QString primaryKey = mUri.keyColumn();
954936
int idx = fieldNameIndex( mUri.keyColumn() );
955937

956-
if ( idx >= 0 && ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) )
938+
if ( idx >= 0 && (
939+
mAttributeFields[idx].type() == QVariant::Int ||
940+
mAttributeFields[idx].type() == QVariant::LongLong ||
941+
mAttributeFields[idx].type() == QVariant::Double
942+
) )
957943
{
958944
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
959945
{
@@ -1505,7 +1491,7 @@ bool QgsOracleProvider::addAttributes( const QList<QgsField> &attributes )
15051491
returnvalue = false;
15061492
}
15071493

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

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

2085+
if ( mIsQuery )
2086+
{
2087+
detectedSrid = mSrid;
2088+
detectedType = mRequestedGeomType;
2089+
}
2090+
20992091
if ( !ownerName.isEmpty() )
21002092
{
21012093
if ( exec( qry, QString( "SELECT srid FROM mdsys.all_sdo_geom_metadata WHERE owner=%1 AND table_name=%2 AND column_name=%3" )

0 commit comments

Comments
 (0)
Please sign in to comment.