Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0
Accepted Solution

How to solve this data base query using sqlite phone gap

am facing a problem from last few days .The problem is of database .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.

 

function onDeviceReady() {
 
 
    db = window.openDatabase("Casepad", "1.0", "Casepad", 200000);
 
db.transaction(getallTableData, errorCB);
 
 
}
 
function insertData() {
    db.transaction(createTable, errorCB, afterSuccessTableCreation);
}
 
//createtableandinsertsome 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++) {
 
 
        $('#folderData').append(
                '<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>'+'</li>'
                );
    }
    $('#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..?

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: How to solve this data base query using sqlite phone gap

Hi there,

 

If I am understanding correctly, you're looking for a SQL statement that will get you the count for the number of elements in table AB? If so, this may be of assistance:

http://www.w3schools.com/sql/sql_func_count.asp

 

Please let me know if you have further questions.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to solve this data base query using sqlite phone gap

thanks done