Use an existing SQLite DB with QML
-
Hi,
I want to be able to browse an existing SQLite database file from the OfflineStorage qml sample.I've ran and noticed that QMLViewer create Db in the directory (windows):
~\Local Settings\Application Data\Nokia\QtQmlViewer\QML\OfflineStorage\Databases
for each data base it creates XXX.sqlite file, XXX.ini file (with openDatabaseSync() parameters), and a XXX directory. Where XXX is something like to "fcc39b3050a2d659cf2c48d5a71fd11d" (headhache ;-)).
I've made this simple test: copy my file (mydb.sqlite) in same DB directory, create the mydb.ini file with "MyDB" as DB name, and create empty mydb directory. Then quit/restart QtCreator (perhaps it hold a db file cross reference table, who now ?)When I try to openDatabaseSync("MyDB", ...) .... then mydb file is not loaded, in place QMLViewer prefer to create en newly DB.
Where is my mistake ?
-
not sure exactly but if you restart the qt creator and run again the qml file again maybe the directory has been changed from “fcc39b3050a2d659cf2c48d5a71fd11d” to another value. did you check to see if another directory has been made?
I think you should create a new QT(not QML) project and use QDeclarativeView to load the qml file and copy your database in you project directory and see if it works. I played a few weeks ago like this and it worked, but I didn't give much importance at that moment.
Hope it helps in any way
-
Thanks for your reply.
QMLViewer create the new DB only once then it always use this one and never my own .... like if there are a database dictionnary file elsewhere (registery?) whereas I was simply thinking QMLViewer load all .ini in this directory to discover existing database.
I'm close to be sure that quit/restart QtCreator have no effect on how QMLViewer handle new database.In other hand, this is my first tests learning and using QML, this is just an evaluation of QtQuick, and I don't want, yet, spend time in C++ compiling. Because I develop somtimes on windows, sometimes on mac OSX.
But if it's the only way to do this ... time to swim ! ;-). -
The file name is a MD5 hash of the database name.
E.g. if your database is named "mydb", if you run Qt.md5("mydb") the result is e04d88072f90f86a07481418b8ff4b6b. Use this to name your .sqlite, .ini and folder in the Databases directory and then openDatabaseSync() will open the existing database correctly.
-
Thanks you blam, that is exactly what i need to go further on my prototype.
As I can see all the directory associated to databases are empty, do you known what is the purpose of those directories ?
-
Looks like the directories are not required. I've filed http://bugreports.qt.nokia.com/browse/QTBUG-15909 so they aren't created in the first place.