I have a table caseTable
with fields (ID, caseName, date). Each row in that table corr
I don't believe it is possible to do this synchronously, and it's probably not a good idea to try.
In this case, you can probably get the value you are after using a subquery, something like:
SELECT *,
(SELECT COUNT(*) FROM CaseTableDetail WHERE CaseTableDetail.CaseID = CaseTable.id)
AS CaseCount
FROM CaseTable;
(this is just a guess as you haven't specified your full table structure for the CaseName table)
Edit:
For the above to work, you will need a proper relational structure, rather than be adding tables dynamically. You should have only 2 tables, I'm going to call them CaseTable and CaseDetailTable.
CaseTable is exactly what you already have.
CaseDetailTable is similar to the Test and Test2 tables above, but has an extra field, CaseID Now I have two more table in DB Test , Test2..
ID CaseID DocumentName Date Notes
1 1 ppp 7/33 asdhdfkdshf
2 1 asdjhad 9/44 dfjasgfsjfj
3 2 sad 7/4 asdhdfkdshf
4 2 assd 3/44 hhhhhh
5 2 asd 2/22 adgjad
So the CaseID field is a pointer to the entry in the CaseTable that each row is part of. Using WHERE, JOIN and subqueries like the one I used above, you will be able to access all the data much more efficiently. You can tell SQLite that this is what you are doing by using the REFERENCES keyword. This will tell the database to create indexes to make looking up CaseDetails faster, and it will make sure that you cannot add any rows to CaseDetailTable unless you have a corresponding entry in CaseTable.
You can create the CaseDetailTable as follows:
CREATE TABLE CaseDetailTable (
id INTEGER PRIMARY KEY AUTOINCREMENT,
CaseID INTEGER REFERENCES CaseTable (ID),
Notes TEXT unique NOT NULL,
DocumentName INTEGER,
Date TEXT NOT NULL
);
I do like this ..!!It is working..Thank for help
function getallTableData(tx) {
// tx.executeSql("DROP TABLE IF EXISTS a");
tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
}
function querySuccess(tx, result) {
var len = result.rows.length;
var countDoument=0
$('#folderData').empty();
for (var i = 0; i < len; i++) {
alert(i)
test1=result.rows.item(i).CaseName;
Test1(test1, function(i) {
return function(result_count) {
countDoument = result_count; // here it count value
alert(result_count + "result_count") //alert is correct count value
alert(i + "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 + countDoument + '</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 class="ui-li-count">' + i + '</span>'+ '</li>'
);
$('#folderData').listview('refresh');
};
}(i));
}
}
function Test1(test, callBack){
var x;
db.transaction(function (tx) {
$yoursql = 'SELECT * FROM "'+test+'" ';
tx.executeSql($yoursql, [], function (tx, results) {
x = results.rows.length + "TableName" + test;
callBack(x);
});
});
}
You could loop through them asynchronously by doing something like this (not tested, but hopefully you get the idea):
var count = 0;
var caseTableResult = [];
var getallTableData = function (tx) {
tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
}
var querySuccess = function (tx, result) {
if (count === 0) {
caseTableResult = result;
$('#folderData').empty();
} else {
var i = count - 1;
$('#folderData').append(
'<li class="caseRowClick" id="' + caseTableResult.rows.item(i).id + '" data-rel="popup" data-position-to="window">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>' + caseTableResult.rows.item(i).CaseName + t+'</h2>' + '<p>' + caseTableResult.rows.item(i).TextArea + '</p>' + '<p>' + caseTableResult.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>'
);
}
if (count <= caseTableResult.rows.length) {
// Call the next query
count += 1;
tx.executeSql('SELECT count(*) FROM ' + caseTableResult.rows.item(i).CaseName, [], querySuccess, errorCB);
} else {
// We're done
$('#folderData').listview('refresh');
}
}
But really you should not be creating lots of tables with the same structure and different names, you should have one table with all the data connected by a relationship, then you can use my other answer.