Silve2611
Silve2611

Reputation: 2278

Receiving Data from SQLITE Select with Javascript

I am encountering a problem with the select of SQLite.

I can read out the data but i do not know how to parse the values to a var so i can work with it. All i can do is log ist. So far i have two approaches. The first is not working at all.

    var readPath = function(){
        var newPath = '';
        var docPath = '';

        console.log("los gehts");

        db.transaction(function(tx) {

            tx.executeSql('Select Path AS path from TProject where Name = "timeBroMain"', [], function(tx, results){
                for (var i=0; i < results.rows.length; i++){
                    console.log(row.path);
                    row = results.rows.item(i);
                    retrieveData(row.path);
                }
            });
        });
    }
    function retrieveData(path) {
        alert(path);
    }
    readPath();

With the second approach I can log the items but not obtain them.

        db.serialize(function() {
            if(!exists) {
                alert("Table not accesed");
            }
            db.each("Select Path AS path from TProject where Name = 'timeBroMain'", function(err, row) {
                console.log(row.path);
                docPath = row.path;
            });
            alert(results.rows.item(0).text);
            newPath = docPath + '/' + name;
        });

How can the Data be processed? I would like to ad the value from the databse to another string and write it back to the db.

Upvotes: 0

Views: 69

Answers (1)

Silve2611
Silve2611

Reputation: 2278

I misunderstood the concept of javascript. The calles are asynchronous which foreces me to handle the data in the callback. Working with callbacks works. An alternative might be using promises which I will try in the future.

Upvotes: 1

Related Questions