// Keep in mind we do not keep local document revision history
  private BasicDocumentRevision doGetLocalDocument(String docId, String revId) {
    assert !Strings.isNullOrEmpty(docId);
    Cursor cursor = null;
    try {
      String[] args = {docId};
      cursor = this.sqlDb.rawQuery("SELECT revid, json FROM localdocs WHERE docid=?", args);
      if (cursor.moveToFirst()) {
        String gotRevID = cursor.getString(0);

        if (revId != null && !revId.equals(gotRevID)) {
          //                    throw new DocumentNotFoundException("No local document found with
          // id: " + docId + ", revId: " + revId);
          return null;
        }

        byte[] json = cursor.getBlob(1);

        DocumentRevisionBuilder builder =
            new DocumentRevisionBuilder()
                .setDocId(docId)
                .setRevId(gotRevID)
                .setBody(BasicDocumentBody.bodyWith(json));

        return builder.buildBasicDBObjectLocalDocument();
      } else {
        return null;
      }
    } catch (SQLException e) {
      throw new SQLRuntimeException("Error getting local document with id: " + docId, e);
    } finally {
      DatabaseUtils.closeCursorQuietly(cursor);
    }
  }
  static BasicDocumentRevision getFullRevisionFromCurrentCursor(Cursor cursor) {
    String docId = cursor.getString(0);
    long internalId = cursor.getLong(1);
    String revId = cursor.getString(2);
    long sequence = cursor.getLong(3);
    byte[] json = cursor.getBlob(4);
    boolean current = cursor.getInt(5) > 0;
    boolean deleted = cursor.getInt(6) > 0;

    long parent = -1L;
    if (cursor.columnType(7) == Cursor.FIELD_TYPE_INTEGER) {
      parent = cursor.getLong(7);
    } else if (cursor.columnType(7) == Cursor.FIELD_TYPE_NULL) {
    } else {
      throw new IllegalArgumentException("Unexpected type: " + cursor.columnType(7));
    }

    DocumentRevisionBuilder builder =
        new DocumentRevisionBuilder()
            .setDocId(docId)
            .setRevId(revId)
            .setBody(BasicDocumentBody.bodyWith(json))
            .setDeleted(deleted)
            .setSequence(sequence)
            .setInternalId(internalId)
            .setCurrnet(current)
            .setParent(parent);

    return builder.buildBasicDBObject();
  }