Refactor DB code with Database(Holder|Helper)#245
Open
vedgy wants to merge 10 commits intoYACReader:developfrom
Open
Refactor DB code with Database(Holder|Helper)#245vedgy wants to merge 10 commits intoYACReader:developfrom
vedgy wants to merge 10 commits intoYACReader:developfrom
Conversation
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.
6ccfc51 to
63fcde8
Compare
728e9bb to
2cd511f
Compare
5d712af to
c2aa5f6
Compare
This file contains hidden or 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
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.