/// <exception cref="Couchbase.Lite.Storage.SQLException"></exception> internal Int32 FindMissingRevisions(RevisionList touchRevs) { var numRevisionsRemoved = 0; if (touchRevs.Count == 0) { return numRevisionsRemoved; } var quotedDocIds = JoinQuoted(touchRevs.GetAllDocIds()); var quotedRevIds = JoinQuoted(touchRevs.GetAllRevIds()); var sql = "SELECT docid, revid FROM revs, docs " + "WHERE docid IN (" + quotedDocIds + ") AND revid in (" + quotedRevIds + ")" + " AND revs.doc_id == docs.doc_id"; Cursor cursor = null; try { cursor = StorageEngine.RawQuery(sql); cursor.MoveToNext(); while (!cursor.IsAfterLast()) { var rev = touchRevs.RevWithDocIdAndRevId(cursor.GetString(0), cursor.GetString(1)); if (rev != null) { touchRevs.Remove(rev); numRevisionsRemoved += 1; } cursor.MoveToNext(); } } finally { if (cursor != null) { cursor.Close(); } } return numRevisionsRemoved; }
public bool FindMissingRevisions(RevisionList touchRevs) { if (touchRevs.Count == 0) { return true; } string quotedDocIds = JoinQuoted(touchRevs.GetAllDocIds()); string quotedRevIds = JoinQuoted(touchRevs.GetAllRevIds()); string sql = "SELECT docid, revid FROM revs, docs " + "WHERE docid IN (" + quotedDocIds + ") AND revid in (" + quotedRevIds + ")" + " AND revs.doc_id == docs.doc_id"; Cursor cursor = null; try { cursor = database.RawQuery(sql, null); cursor.MoveToNext(); while (!cursor.IsAfterLast()) { RevisionInternal rev = touchRevs.RevWithDocIdAndRevId(cursor.GetString(0), cursor .GetString(1)); if (rev != null) { touchRevs.Remove(rev); } cursor.MoveToNext(); } } catch (SQLException e) { Log.E(Database.Tag, "Error finding missing revisions", e); return false; } finally { if (cursor != null) { cursor.Close(); } } return true; }