diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/declarative/sql/README | 7 | ||||
-rw-r--r-- | examples/declarative/sql/hello.qml | 12 |
2 files changed, 16 insertions, 3 deletions
diff --git a/examples/declarative/sql/README b/examples/declarative/sql/README new file mode 100644 index 0000000..a7baab2 --- /dev/null +++ b/examples/declarative/sql/README @@ -0,0 +1,7 @@ +Simple demonstration of HTML5-compatible SQL database interface. +Adds another "hello, world" every time you run it. +Database is stored in: + - %APPDATA%/Nokia/Qt/QML/Databases/ (Windows) + - ~/.local/share/Nokia/Qt/QML/Databases/ (Unix) + - ~/Library/Application Support/Nokia/Qt/QML/Databases/ (Mac OS X) +No quota management. diff --git a/examples/declarative/sql/hello.qml b/examples/declarative/sql/hello.qml index fb6d21c..e43d320 100644 --- a/examples/declarative/sql/hello.qml +++ b/examples/declarative/sql/hello.qml @@ -2,10 +2,9 @@ import Qt 4.6 Text { Script { - function test() + function allGreetings() { var db = openDatabase("QmlExampleDB", "", "The Example QML SQL!", 1000000); - print(db) var r = "" db.transaction(function(tx) { @@ -13,9 +12,16 @@ Text { tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); tx.executeSql('SELECT * FROM Greeting', [], function(tx, rs) { + /* Inefficient HTML5-compatible way for(var i = 0; i < rs.rows.length; i++) { r += rs.rows[i][0] + ", " + rs.rows[i][1] + "\n" } + */ + /* Efficient way: forward only, not "length" query */ + rs.rows.forwardOnly = true; + for(var i = 0; rs.rows[i]; i++) { + r += rs.rows[i][0] + ", " + rs.rows[i][1] + "\n" + } }, function(tx, error) { print("ERROR:", error.message) @@ -26,5 +32,5 @@ Text { return r } } - text: test() + text: allGreetings() } |