Qml provides the SQL local storage solution. It uses the opendatabasesync () function to provide a local offline storage that can access the SQL database. Generally, I will encapsulate this function in JS funcation.
VaR DB = opendatabasesync (identifier, version, description, estimated_size, callback (db ));
Identifier: identifier
Version: Version Number
Description: Database description
Estimated_size: initial database size
Callback (db): currently "qsqlite"
For example:
VaR DB = opendatabasesync ("qdeclarativeexampledb", "1.0", "The example qml SQL! ", 1000000 );
Open the execution SQL database. The generated database file is in the qdeclarativeengine: offlinestoragepath () path by default,
You can also modify the path of voidsetofflinestoragepath (const qstring & DIR.
In actual mobile apps, mobile phones below s60 3rd fp2 do not support database storage. All models of 3rd fp2 and 5th and Symbian 3 have built-in local databases.
import QtQuick 1.0 Rectangle { color: "white" width: 200 height: 100 Text { text: "?" anchors.horizontalCenter: parent.horizontalCenter function findGreetings() { var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000); db.transaction( function(tx) { // Create the database if it doesn't already exist tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); // Add (another) greeting row tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); // Show all added greetings var rs = tx.executeSql('SELECT * FROM Greeting'); var r = "" for(var i = 0; i < rs.rows.length; i++) { r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "/n" } text = r } ) } Component.onCompleted: findGreetings() } }