Fix "database source is already in use" error #924
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: tests fail for me without #925
Fixes #829
Fixes #871
Fixes #910
When using
clonewith--followand--filter, the code opens the filters SQLite database then tries to attach the source database multiple times. This fails because the source database has already been attached with the same name.This code queries
pragma_database_listto see if a database has already been attached with the same name. If so, it skips trying to attach it again and returns success.It's been a while since I've written C, and this is probably my first time using SQLite, so please let me know if I should have gone about this another way.
I considered other approaches but decided on this:
This seems destructive/heavy handed and might cause race conditions or something
The response code for this error isn't unique, so we'd need to actually parse the error message, which seems fragile.
catalog_attachmultiple timesThis seems like a potentially good solution, but it felt like
catalog_attachshould be idempotent (or whatever the right term is) and not fail when called multiple times.