diff options
Diffstat (limited to 'src/com/android/browser/provider')
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider2.java | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 5825525..d93a039 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -31,13 +31,13 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.provider.BrowserContract; +import android.provider.SyncStateContract; import android.provider.BrowserContract.Bookmarks; import android.provider.BrowserContract.ChromeSyncColumns; import android.provider.BrowserContract.History; import android.provider.BrowserContract.Searches; import android.provider.BrowserContract.SyncState; import android.provider.ContactsContract.RawContacts; -import android.provider.SyncStateContract; import android.text.TextUtils; import java.util.HashMap; @@ -615,12 +615,12 @@ public class BrowserProvider2 extends SQLiteContentProvider { } case SEARCHES: { - id = db.insertOrThrow(TABLE_SEARCHES, Searches.SEARCH, values); + id = insertSearchesInTransaction(db, values); break; } case SYNCSTATE: { - id = mSyncHelper.insert(mDb, values); + id = mSyncHelper.insert(db, values); break; } @@ -636,6 +636,31 @@ public class BrowserProvider2 extends SQLiteContentProvider { } } + /** + * Searches are unique, so perform an UPSERT manually since SQLite doesn't support them. + */ + private long insertSearchesInTransaction(SQLiteDatabase db, ContentValues values) { + String search = values.getAsString(Searches.SEARCH); + if (TextUtils.isEmpty(search)) { + throw new IllegalArgumentException("Must include the SEARCH field"); + } + Cursor cursor = null; + try { + cursor = db.query(TABLE_SEARCHES, new String[] { Searches._ID }, + Searches.SEARCH + "=?", new String[] { search }, null, null, null); + if (cursor.moveToNext()) { + long id = cursor.getLong(0); + db.update(TABLE_SEARCHES, values, Searches._ID + "=?", + new String[] { Long.toString(id) }); + return id; + } else { + return db.insertOrThrow(TABLE_SEARCHES, Searches.SEARCH, values); + } + } finally { + if (cursor != null) cursor.close(); + } + } + @Override public int updateInTransaction(Uri uri, ContentValues values, String selection, String[] selectionArgs, boolean callerIsSyncAdapter) { @@ -664,16 +689,6 @@ public class BrowserProvider2 extends SQLiteContentProvider { return db.update(TABLE_HISTORY, values, selection, selectionArgs); } - case SEARCHES_ID: { - selection = DatabaseUtils.concatenateWhere(selection, TABLE_SEARCHES + "._id=?"); - selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs, - new String[] { Long.toString(ContentUris.parseId(uri)) }); - // fall through - } - case SEARCHES: { - return db.update(TABLE_SEARCHES, values, selection, selectionArgs); - } - case SYNCSTATE: { return mSyncHelper.update(mDb, values, appendAccountToSelection(uri, selection), selectionArgs); |