-
Notifications
You must be signed in to change notification settings - Fork 94
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
Refactor DB code with Database(Holder|Helper) #245
Open
vedgy
wants to merge
10
commits into
YACReader:develop
Choose a base branch
from
vedgy:db-refactoring
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Including only what is used should reduce compilation time. The added includes were necessary to make the respective translation units compile after a thorough cleanup of data_base_management.h includes. This is how the complete include and forward-declaration sections should look like in data_base_management.h: '#'include <QThread> // (prevent '#' from starting a git comment line) class QSqlDatabase; class QSqlQuery; class QSqlRecord; class QString; class QStringList; Subsequently I had to partly restore the unnecessary includes by moving them from data_base_management.cpp into the header due to the huge number of compilation errors I am not prepared to deal with right now.
Even an implicitly shared class is cheaper to pass by reference than by value, as evidenced by Qt APIs themselves.
All other similar updating functions take db as the last argument.
Take QString arguments by value only if they are unconditionally moved from. Fix typos in DBHelper::reassignOrderTo* member function names.
These classes will allow to improve exception and early-return safety as well as simplify code that calls QSqlDatabase::removeDatabase().
The returned value is always the same and is not used by the caller. Remove unused variables from this function.
DatabaseHolder is preferable to DatabaseHelper here for these reasons: 1. DataBaseManagement uses DBHelper only once, so DatabaseHelper's advantage is tiny here. 2. DataBaseManagement uses the wrapped QSqlDatabase object a lot. DatabaseHolder's operators make these uses convenient and less verbose. 3. In YACReader code a QSqlDatabase object is almost always obtained via DataBaseManagement::loadDatabase(). DatabaseHelper provides only one constructor that adds a QSqlDatabase connection in this way to prevent usage mistakes. By contrast, DataBaseManagement always adds QSqlDatabase connections in other ways, so DatabaseHelper cannot be used as is.
This change eliminates the following warning from the output of YACReaderLibrary built in Debug mode: QSqlDatabasePrivate::addDatabase: duplicate connection name '/path/to/.yacreaderlibrary<thread id>', old connection removed.
This change shows how code is simplified by using DatabaseHelper. It also allows to test DatabaseHelper. Eventually DatabaseHelper (or rarely DatabaseHolder) should replace almost all explicit QSqlDatabase::removeDatabase() calls.
luisangelsm
force-pushed
the
develop
branch
from
September 15, 2024 13:50
6ccfc51
to
63fcde8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See the commit messages for details.