Add a third variable to a WEbSQL callback function

This is the code. I tried exploring the options of SQL for solving this, but they are limited. I want to pass newSync[i].id to the onsuccess callback function, but I fail

   tx.executeSql('SELECT * FROM bookmarks WHERE bookmarkID = ?', [newSync[i].id],
          function(tx,results){
            console.log('results.rows.item(0).bookmarkID', results.rows.item(0).bookmarkID);
            tx.executeSql('UPDATE bookmarksSync SET thumbnail=?, ts_created=?, visits=?, visits_morning=?, visits_afternoon=?, visits_evening=?, visits_night=?, position=?, idgroup=? WHERE bookmarkID=?', 
          [results.rows.item(0).thumbnail, results.rows.item(0).ts_created, results.rows.item(0).visits, results.rows.item(0).visits_morning, results.rows.item(0).visits_afternoon, results.rows.item(0).visits_evening, results.rows.item(0).visits_night, results.rows.item(0).position, 0, newSync[i].id]],
          null,speeddial.storage.onError)
          }
          , speeddial.storage.onError);

newSync[i].id appears to be undefined and I am pretty sure I have to pass it to the callback function, but I dont know how… Any ideas? I want to be able to pass the newSync[i].id and the results from the SQL selection to another function, which will update the WebSQL table.
I fail even if I add newSync[i].id as a third argument to function(tx,results)

Both are defined inside this function, they are not global. I will post the whole code. This is a part of an chrome extension. My bigger problem is , that function(tx,results){…} is a callback function and should be executed after all code is executed( and the cycle for i is run. So I want to pass the current value to this function…

here is the whole function

speeddial.storage.Sync = function() {
  chrome.bookmarks.getChildren(String(localStorage['rootFolderID']), function(newSync){
    speeddial.storage.db.transaction(function(tx){
      tx.executeSql('DELETE FROM bookmarksSync',null,null,speeddial.storage.onError);	
      tx.executeSql('DELETE FROM groupsSync',null,null,speeddial.storage.onError);	
      for (var i=0; i<newSync.length; i++){
	if(!newSync[i].url)
	{
// 	  tx.executeSql('SELECT * INTO groupsSync FROM groups', [],null
// // // 			function(tx,results){
// // 
// // // 	    console.log('results', results);
// // 	    
// // // 	    speeddial.storage.SyncGetChildren(newSync[i].id)
// // // 	    speeddial.storage.SyncGetTry(newSync[i].id)
// // 	    
// // // 	  }
// // 	    
// 	  ,speeddial.storage.onError);
	}
	else
	{
	  tx.executeSql('INSERT INTO bookmarksSync (title, bookmarkID, url, idgroup) values (?, ?, ?, ?)', [newSync[i].title,  newSync[i].id, newSync[i].url, 0],null,speeddial.storage.onError);

	      tx.executeSql('SELECT * FROM bookmarks WHERE bookmarkID = ?', [newSync[i].id], function(tx,results){
            console.log('results.rows.item(0).bookmarkID', results.rows.item(0).bookmarkID);
            tx.executeSql('UPDATE bookmarksSync SET thumbnail=?, ts_created=?, visits=?, visits_morning=?, visits_afternoon=?, visits_evening=?, visits_night=?, position=?, idgroup=? WHERE bookmarkID=?', 
          [results.rows.item(0).thumbnail, results.rows.item(0).ts_created, results.rows.item(0).visits, results.rows.item(0).visits_morning, results.rows.item(0).visits_afternoon, results.rows.item(0).visits_evening, results.rows.item(0).visits_night, results.rows.item(0).position, 0, newSync[i].id]],
          null,speeddial.storage.onError)
          }		  
		  , speeddial.storage.onError);

	}
	//above is the end of else statement
      }
//        	  tx.executeSql('DELETE FROM bookmarks',null,null,speeddial.storage.onError);
// 	  tx.executeSql('INSERT INTO bookmarks SELECT * FROM bookmarksSync', [],null,speeddial.storage.onError); 
    })
  })	
}

If newSync is not defined globally it will be out of scope when passed as a parameter to the ‘executeSql’ call.
Where/how/when is newSync defined elsewhere in your code?
How do you get the value for ‘i’ ?; which is also out of scope according to this code snippet.