2

Sqlite DB 内のすべてのテーブルをループしてサーバー DB に送信しようとしています。$.get() を介して情報を送信する部分に到達したときを除いて、すべてが機能しています tbl_name 変数はすでに最後の値に設定されています...つまり、すべての $.get() 呼び出しはtbl_name、最後のテーブル名。

        var submissionID=10;
        var varStr;

        DEMODB.transaction(function (transaction) {
            transaction.executeSql("SELECT name FROM sqlite_master WHERE type='table';", [], function(transaction, results) {
                for (var i = 0; i < results.rows.length; i++) {
                    var tables = results.rows.item(i);
                    var tbl_name=tables['name'];

                    if (tbl_name=="__WebKitDatabaseInfoTable__" || tbl_name=="Submission") { continue; }

                    transaction.executeSql("SELECT * FROM " + tbl_name + " WHERE submissionID=?;", [ID], function(transaction, results) {
                        varStr="";
                        for (var i = 0; i < results.rows.length; i++) {
                            var row = results.rows.item(i);

                            for (col in row) {
                                if (col=="submissionID" || col=="ID") { continue; }
                                varStr += col + "=" + row[col] + '&';
                            }
                        }
                        varStr += 'submissionID=' + submissionID + "&table=" + tbl_name + "&num=" + i;
                        $.get("script/to/process.aspx",varStr);
                    }, errorHandler);
                }
            }, errorHandler);
        });
4

1 に答える 1

1
DEMODB.transaction(function (transaction) {
  transaction.executeSql("SELECT name FROM sqlite_master WHERE type='table';", [], function(transaction, results) {
    for (var i = 0; i < results.rows.length; i++) {
      var tables = results.rows.item(i);
      handleTable(tables['name'], transaction);
    }
  }, errorHandler);
});


function handleTable(tbl_name, transaction) {

  if (tbl_name=="__WebKitDatabaseInfoTable__" || tbl_name=="Submission") { return; }

  transaction.executeSql("SELECT * FROM " + tbl_name + " WHERE submissionID=?;", [ID], function(transaction, results) {
    varStr="";
    for (var i = 0; i < results.rows.length; i++) {
      var row = results.rows.item(i);

      for (col in row) {
        if (col=="submissionID" || col=="ID") { continue; }
        varStr += col + "=" + row[col] + '&';
      }
    }
    varStr += 'submissionID=' + submissionID + "&table=" + tbl_name + "&num=" + i;
    $.get("script/to/process.aspx",varStr);
  }, errorHandler);
}
于 2012-11-20T05:31:49.083 に答える