I'm making a tiny app that will use Databases, I want to know how to convert this:
function testDB()
{
var db = window.openDatabase("Database", "1.0", "mydatabase", 2000000);
db.transaction(queryNames, errorDB);
}
function queryNames(tx)
{
tx.executeSql('SELECT name FROM people WHERE id=13', [], listNames, errorDB);
}
function listNames(tx, results)
{
for (var i=0;i<results.rows.length;i++)
{
alert(results.rows.item(i).name);
}
}
function errorDB(err)
{
alert("Fatal error");
}
To something like this (either if it is possible more compacted):
function testDB()
{
var db = window.openDatabase("Database", "1.0", "mydatabase", 2000000);
db.transaction(queryNames('SELECT name FROM people WHERE id=13'), errorDB);
}
function queryNames(tx, query)
{
tx.executeSql(, [],
function listNames(tx, results)
{
for (var i=0;i<results.rows.length;i++)
{
alert(results.rows.item(i).name);
}
},
errorDB);
}
function errorDB(err)
{
alert("Fatal error");
}
In few words, I'm trying to "recycle" the code. Thanks for reading.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…