Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[Qt] Align database creation behavior with the default implementation - #9516

Merged
tmpsantos merged 2 commits into
masterfrom
tmpsantos-qt_database
Jul 17, 2017
Merged

tmpsantos merged 2 commits into
masterfrom
tmpsantos-qt_database

Conversation

@tmpsantos

Copy link
Copy Markdown
Contributor

Qt doesn't throw a Exception::Code::CANTOPEN when trying to open a database
that doesn't exist without the Create flag.

Another attempt to fix #9108

@tmpsantos
tmpsantos force-pushed the tmpsantos-qt_database branch from dd2b911 to b0eeef8 Compare July 14, 2017 13:59
@jfirebaugh

Copy link
Copy Markdown
Contributor

This is technically a race condition -- the database could exist at the time you call QFile(filename).exists(), but then be removed by some other thread or process before you attempt to connect.

Does the Qt API not provide any way of diagnosing the reason for a failed connection?

@kkaefer kkaefer added the Core The cross-platform C++ core, aka mbgl label Jul 17, 2017
@tmpsantos
tmpsantos force-pushed the tmpsantos-qt_database branch from b0eeef8 to 7b7e864 Compare July 17, 2017 12:14
@tmpsantos

Copy link
Copy Markdown
Contributor Author

Does the Qt API not provide any way of diagnosing the reason for a failed connection?

The problem was exactly that. For database errors, QSqlError::nativeErrorCode() was always returning -1 instead of 14/CANTOPEN.

I'm now working around it by assuming every error when opening the database as CANTOPEN which I think makes sense. This way we don't have the race anymore at the cost of sometimes a less precise debug message.

@tmpsantos
tmpsantos force-pushed the tmpsantos-qt_database branch from 7b7e864 to a9b3020 Compare July 17, 2017 12:18
@tmpsantos tmpsantos added the Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL label Jul 17, 2017
Qt doesn't throw a Exception::Code::CANTOPEN when trying to open
a database that doesn't exist without the Create flag.
Make sure all the implementations, currently Qt and Default, throw
an exception with error code CANTOPEN when opening a database that
doesn't exist without the CREATE flag.
@tmpsantos
tmpsantos force-pushed the tmpsantos-qt_database branch from a9b3020 to 7de08f3 Compare July 17, 2017 13:18
@tmpsantos
tmpsantos merged commit 544d875 into master Jul 17, 2017
@tmpsantos
tmpsantos deleted the tmpsantos-qt_database branch July 17, 2017 13:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Qt] "database is locked" when opening the same db in different threads

4 participants