是否可以从 cordova-sqlite 同步获取数据?
我有一个caseTable
包含字段(ID、caseName、日期)的表。该表中的每一行对应于另一个以 caseName 字段命名的表。我需要遍历caseTable
表并计算所引用表中的行数。
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 a synchronous method which returns the
* number of rows in the result.rows.item(i).CaseName table
* ************************************************************* */
$('#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');
}
为了在列表视图中显示“i”的值,我需要显示该表中有多少元素。我需要调用同步,因为我需要调用一些查询来计算该元素中“result.rows.item(i).CaseName”中元素的数量..?
举个例子...
DB 名称Case Pad 表名称 CaseTable
Let assume having entries in caseTable.
ID CaseName Case Date caseNote
1 Test 3/77/13 jgjgj
2 Test2 4/34/3 hsadkkadsh
Now I have two more table in DB
Test , Test2..
**Test** having entries like this
ID DocumentName Date Notes
1) ppp 7/33 asdhdfkdshf
2) asdjhad 9/44 dfjasgfsjfj
**Test2** having entries like this
ID DocumentName Date Notes
1) sad 7/4 asdhdfkdshf
2) assd 3/44 hhhhhh
3) asd 2/22 adgjad
现在 Test , Test2 的条目是 2 和 3。
现在我需要获取 CaseTable 的数据。在获取时,我需要计算我的 casename 表(Test,Test1)中的元素数。只在这里
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(
'<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');
}
我需要打印 casename casedate case 注意,元素数量 所以我的列表看起来像这样
Test 3/77/13 jgjgj 2
Test2 4/34/3 hsadkkadsh 3
如何在该表中打印 2 和 3 ......:(您能给我任何查询吗)