title: Apache Cordova, SQLite, Delete from [table] where id=? does not return
body: <p>I have an Apache Cordova application that caches data that cannot be sent to a server when no communications are available, such as no 3G coverage etc.</p>
  
  <p>I have some code that runs when the device comes back online. The idea of this code is to recursively ripple through that cached data and send it to the server in the background. Once sent, each row should then be deleted to prevent it from being sent again.</p>
  
  <p>A cut-down and anonymised version of the code follows...</p>
  
  <pre><code>var app = {
  
      name: 'myApp',
      displayName: 'my application',
  
      db: null,
  
      initialize: function () {
  
          document.addEventListener("deviceready", app.onDeviceReady, false);
          document.addEventListener("online", app.onDeviceOnline, false);
  
      },
  
      onDeviceOnline: function () {
  
          app.db.transaction(
              function (tx) {
                  app.uploadCachedData(tx);
              },
              function (error) {
                  console.error("'" + error.message + "' creating database transaction.");
              },
              function () {
              }
  
          );
  
      },
  
      onDeviceReady: function () {
  
          app.db = window.openDatabase(app.name, "2.2", app.displayName, 1 * 1024 * 1024);
  
      },
  
      uploadCachedData: function (tx) {
  
          tx.executeSql('select * from [data]', [],
              function (tx, results) {
  
                  console.log("uploadCachedData, rows.length=" + results.rows.length);
                  if (results.rows.length &gt; 0) {
  
                      var item = results.rows.item(0);
                      var cachedDataId = item.id;
  
                      console.log("Uploading cached data, id=" + cachedDataId)
                      app.ws.uploadImage(item.f1, item.f2, item.f3, item.f4, item.f5,
                          function (data) {
                              console.log("'Data' (id=" + cachedDataId + ") uploaded from cache.");
                              tx.executeSql('delete from [data] where [id] = ?', [cachedDataId],
                                  function (tx, resultSet) {
                                      console.log("'[data] where [id]=" + cachedDataId + "' deleted.");
                                      app.uploadCachedData(tx);
                                  },
                                  function (error) {
                                      console.log("'" + error.message + "' deleting [data] where [id]=" + cachedDataId + "'.");
                                  });
                          },
                          function (response, textStatus, errorThrown) {
                              console.log("'" + error.message + "' uploading Data (id=" + cachedDataId + ") from cache.");
                          });
                  }
              },
              function (error) {
                  console.error("'" + error.message + "' selecting '[data]'.");
              });
  
      }
  
  };
  
  app.initialize();
  </code></pre>
  
  <p>When the code runs, I see messages up to and including "'Data' (id=1) uploaded from cache", and the first row of data is sent to the server. I see no more messages, not the success or fail messages from the delete that follows that message. I also see no more messages to indicate that the recursive call has been made (there are 4 rows in my test data) and no other data is sent to the server.</p>
  
  <p>Can anybody explain why the delete never seems to complete?</p>
  
  <p>Thanks.</p>