converting from mySQL to SQlite with QSqlTableModel
-
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!
-
Hi,
And what is your question exactly ?
-
How did you do the migration ?
-
- subclass
QSQLiteResult
and reimplementbindValue
to convert dates to strings anddata()
to convert strings to dates. - create a custom driver squbclassing
QSQLiteDriver
and reimplementingcreateResult()
to return an instance of the subclass created above.
- subclass
-
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.