0

I am attempting to return all column values from an Sqlite db to a Qchart in qml in Ubuntu SDK - the db contains various fields including kilometres, miles, etc. I would like to return all values in one field (e.g. kilometres) into the Qchart - I know that this is possible using an array, e.g.

function testData(){
var kilometres = ["25","45","42","39"];
    return kilometres;
}

this will happily display the values 25,45,42 & 39 in the chart. However, try as I might, I cannot find a way to pass the values contained in the database to the array shown above. The following is what I have tried so far:-

// Chart Data
function getData() {
    var db = LocalStorage.openDatabaseSync("data.sql", "1.0",  "mileageDataBase", 10000000);
    var res = "";
    db.transaction(
    function(tx) {
    var rs = tx.executeSql('SELECT kilometres FROM mpg');
    res = rs.rows.item().kilometres;
    }
 );
 return res;
 }

(Please note that an earlier version of this question I asked about returning values to a TextField. I thought I could use this TextField to populate the graph but, after some experimentation, that does not appear to be the case. Apologies for the confusion.)

1 Answers1

0

Finally managed to get it to work :-). I'm posting my (working) code here in case anyone else hits a similar problem:

// Chart Data
function getData() {
var db = LocalStorage.openDatabaseSync("data.sql", "1.0",  "mileageDataBase", 10000000);
var ret;
var res = [];
var index;
db.transaction(
   function(tx) {
   var rs = tx.executeSql('SELECT * FROM mpg');
   for (var i=0; i<rs.rows.length; i++) {
   var row = rs.rows.item(i);
   ret = row.miles/row.gallons;
   res.push(ret);
  }
}
);
return res;
    }

Many thanks to Velkan for helping to point me in the right direction (even though the original question was more than a little ambiguous :-) )