Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setSubsetString return value on error #34368

Merged
merged 3 commits into from
Feb 11, 2020

Conversation

uclaros
Copy link
Contributor

@uclaros uclaros commented Feb 8, 2020

Description

QgsOgrProvider::setSubsetString should return false on malformed sql.

Fixes #34259

OGR_L_SetAttributeFilter( layer, encoding->fromUnicode( subsetString ).constData() );
if ( OGR_L_SetAttributeFilter( layer, encoding->fromUnicode( subsetString ).constData() ) != OGRERR_NONE )
{
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to also log an error message if this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QgsOgrProviderUtils::setSubsetString is just a utility method used by QgsOgrProvider::_setSubsetString that handles the error and the logging:

subsetLayerH = QgsOgrProviderUtils::setSubsetString( layer, ds, textEncoding(), theSQL );
}
if ( !subsetLayerH )
{
pushError( tr( "OGR[%1] error %2: %3" ).arg( CPLGetLastErrorType() ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ) );
return false;
}

then
void QgsVectorDataProvider::pushError( const QString &msg ) const
{
QgsDebugMsg( msg );
mErrors << msg;
emit raiseError( msg );
}

So I don't think extra logging is needed. I could add some unit test though, I just need to figure out where!...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good.

Some tests exist already in tests/src/python/test_provider_ogr*.py, you could build on top of that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but shapefile and spatialite tests are in test_provider_shapefile.py and test_provider_spatialite.py, are they not using ogrdataprovider? I think I'll put them on test_provider_ogr.py that is more generic, though currently all tests regarding setSubsetString are in each format's test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind and added the test on test_provider_shapefile.py since most ogr tests are there.

@elpaso elpaso merged commit 79ee761 into qgis:master Feb 11, 2020
@elpaso
Copy link
Contributor

elpaso commented May 22, 2020

@uclaros any chance to see it backported to 3.10 and 3.12? I don't see any potential regression unless there was some code relying on a plain wrong behavior.

@elpaso
Copy link
Contributor

elpaso commented May 22, 2020

sorry, I meant backport to 3.10 only.

uclaros added a commit to uclaros/QGIS that referenced this pull request May 22, 2020
@elpaso
Copy link
Contributor

elpaso commented May 22, 2020

@uclaros thank you!

@uclaros
Copy link
Contributor Author

uclaros commented May 22, 2020

@elpaso You're welcome :)

elpaso added a commit that referenced this pull request May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filter expression error returns true
3 participants