How can I fetch data synchronously from cordova-sqlite?

前端 未结 3 1696
灰色年华
灰色年华 2021-01-06 07:07

Is it possible to fetch data synchronously from cordova-sqlite?

I have a table caseTable with fields (ID, caseName, date). Each row in that table corr

3条回答
  •  被撕碎了的回忆
    2021-01-06 08:03

    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(
                    '
  • ' + '' + '' + '

    ' + caseTableResult.rows.item(i).CaseName + t+'

    ' + '

    ' + caseTableResult.rows.item(i).TextArea + '

    ' + '

    ' + caseTableResult.rows.item(i).CaseDate + '

    ' + '' + i + '
    ' + '
    '+'
  • ' ); } 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.

提交回复
热议问题