int updateBookmarksInTransaction(ContentValues values,String selection,String[] selectionArgs,boolean callerIsSyncAdapter){
  int count=0;
  final SQLiteDatabase db=mOpenHelper.getWritableDatabase();
  final String[] bookmarksProjection=new String[]{Bookmarks._ID,Bookmarks.VERSION,Bookmarks.URL,Bookmarks.TITLE,Bookmarks.IS_FOLDER,Bookmarks.ACCOUNT_NAME,Bookmarks.ACCOUNT_TYPE};
  Cursor cursor=db.query(TABLE_BOOKMARKS,bookmarksProjection,selection,selectionArgs,null,null,null);
  boolean updatingParent=values.containsKey(Bookmarks.PARENT);
  String parentAccountName=null;
  String parentAccountType=null;
  if (updatingParent) {
    long parent=values.getAsLong(Bookmarks.PARENT);
    Cursor c=db.query(TABLE_BOOKMARKS,new String[]{Bookmarks.ACCOUNT_NAME,Bookmarks.ACCOUNT_TYPE},"_id = ?",new String[]{Long.toString(parent)},null,null,null);
    if (c.moveToFirst()) {
      parentAccountName=c.getString(0);
      parentAccountType=c.getString(1);
    }
    c.close();
  }
 else   if (values.containsKey(Bookmarks.ACCOUNT_NAME) || values.containsKey(Bookmarks.ACCOUNT_TYPE)) {
  }
  try {
    String[] args=new String[1];
    if (!callerIsSyncAdapter) {
      values.put(Bookmarks.DATE_MODIFIED,System.currentTimeMillis());
      values.put(Bookmarks.DIRTY,1);
    }
    boolean updatingUrl=values.containsKey(Bookmarks.URL);
    String url=null;
    if (updatingUrl) {
      url=values.getAsString(Bookmarks.URL);
    }
    ContentValues imageValues=extractImageValues(values,url);
    while (cursor.moveToNext()) {
      long id=cursor.getLong(0);
      args[0]=Long.toString(id);
      String accountName=cursor.getString(5);
      String accountType=cursor.getString(6);
      if (updatingParent && (!TextUtils.equals(accountName,parentAccountName) || !TextUtils.equals(accountType,parentAccountType))) {
        ContentValues newValues=valuesFromCursor(cursor);
        newValues.putAll(values);
        newValues.remove(Bookmarks._ID);
        newValues.remove(Bookmarks.VERSION);
        newValues.put(Bookmarks.ACCOUNT_NAME,parentAccountName);
        newValues.put(Bookmarks.ACCOUNT_TYPE,parentAccountType);
        Uri insertUri=insertInTransaction(Bookmarks.CONTENT_URI,newValues,callerIsSyncAdapter);
        long newId=ContentUris.parseId(insertUri);
        if (cursor.getInt(4) != 0) {
          ContentValues updateChildren=new ContentValues(1);
          updateChildren.put(Bookmarks.PARENT,newId);
          count+=updateBookmarksInTransaction(updateChildren,Bookmarks.PARENT + "=?",new String[]{Long.toString(id)},callerIsSyncAdapter);
        }
        Uri uri=ContentUris.withAppendedId(Bookmarks.CONTENT_URI,id);
        deleteInTransaction(uri,null,null,callerIsSyncAdapter);
        count+=1;
      }
 else {
        if (!callerIsSyncAdapter) {
          values.put(Bookmarks.VERSION,cursor.getLong(1) + 1);
        }
        count+=db.update(TABLE_BOOKMARKS,values,"_id=?",args);
      }
      if (imageValues != null) {
        if (!updatingUrl) {
          url=cursor.getString(2);
          imageValues.put(Images.URL,url);
        }
        if (!TextUtils.isEmpty(url)) {
          args[0]=url;
          if (db.update(TABLE_IMAGES,imageValues,Images.URL + "=?",args) == 0) {
            db.insert(TABLE_IMAGES,Images.FAVICON,imageValues);
          }
        }
      }
    }
  }
  finally {
    if (cursor != null)     cursor.close();
  }
  return count;
}

int updateBookmarksInTransaction ( ContentValues values , String selection , String [ ] selectionArgs , boolean callerIsSyncAdapter ) { int count = 0 ; final SQLiteDatabase db = mOpenHelper . getWritableDatabase ( ) ; final String [ ] bookmarksProjection = new String [ ] { Bookmarks . _ID , Bookmarks . VERSION , Bookmarks . URL , Bookmarks . TITLE , Bookmarks . IS_FOLDER , Bookmarks . ACCOUNT_NAME , Bookmarks . ACCOUNT_TYPE } ; Cursor cursor = db . query ( TABLE_BOOKMARKS , bookmarksProjection , selection , selectionArgs , null , null , null ) ; boolean updatingParent = values . containsKey ( Bookmarks . PARENT ) ; String parentAccountName = null ; String parentAccountType = null ; if ( updatingParent ) { long parent = values . getAsLong ( Bookmarks . PARENT ) ; Cursor c = db . query ( TABLE_BOOKMARKS , new String [ ] { Bookmarks . ACCOUNT_NAME , Bookmarks . ACCOUNT_TYPE } , "_id = ?" , new String [ ] { Long . toString ( parent ) } , null , null , null ) ; if ( c . moveToFirst ( ) ) { parentAccountName = c . getString ( 0 ) ; parentAccountType = c . getString ( 1 ) ; } c . close ( ) ; } else if ( values . containsKey ( Bookmarks . ACCOUNT_NAME ) || values . containsKey ( Bookmarks . ACCOUNT_TYPE ) ) { } try { String [ ] args = new String [ 1 ] ; if ( ! callerIsSyncAdapter ) { values . put ( Bookmarks . DATE_MODIFIED , System . currentTimeMillis ( ) ) ; values . put ( Bookmarks . DIRTY , 1 ) ; } boolean updatingUrl = values . containsKey ( Bookmarks . URL ) ; String url = null ; if ( updatingUrl ) { url = values . getAsString ( Bookmarks . URL ) ; } ContentValues imageValues = extractImageValues ( values , url ) ; while ( cursor . moveToNext ( ) ) { long id = cursor . getLong ( 0 ) ; args [ 0 ] = Long . toString ( id ) ; String accountName = cursor . getString ( 5 ) ; String accountType = cursor . getString ( 6 ) ; if ( updatingParent && ( ! TextUtils . equals ( accountName , parentAccountName ) || ! TextUtils . equals ( accountType , parentAccountType ) ) ) { ContentValues newValues = valuesFromCursor ( cursor ) ; newValues . putAll ( values ) ; newValues . remove ( Bookmarks . _ID ) ; newValues . remove ( Bookmarks . VERSION ) ; newValues . put ( Bookmarks . ACCOUNT_NAME , parentAccountName ) ; newValues . put ( Bookmarks . ACCOUNT_TYPE , parentAccountType ) ; Uri insertUri = insertInTransaction ( Bookmarks . CONTENT_URI , newValues , callerIsSyncAdapter ) ; long newId = ContentUris . parseId ( insertUri ) ; if ( cursor . getInt ( 4 ) != 0 ) { ContentValues updateChildren = new ContentValues ( 1 ) ; updateChildren . put ( Bookmarks . PARENT , newId ) ; count += updateBookmarksInTransaction ( updateChildren , Bookmarks . PARENT + "=?" , new String [ ] { Long . toString ( id ) } , callerIsSyncAdapter ) ; } Uri uri = ContentUris . withAppendedId ( Bookmarks . CONTENT_URI , id ) ; deleteInTransaction ( uri , null , null , callerIsSyncAdapter ) ; count += 1 ; } else { if ( ! callerIsSyncAdapter ) { values . put ( Bookmarks . VERSION , cursor . getLong ( 1 ) + 1 ) ; } count += db . update ( TABLE_BOOKMARKS , values , "_id=?" , args ) ; } if ( imageValues != null ) { if ( ! updatingUrl ) { url = cursor . getString ( 2 ) ; imageValues . put ( Images . URL , url ) ; } if ( ! TextUtils . isEmpty ( url ) ) { args [ 0 ] = url ; if ( db . update ( TABLE_IMAGES , imageValues , Images . URL + "=?" , args ) == 0 ) { db . insert ( TABLE_IMAGES , Images . FAVICON , imageValues ) ; } } } } } finally { if ( cursor != null ) cursor . close ( ) ; } return count ; }
does a query to find the matching bookmarks and updates each one with the provided values .
