title: Query based on previous query results in Phonegap SQLite
body: <p>I am writing an Android app with Phonegap and its sqlite API. 
  Now I want to insert a record if some conditions are met in a previous query. 
  For example, </p>
  
  <pre><code>tx.executeSql("SELECT * FROM T_Task WHERE is_valid=1",[], successCB, errorCB);
  </code></pre>
  
  <p>In successCB, I want to add sub task if the task date is today and the sub task is not added for today yet. The condition to check if the task already exists is by task title.</p>
  
  <pre><code>function successCB(tx,results){
   for(var i=0; i&lt;results.rows.length; i++){
     var item=results.rows.item(i);
     if(item.date==today){//'today' is defined elsewhere, globally accessible
        var sql="SELECT * FROM T_SubTask WHERE title='"+item.title+"' and date='"+today+"')";
        tx.executeSql(sql,[],function(tx,results){addSubTask(tx, results, item.title)},errorCB);
     }
  }
  </code></pre>
  
  <p>Now the problem is if there are multiple tasks, the passing parameter item.title will be overridden by the last loop.
  I know I can use something like (function(x){FUNCTION(x)})(item.title) to avoid similar issues. But I don't know how to do it in the sqlite case, where I want to pass the correct 'item.title' and 'results' parameters both. If I use</p>
  
  <pre><code>tx.executeSql(sql,[],function(tx,results){ (function(x){addSubTask(tx, results, x)})(item.title),errorCB);
  </code></pre>
  
  <p>, another problem is the results will be the input parameter of "successCB(tx, results)", not the results object for the "FROM T_SubTask" query.</p>
  
  <p>How can I make everything correct here?</p>