Unable to assign a value in a javascript function while fetching from sqlite.
For Eg: This code in not working
function bookContent(dtb) {
var bkContent = '';
dtb.all("SELECT count(*) ttlRw FROM books;", function(err, row) {
if (err)
bkContent = "Error SQL";
else
{
if(parseInt(row[0].ttlRw)>0)
{
bkContent = row[0].ttlRw + " rows";
}
else
bkContent = 'No rows found!';
}
});
return bkContent;
}
It's returns an empty value.
This is working
function bookContent(dtb) {
dtb.all("SELECT count(*) ttlRw FROM books;", function(err, row) {
if (err)
document.getElementById("bookCnt").innerHTML = "Error SQL";
else
{
if(parseInt(row[0].ttlRw)>0)
{
document.getElementById("bookCnt").innerHTML = row[0].ttlRw + " rows";
}
else
document.getElementById("bookCnt").innerHTML = 'No rows found!';
}
});
}
I want the first one work. Please tell me, where i am wrong.