Qml SQL offline storage

Source: Internet
Author: User

 

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()     } }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.