public override int Delete(Uri uri, string selection, string[] selectionArgs) { if (LOGV) { Log.Verbose(TAG, "delete(uri=" + uri + ")"); } SQLiteDatabase db = mOpenHelper.WritableDatabase; SelectionBuilder builder = BuildSimpleSelection(uri); int retVal = builder.Where(selection, selectionArgs).Delete(db); Context.ContentResolver.NotifyChange(uri, null); return(retVal); }
public override int Update(Uri uri, ContentValues values, string selection, string[] selectionArgs) { if (LOGV) { Log.Verbose(TAG, "update(uri=" + uri + ", values=" + values.ToString() + ")"); } SQLiteDatabase db = mOpenHelper.WritableDatabase; SelectionBuilder builder = BuildSimpleSelection(uri); int retVal = builder.Where(selection, selectionArgs).Update(db, values); Context.ContentResolver.NotifyChange(uri, null); return(retVal); }
public override Android.Database.ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { if (LOGV) { Log.Verbose(TAG, "query(uri=" + uri + ", proj=" + projection.ToString() + ")"); } SQLiteDatabase db = mOpenHelper.ReadableDatabase; int match = sUriMatcher.Match(uri); switch (match) { default: { // Most cases are handled with simple SelectionBuilder SelectionBuilder builder = BuildExpandedSelection(uri, match); return(builder.Where(selection, selectionArgs).Query(db, projection, sortOrder)); } case SEARCH_SUGGEST: { SelectionBuilder builder = new SelectionBuilder(); // Adjust incoming query to become SQL text match selectionArgs[0] = selectionArgs[0] + "%"; builder.Table(ScheduleDatabase.Tables.SEARCH_SUGGEST); builder.Where(selection, selectionArgs); builder.Map(SearchManager.SuggestColumnQuery, SearchManager.SuggestColumnText1); projection = new String[] { BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnQuery }; String limit = uri.GetQueryParameter(SearchManager.SuggestParameterLimit); return(builder.Query(db, projection, null, null, ScheduleContract.SearchSuggest.DEFAULT_SORT, limit)); } } }
/** * Build an advanced {@link SelectionBuilder} to match the requested * {@link Uri}. This is usually only used by {@link #query}, since it * performs table joins useful for {@link Cursor} data. */ private SelectionBuilder BuildExpandedSelection(Uri uri, int match) { SelectionBuilder builder = new SelectionBuilder(); switch (match) { case BLOCKS: { return builder.Table(ScheduleDatabase.Tables.BLOCKS); } case BLOCKS_BETWEEN: { var segments = uri.PathSegments; String startTime = segments[2]; String endTime = segments[3]; return builder.Table(ScheduleDatabase.Tables.BLOCKS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .Where(ScheduleContract.Blocks.BLOCK_START + ">=?", startTime) .Where(ScheduleContract.Blocks.BLOCK_START + "<=?", endTime); } case BLOCKS_ID: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return builder.Table(ScheduleDatabase.Tables.BLOCKS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .Where(ScheduleContract.Blocks.BLOCK_ID + "=?", blockId); } case BLOCKS_ID_SESSIONS: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_BLOCK_ID + "=?", blockId); } case TRACKS: { return builder.Table(ScheduleDatabase.Tables.TRACKS) .Map(ScheduleContract.Tracks.SESSIONS_COUNT, Subquery.TRACK_SESSIONS_COUNT) .Map(ScheduleContract.Tracks.VENDORS_COUNT, Subquery.TRACK_VENDORS_COUNT); } case TRACKS_ID: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return builder.Table(ScheduleDatabase.Tables.TRACKS) .Where(ScheduleContract.Tracks.TRACK_ID + "=?", trackId); } case TRACKS_ID_SESSIONS: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS_JOIN_SESSIONS_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_TRACKS_TRACK_ID + "=?", trackId); } case TRACKS_ID_VENDORS: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(Qualified.VENDORS_TRACK_ID + "=?", trackId); } case ROOMS: { return builder.Table(ScheduleDatabase.Tables.ROOMS); } case ROOMS_ID: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return builder.Table(ScheduleDatabase.Tables.ROOMS) .Where(ScheduleContract.Rooms.ROOM_ID + "=?", roomId); } case ROOMS_ID_SESSIONS: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_ROOM_ID + "=?", roomId); } case SESSIONS: { return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS); } case SESSIONS_STARRED: { return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.SESSION_STARRED + "=1", (string) null); } case SESSIONS_SEARCH: { String query = ScheduleContract.Sessions.GetSearchQuery(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_SEARCH_JOIN_SESSIONS_BLOCKS_ROOMS) .Map(ScheduleContract.Sessions.SEARCH_SNIPPET, Subquery.SESSIONS_SNIPPET) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleDatabase.SessionsSearchColumns.BODY + " MATCH ?", query); } case SESSIONS_AT: { var segments = uri.PathSegments; String time = segments[2]; return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.BLOCK_START + "<=?", time) .Where(ScheduleContract.Sessions.BLOCK_END + ">=?", time); } case SESSIONS_ID: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_SESSION_ID + "=?", sessionId); } case SESSIONS_ID_SPEAKERS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS_JOIN_SPEAKERS) .MapToTable(ScheduleContract.Speakers._ID, ScheduleDatabase.Tables.SPEAKERS) .MapToTable(ScheduleContract.Speakers.SPEAKER_ID, ScheduleDatabase.Tables.SPEAKERS) .Where(Qualified.SESSIONS_SPEAKERS_SESSION_ID + "=?", sessionId); } case SESSIONS_ID_TRACKS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS_JOIN_TRACKS) .MapToTable(ScheduleContract.Tracks._ID, ScheduleDatabase.Tables.TRACKS) .MapToTable(ScheduleContract.Tracks.TRACK_ID, ScheduleDatabase.Tables.TRACKS) .Where(Qualified.SESSIONS_TRACKS_SESSION_ID + "=?", sessionId); } case SPEAKERS: { return builder.Table(ScheduleDatabase.Tables.SPEAKERS); } case SPEAKERS_ID: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return builder.Table(ScheduleDatabase.Tables.SPEAKERS) .Where(ScheduleContract.Speakers.SPEAKER_ID + "=?", speakerId); } case SPEAKERS_ID_SESSIONS: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS_JOIN_SESSIONS_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_SPEAKERS_SPEAKER_ID + "=?", speakerId); } case VENDORS: { return builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS); } case VENDORS_STARRED: { return builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_STARRED + "=1", (string) null); } case VENDORS_SEARCH: { String query = ScheduleContract.Vendors.GetSearchQuery(uri); return builder.Table(ScheduleDatabase.Tables.VENDORS_SEARCH_JOIN_VENDORS_TRACKS) .Map(ScheduleContract.Vendors.SEARCH_SNIPPET, Subquery.VENDORS_SNIPPET) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.VENDOR_ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleDatabase.VendorsSearchColumns.BODY + " MATCH ?", query); } case VENDORS_ID: { String vendorId = ScheduleContract.Vendors.GetVendorId(uri); return builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_ID + "=?", vendorId); } default: { throw new Exception("Unknown uri: " + uri); } } }
/** * Build a simple {@link SelectionBuilder} to match the requested * {@link Uri}. This is usually enough to support {@link #insert}, * {@link #update}, and {@link #delete} operations. */ private SelectionBuilder BuildSimpleSelection(Uri uri) { SelectionBuilder builder = new SelectionBuilder(); int match = sUriMatcher.Match(uri); switch (match) { case BLOCKS: { return builder.Table(ScheduleDatabase.Tables.BLOCKS); } case BLOCKS_ID: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return builder.Table(ScheduleDatabase.Tables.BLOCKS) .Where(ScheduleContract.Blocks.BLOCK_ID + "=?", blockId); } case TRACKS: { return builder.Table(ScheduleDatabase.Tables.TRACKS); } case TRACKS_ID: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return builder.Table(ScheduleDatabase.Tables.TRACKS) .Where(ScheduleContract.Tracks.TRACK_ID + "=?", trackId); } case ROOMS: { return builder.Table(ScheduleDatabase.Tables.ROOMS); } case ROOMS_ID: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return builder.Table(ScheduleDatabase.Tables.ROOMS) .Where(ScheduleContract.Rooms.ROOM_ID + "=?", roomId); } case SESSIONS: { return builder.Table(ScheduleDatabase.Tables.SESSIONS); } case SESSIONS_ID: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId); } case SESSIONS_ID_SPEAKERS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId); } case SESSIONS_ID_TRACKS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId); } case SPEAKERS: { return builder.Table(ScheduleDatabase.Tables.SPEAKERS); } case SPEAKERS_ID: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return builder.Table(ScheduleDatabase.Tables.SPEAKERS) .Where(ScheduleContract.Speakers.SPEAKER_ID + "=?", speakerId); } case VENDORS: { return builder.Table(ScheduleDatabase.Tables.VENDORS); } case VENDORS_ID: { String vendorId = ScheduleContract.Vendors.GetVendorId(uri); return builder.Table(ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_ID + "=?", vendorId); } case SEARCH_SUGGEST: { return builder.Table(ScheduleDatabase.Tables.SEARCH_SUGGEST); } default: { throw new Exception("Unknown uri: " + uri); } } }
public override Android.Database.ICursor Query (Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { if (LOGV) Log.Verbose(TAG, "query(uri=" + uri + ", proj=" + projection.ToString() + ")"); SQLiteDatabase db = mOpenHelper.ReadableDatabase; int match = sUriMatcher.Match(uri); switch (match) { default: { // Most cases are handled with simple SelectionBuilder SelectionBuilder builder = BuildExpandedSelection(uri, match); return builder.Where(selection, selectionArgs).Query(db, projection, sortOrder); } case SEARCH_SUGGEST: { SelectionBuilder builder = new SelectionBuilder(); // Adjust incoming query to become SQL text match selectionArgs[0] = selectionArgs[0] + "%"; builder.Table(ScheduleDatabase.Tables.SEARCH_SUGGEST); builder.Where(selection, selectionArgs); builder.Map(SearchManager.SuggestColumnQuery, SearchManager.SuggestColumnText1); projection = new String[] { BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnQuery }; String limit = uri.GetQueryParameter(SearchManager.SuggestParameterLimit); return builder.Query(db, projection, null, null, ScheduleContract.SearchSuggest.DEFAULT_SORT, limit); } } }
/** * Build an advanced {@link SelectionBuilder} to match the requested * {@link Uri}. This is usually only used by {@link #query}, since it * performs table joins useful for {@link Cursor} data. */ private SelectionBuilder BuildExpandedSelection(Uri uri, int match) { SelectionBuilder builder = new SelectionBuilder(); switch (match) { case BLOCKS: { return(builder.Table(ScheduleDatabase.Tables.BLOCKS)); } case BLOCKS_BETWEEN: { var segments = uri.PathSegments; String startTime = segments[2]; String endTime = segments[3]; return(builder.Table(ScheduleDatabase.Tables.BLOCKS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .Where(ScheduleContract.Blocks.BLOCK_START + ">=?", startTime) .Where(ScheduleContract.Blocks.BLOCK_START + "<=?", endTime)); } case BLOCKS_ID: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return(builder.Table(ScheduleDatabase.Tables.BLOCKS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .Where(ScheduleContract.Blocks.BLOCK_ID + "=?", blockId)); } case BLOCKS_ID_SESSIONS: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .Map(ScheduleContract.Blocks.SESSIONS_COUNT, Subquery.BLOCK_SESSIONS_COUNT) .Map(ScheduleContract.Blocks.CONTAINS_STARRED, Subquery.BLOCK_CONTAINS_STARRED) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_BLOCK_ID + "=?", blockId)); } case TRACKS: { return(builder.Table(ScheduleDatabase.Tables.TRACKS) .Map(ScheduleContract.Tracks.SESSIONS_COUNT, Subquery.TRACK_SESSIONS_COUNT) .Map(ScheduleContract.Tracks.VENDORS_COUNT, Subquery.TRACK_VENDORS_COUNT)); } case TRACKS_ID: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return(builder.Table(ScheduleDatabase.Tables.TRACKS) .Where(ScheduleContract.Tracks.TRACK_ID + "=?", trackId)); } case TRACKS_ID_SESSIONS: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS_JOIN_SESSIONS_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_TRACKS_TRACK_ID + "=?", trackId)); } case TRACKS_ID_VENDORS: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return(builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(Qualified.VENDORS_TRACK_ID + "=?", trackId)); } case ROOMS: { return(builder.Table(ScheduleDatabase.Tables.ROOMS)); } case ROOMS_ID: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return(builder.Table(ScheduleDatabase.Tables.ROOMS) .Where(ScheduleContract.Rooms.ROOM_ID + "=?", roomId)); } case ROOMS_ID_SESSIONS: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_ROOM_ID + "=?", roomId)); } case SESSIONS: { return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS)); } case SESSIONS_STARRED: { return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.SESSION_STARRED + "=1", (string)null)); } case SESSIONS_SEARCH: { String query = ScheduleContract.Sessions.GetSearchQuery(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_SEARCH_JOIN_SESSIONS_BLOCKS_ROOMS) .Map(ScheduleContract.Sessions.SEARCH_SNIPPET, Subquery.SESSIONS_SNIPPET) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleDatabase.SessionsSearchColumns.BODY + " MATCH ?", query)); } case SESSIONS_AT: { var segments = uri.PathSegments; String time = segments[2]; return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.BLOCK_START + "<=?", time) .Where(ScheduleContract.Sessions.BLOCK_END + ">=?", time)); } case SESSIONS_ID: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_JOIN_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_SESSION_ID + "=?", sessionId)); } case SESSIONS_ID_SPEAKERS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS_JOIN_SPEAKERS) .MapToTable(ScheduleContract.Speakers._ID, ScheduleDatabase.Tables.SPEAKERS) .MapToTable(ScheduleContract.Speakers.SPEAKER_ID, ScheduleDatabase.Tables.SPEAKERS) .Where(Qualified.SESSIONS_SPEAKERS_SESSION_ID + "=?", sessionId)); } case SESSIONS_ID_TRACKS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS_JOIN_TRACKS) .MapToTable(ScheduleContract.Tracks._ID, ScheduleDatabase.Tables.TRACKS) .MapToTable(ScheduleContract.Tracks.TRACK_ID, ScheduleDatabase.Tables.TRACKS) .Where(Qualified.SESSIONS_TRACKS_SESSION_ID + "=?", sessionId)); } case SPEAKERS: { return(builder.Table(ScheduleDatabase.Tables.SPEAKERS)); } case SPEAKERS_ID: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return(builder.Table(ScheduleDatabase.Tables.SPEAKERS) .Where(ScheduleContract.Speakers.SPEAKER_ID + "=?", speakerId)); } case SPEAKERS_ID_SESSIONS: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS_JOIN_SESSIONS_BLOCKS_ROOMS) .MapToTable(ScheduleContract.Sessions._ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.SESSION_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.BLOCK_ID, ScheduleDatabase.Tables.SESSIONS) .MapToTable(ScheduleContract.Sessions.ROOM_ID, ScheduleDatabase.Tables.SESSIONS) .Where(Qualified.SESSIONS_SPEAKERS_SPEAKER_ID + "=?", speakerId)); } case VENDORS: { return(builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS)); } case VENDORS_STARRED: { return(builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_STARRED + "=1", (string)null)); } case VENDORS_SEARCH: { String query = ScheduleContract.Vendors.GetSearchQuery(uri); return(builder.Table(ScheduleDatabase.Tables.VENDORS_SEARCH_JOIN_VENDORS_TRACKS) .Map(ScheduleContract.Vendors.SEARCH_SNIPPET, Subquery.VENDORS_SNIPPET) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.VENDOR_ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleDatabase.VendorsSearchColumns.BODY + " MATCH ?", query)); } case VENDORS_ID: { String vendorId = ScheduleContract.Vendors.GetVendorId(uri); return(builder.Table(ScheduleDatabase.Tables.VENDORS_JOIN_TRACKS) .MapToTable(ScheduleContract.Vendors._ID, ScheduleDatabase.Tables.VENDORS) .MapToTable(ScheduleContract.Vendors.TRACK_ID, ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_ID + "=?", vendorId)); } default: { throw new Exception("Unknown uri: " + uri); } } }
/** * Build a simple {@link SelectionBuilder} to match the requested * {@link Uri}. This is usually enough to support {@link #insert}, * {@link #update}, and {@link #delete} operations. */ private SelectionBuilder BuildSimpleSelection(Uri uri) { SelectionBuilder builder = new SelectionBuilder(); int match = sUriMatcher.Match(uri); switch (match) { case BLOCKS: { return(builder.Table(ScheduleDatabase.Tables.BLOCKS)); } case BLOCKS_ID: { String blockId = ScheduleContract.Blocks.GetBlockId(uri); return(builder.Table(ScheduleDatabase.Tables.BLOCKS) .Where(ScheduleContract.Blocks.BLOCK_ID + "=?", blockId)); } case TRACKS: { return(builder.Table(ScheduleDatabase.Tables.TRACKS)); } case TRACKS_ID: { String trackId = ScheduleContract.Tracks.GetTrackId(uri); return(builder.Table(ScheduleDatabase.Tables.TRACKS) .Where(ScheduleContract.Tracks.TRACK_ID + "=?", trackId)); } case ROOMS: { return(builder.Table(ScheduleDatabase.Tables.ROOMS)); } case ROOMS_ID: { String roomId = ScheduleContract.Rooms.GetRoomId(uri); return(builder.Table(ScheduleDatabase.Tables.ROOMS) .Where(ScheduleContract.Rooms.ROOM_ID + "=?", roomId)); } case SESSIONS: { return(builder.Table(ScheduleDatabase.Tables.SESSIONS)); } case SESSIONS_ID: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId)); } case SESSIONS_ID_SPEAKERS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_SPEAKERS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId)); } case SESSIONS_ID_TRACKS: { String sessionId = ScheduleContract.Sessions.GetSessionId(uri); return(builder.Table(ScheduleDatabase.Tables.SESSIONS_TRACKS) .Where(ScheduleContract.Sessions.SESSION_ID + "=?", sessionId)); } case SPEAKERS: { return(builder.Table(ScheduleDatabase.Tables.SPEAKERS)); } case SPEAKERS_ID: { String speakerId = ScheduleContract.Speakers.GetSpeakerId(uri); return(builder.Table(ScheduleDatabase.Tables.SPEAKERS) .Where(ScheduleContract.Speakers.SPEAKER_ID + "=?", speakerId)); } case VENDORS: { return(builder.Table(ScheduleDatabase.Tables.VENDORS)); } case VENDORS_ID: { String vendorId = ScheduleContract.Vendors.GetVendorId(uri); return(builder.Table(ScheduleDatabase.Tables.VENDORS) .Where(ScheduleContract.Vendors.VENDOR_ID + "=?", vendorId)); } case SEARCH_SUGGEST: { return(builder.Table(ScheduleDatabase.Tables.SEARCH_SUGGEST)); } default: { throw new Exception("Unknown uri: " + uri); } } }