Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-39957

QSqlDatabase should be fixed to be usable in multithreaded environment

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.8.0 FF
    • None
    • SQL Support
    • None
    • b4c63b89d (dev)

    Description

      The current design of QSqlDatabase is hostile to multithreading (which is quite common these days). For one, the public API forces anyone to add and remove databases to/from a global table, yet each thread can only access database objects created in its own, rendering the global table pointless. For two, the fact that a database objects cannot be moved poses serious design problems. No longer can QSqlDatabase be created at construction time; instead, a special init() function must be provided if a QObject is intended to live in another thread. In addition, any QObject has a non-overridable moveToThread() method, yet some of them (referring to any QSqlDatabase) must have thread affinity fixed or risk undefined behavior. I believe this violates Liskov substitution principle and thus pokes a hole in the objected oriented design.

      To fix this, the global table should become optional. QSqlDatabase also must be allowed to move to another thread; or as what other database library do, be able to be accessed in any thread provided that it is not accessed simultaneously.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            netheril96 Siyuan Ren
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes