Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. converting from mySQL to SQlite with QSqlTableModel

converting from mySQL to SQlite with QSqlTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
mysqlsqliteqsqltablemodelpyqt5
7 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johnny78
    wrote on 8 Jun 2020, 08:03 last edited by Johnny78 6 Aug 2020, 08:15
    #1

    Hello,

    I would appreciate your help with the following problem:
    I have written an application with pyQt5 that uses a mysql database
    together with QSqlTableModel. I decided to migrate to sqlite and managed
    to migrate the data in the database. But this means that the dates from the
    sqlite database are now QStrings and not QDate as before.
    This makes my code crash, as the code often expects QDate instead of QString.
    Is there an easy way to fix this? Can I somehow make Qt convert the date strings from the sqlite database into a QDate?
    Of course I could go through my code line by line and change it everywhere is wants to have a QDate, but that would be very tedious. Is there a better way?

    thanks for your help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Jun 2020, 08:13 last edited by
      #2

      Hi,

      And what is your question exactly ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Johnny78
        wrote on 8 Jun 2020, 08:17 last edited by
        #3

        Sorry, I made a mistake and left my question empty. Thank you for the prompt response.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Johnny78
          wrote on 8 Jun 2020, 08:46 last edited by
          #4

          just to clarify, database access is handled with Qt5 and not with python. I use QSqlDatabase to register the mySQL and later SQlite databases.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Jun 2020, 11:16 last edited by
            #5

            How did you do the migration ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 8 Jun 2020, 11:30 last edited by VRonin 6 Aug 2020, 13:08
              #6
              • subclass QSQLiteResult and reimplement bindValue to convert dates to strings and data() to convert strings to dates.
              • create a custom driver squbclassing QSQLiteDriver and reimplementing createResult() to return an instance of the subclass created above.

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1
              • J Offline
                J Offline
                Johnny78
                wrote on 8 Jun 2020, 12:11 last edited by
                #7

                I did the migration with mysqldump then I edited the dump file. Then I have the resulting file into sqlite and saved it as database. The date columns are now stored in sqlite as TEXT fields. All done on a linux machine.

                Thank you VRonin for your suggestion. That sounds like a great idea. Can I do this in pyQt5 or do I need to go to C++? I think QSQLiteDriver is a plugin i.e. a shared library. That means I have to do this in C++. Is that right? I wanted to avoid C++ so that my application is more portable. But anyway this solution sounds great.

                Thanks for you answers guys.

                1 Reply Last reply
                0

                2/7

                8 Jun 2020, 08:13

                topic:navigator.unread, 5
                • Login

                • Login or register to search.
                2 out of 7
                • First post
                  2/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved