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 GPKG and Spatialite UNIQUE and NOT NULL constraints detection #36802

Merged
merged 6 commits into from
May 30, 2020

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented May 28, 2020

Fixes #36468 and unreported NOT NULL
detection failure in spatialite.

Also adds tests for both in the main testsuite for providers.

Unique detection is being implemented in GDAL too with the same logic and more tests, so this is meant to be partly (for OGR) a temporary solution until GDAL implementation is ready, for spatialite it will remain a valid patch because the native provider does not use GDAL.

@elpaso elpaso added Data Provider Related to specific vector, raster or mesh data providers Bug Either a bug report, or a bug fix. Let's hope for the latter! labels May 28, 2020
@github-actions github-actions bot added this to the 3.14.0 milestone May 28, 2020
@@ -1099,6 +1103,22 @@ void QgsOgrProvider::loadFields()
mFirstFieldIsFid = !fidColumn.isEmpty() &&
fdef.GetFieldIndex( fidColumn ) < 0;

// This is a temporary solution until GDAL Unique support is available
QSet<QString> uniqueFieldNames;
Copy link
Contributor

Choose a reason for hiding this comment

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

are you considering to have a GDAL >= 3.2 path that uses the GDAL API (in this PR or a follow-up once OSGeo/gdal#2622 is merged) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rouault yes, that was the idea.
But I'm now thinking to remove the OGR part from this PR leaving spatialite (because it fixes another bug about NOT NULL) and wait for GDAL API to be ready, there is failing test about number of connections, https://travis-ci.org/github/qgis/QGIS/builds/692197527#L2175
I don't get exactly why it happens, because the solution in the patch does actually open an additional connection but it should be closed immediately thanks to the sqlite3_database_unique_ptr.

Anyway I've already spent faaaaar too much time on this issue and I don't think I can spend more.

I also tried a different implementation where I pass the sqlite3 handle to the uniqueValues method (and make it static) but it seems there is no way to retrieve it from the OGR layer.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes the failure is mysterious... And there is indeed no way to get the sqlite3 handle from a GDALDataset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rouault I've checked and the sqlite3_database_unique_ptr deleter actually called sqlite3_close_v2, how do you feel about changing the test expected value?

I can add a note that it is a temporary solution until we use the GDAL implementation.

I'd really like to avoid putting yet another sql parser inside the OGR provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

how do you feel about changing the test expected value?

I can add a note that it is a temporary solution until we use the GDAL implementation.

yeah, we can do that. Odd though

@elpaso elpaso force-pushed the bugfix-36468-unique-tests branch 2 times, most recently from 6611d63 to a00195f Compare May 29, 2020 09:27
Fixes qgis#36468 and un reported NOT NULL
detection failure in spatialite.
This is a temporary solution for OGR because we expect
to use the native GDAL implementation in GDAL 3.2.

For now a new method QgsSqliteUtils::uniqueFields
used by spatialite and OGR/GPKG is used to detect
UNIQUE constraints on single fields.
@elpaso elpaso force-pushed the bugfix-36468-unique-tests branch from a00195f to 1bdaf15 Compare May 29, 2020 12:00
@elpaso elpaso closed this May 29, 2020
@elpaso elpaso reopened this May 29, 2020
@elpaso elpaso merged commit 51be73e into qgis:master May 30, 2020
@elpaso elpaso deleted the bugfix-36468-unique-tests branch May 30, 2020 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GPKG (and spatialite) DB-level unique constraints are not supported by OGR (and spatialite) provider
2 participants