Click here to Skip to main content
15,888,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
can you please tell me the example how to fetch data synchronously ? Actually I create the data base of mane "casepad".Then i create a table in that data base "case table" having (ID ,case name, date). Now i insert the value on that table .On insert i also create a table of name ("casename").mean if i insert value of case table (1,"AB",2/13).Then i create AB table.Now I need to get value from case table (i am getting) but along i need to count number of element in other table (AB).Here i am need trying like that.

JavaScript
function onDeviceReady() {

db = window.openDatabase("Casepad", "1.0", "Casepad", 200000);
db.transaction(getallTableData, errorCB);
}

function insertData() {
    db.transaction(createTable, errorCB, afterSuccessTableCreation);
}

//create table and insert some record
function createTable(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS CaseTable (id INTEGER PRIMARY KEY AUTOINCREMENT, CaseName  TEXT unique NOT NULL ,CaseDate INTEGER ,TextArea TEXT NOT NULL)');

    tx.executeSql('INSERT OR IGNORE INTO CaseTable(CaseName,CaseDate,TextArea) VALUES ("' + $('.caseName_h').val() + '", "' + $('.caseDate_h').val() + '","' + $('.caseTextArea_h').val() + '")');


}
//function will be called when an error occurred
function errorCB(err) {
    navigator.notification.alert("Error processing SQL: " + err.code);
}

//function will be called when process succeed
function afterSuccessTableCreation() {
    console.log("success!");
    db.transaction(getallTableData, errorCB);
}



//select all from SoccerPlayer
function getallTableData(tx) {
    tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
}



function querySuccess(tx, result) {
    var len = result.rows.length;
    var t;
    $('#folderData').empty();
    for (var i = 0; i < len; i++) {
Here i need to call synchronize method which call the number of element in in that  result.rows.item(i).CaseName and insert it in this table
****************************************************************************
        $('#folderData').append(
                '<ul><li class="caseRowClick" id="' + result.rows.item(i).id + '" data-rel="popup" data-position-to="window">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>' + result.rows.item(i).CaseName + t+'</h2>' + '<p>' + result.rows.item(i).TextArea + '</p>' + '<p>' + result.rows.item(i).CaseDate + '</p>' + '<span class="ui-li-count">' + i + '</span></a>' + 
                 '<span class="ctrl togg"><fieldset data-role="controlgroup" data-type="horizontal" data-mini="true"><button class="edit button_design">Edit</button><button class="del button_design">Delete</button></fieldset><span>'+'</span></span></li></ul>'
                );
    }
    $('#folderData').listview('refresh');

}


Instend of showing value of "i" in list view i need to show how many element in that table . I need to call synchronise because i need to call some query which count the number of element in "result.rows.item(i).CaseName" in this element..?
Posted
Updated 19-Jul-13 9:00am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900