Q: How to return a result from a SQLite SELECT? I'm trying to pass the result from an SQLite SELECT to the var res and show it but in the alert I get "undefined". How to correctly return it?
function read(key){
    app.db.transaction(function(tx) {
        tx.executeSql('SELECT value FROM MyTable WHERE key = ?',
            [key],
            function(tx, results)
            {
                return results.rows.item(0)['value']
            },                
            app.onError
        );
        return;
    });
    return;
}

res=read("pipi")
alert(res);


A: You cannot return a value from an asynchronous function. You need to either pass a function that will execute with the results of the async function OR use a global variable to hold the results.
res=read("pipi") // will always return undefined

you can declare a global variable and a global function.
resultSelect = "";
function alertResultSelect(result){
    alert(result);
}

then in your function(tx, results) code add
function(tx, results)
{
   //Assign the results to the global variable.
   resultSelect = results.rows.item(0)['value'];
   // OR call the global function
   alertResultSelect(results.rows.item(0)['value']);
}

