diff options
author | Nico Vertriest <nico.vertriest@theqtcompany.com> | 2016-10-18 14:07:20 +0200 |
---|---|---|
committer | Nico Vertriest <nico.vertriest@theqtcompany.com> | 2016-10-26 11:24:18 +0000 |
commit | 621c5b2b260d63fef7190c133f7384b8ccb93307 (patch) | |
tree | 1e98c2ee4a40c3c07a086b62b5e86553ce957318 | |
parent | 210a4584b87add2061f805ae50eb5079eec48cf5 (diff) |
Doc: better example explaining use of tx.executeSql with parameters
Change-Id: I79ab2cc4c0525dbc285b04b3867220f6943dc9e6
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
-rw-r--r-- | src/quick/doc/snippets/qml/localstorage/dbtransaction.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/quick/doc/snippets/qml/localstorage/dbtransaction.js b/src/quick/doc/snippets/qml/localstorage/dbtransaction.js index 07d8a5618b..40eb6d2804 100644 --- a/src/quick/doc/snippets/qml/localstorage/dbtransaction.js +++ b/src/quick/doc/snippets/qml/localstorage/dbtransaction.js @@ -39,30 +39,47 @@ ****************************************************************************/ //![0] +var db = LocalStorage.openDatabaseSync("ActivityTrackDB", "", "Database tracking sports activities", 1000000); db.transaction( try { function(tx) { - tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO trip_log VALUES(?, ?, ?)', + [ '01/10/2016','Sylling - Vikersund', '53' ]); } } catch (err) { - console.log("Error inserting into table Greeting"); + console.log("Error inserting into table Greeting: " + err); } ) //![0] //![1] +// Retrieve activity date, description and distance based on minimum +// distance parameter Pdistance +function db_distance_select(Pdistance) +{ +var db = LocalStorage.openDatabaseSync("ActivityTrackDB", "", "Database tracking sports activities", 1000000); db.transaction( function(tx) { - var results = tx.executeSql('SELECT salutation FROM Greeting WHERE salutee=?;', 'world'); + var results = tx.executeSql('SELECT rowid, + date, + trip_desc, + distance FROM trip_log + where distance >= ?',[Pdistance]'); + for (var i = 0; i < results.rows.length; i++) { + listModel.append({"id": results.rows.item(i).rowid, + "date": results.rows.item(i).date, + "trip_desc": results.rows.item(i).trip_desc, + "distance": results.rows.item(i).distance}); + } } - console.log("We greeted in this most respectful way: " + results.rows.item(0).value); -) +} //![1] //![2] -var db = LocalStorage.openDatabaseSync("QQmlExampleDB", "", "The Example QML SQL!", 1000000); +var db = LocalStorage.openDatabaseSync("ActivityTrackDB", "", "Database tracking sports activities", 1000000); if (db.version == '0.1') { db.changeVersion('0.1', '0.2', function(tx) { - tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO trip_log VALUES(?, ?, ?)', + [ '01/10/2016','Sylling - Vikersund', '53' ]); } }); //![2] |