/// Ejecutas las sentencias de busquedad deacuerdo a los parametros que le hayan pasado.
		Android.Database.ICursor EjecutaSentencia (String selection, String[] selectionArgs, String[] columns)
		{
			//creamos un querybuilder
			var builder = new SQLiteQueryBuilder ();
			//le asignamos el nombre de la tabla va utilizar para ejecutar las sentencias
			builder.Tables = FTS_VIRTUAL_TABLE;
			//Asignamos el esquema de mapeo de columnas que utilizara nuestro query builder para ejecutar la sentencias
			builder.SetProjectionMap (MapColumnas);

			//Ejecutamos la sentencia y le pasamos los argumentos necesarios para ejecutarla
			var cursor = builder.Query (dasedatosOpenHelper.ReadableDatabase,
				columns, selection, selectionArgs, null, null, null);

			//verificamos que nuestro cursor tenga informacion
			if (cursor == null) {
				return null;
			} else if (!cursor.MoveToFirst ()) {
				cursor.Close ();
				return null;
			}
			return cursor;
		}
        public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
        {
            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
            qb.Tables = DATABASE_TABLE_NAME;

            switch (uriMatcher.Match(uri))
            {
                case LOCATIONS:
                    qb.SetProjectionMap(mProjectionMap);
                    break;
                case LOCATION_ID:
                    qb.SetProjectionMap(mProjectionMap);
                    qb.AppendWhere(_ID + "=" + uri.PathSegments.ElementAt(1));
                    break;
                default:
                    throw new ArgumentException("Unknown URI " + uri);
            }

            // If no sort order is specified use the default
            string orderBy;
            if (sortOrder.Length < 1)
            {
                orderBy = DEFAULT_SORT_ORDER;
            }
            else
            {
                orderBy = sortOrder;
            }

            // Get the database and run the query
            SQLiteDatabase db = dbHelper.ReadableDatabase;
            ICursor c = qb.Query(db, projection, selection, selectionArgs, null, null, orderBy);

            // Tell the cursor what uri to watch, so it knows when its source data changes
            c.SetNotificationUri(Context.ContentResolver, uri);

            return c;
        }
        Android.Database.ICursor Query(String selection, String[] selectionArgs, String[] columns)
        {
            var builder = new SQLiteQueryBuilder ();
            builder.Tables = FTS_VIRTUAL_TABLE;
            builder.SetProjectionMap (mColumnMap);

            var cursor = builder.Query (databaseOpenHelper.ReadableDatabase,
                columns, selection, selectionArgs, null, null, null);

            if (cursor == null) {
                return null;
            } else if (!cursor.MoveToFirst ()) {
                cursor.Close ();
                return null;
            }
            return cursor;
        }
 //@Override
 //public override Cursor query(Android.Net.Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
 //{
 public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
 {
     SQLiteDatabase db = mDBHelper.ReadableDatabase; // .GetReadableDatabase();
     int match = sUriMatcher.Match(uri);
     //
     SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
     //**WES**            queryBuilder. .SetTables(BowlingDatabase.Table_SCORECARD);
     queryBuilder.Tables = BowlingDatabase.Table_SCORECARD;
     //
     switch (match)
     {
         case SCORECARD:
             break;
         case SCORECARD_ID:
             String id = BowlingContract.BCScorecard.getScorecardId(uri);
             queryBuilder.AppendWhere(BowlingContract.BaseColumns._ID + "=" + id);
             break;
         default:
             throw new Exception("Unknown uri: " + uri);
     }
     ICursor cursor = queryBuilder.Query(db, projection, selection, selectionArgs, null, null, sortOrder);
     return cursor;
 }
        /// <summary>
        /// Figure out which query to run based on the URL requested and any other
        /// parameters provided.
        /// </summary>
        /// <param name="paramUri"></param>
        /// <param name="?"></param>
        /// <param name="projection"></param>
        /// <param name="selection"></param>
        /// <param name="selectionArgs"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        public override ICursor Query(AndroidUri paramUri, string[] projection, string selection,	string[] selectionArgs, string sort)
        {
            // Query the database using the arguments provided
            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
            string[] whereArgs = null;

            // What type of query are we going to use - the URL_MATCHER
            // defined at the bottom of this class is used to pattern-match
            // the URL and select the right query from the switch statement
            switch (URI_MATCHER.Match(paramUri))
            {
                case NOTES:
                    // this match lists all notes
                    qb.Tables = WikiNote.Notes.TABLE_WIKINOTES;
                    qb.SetProjectionMap(NOTES_LIST_PROJECTION_MAP);
                    break;

                case NOTE_SEARCH:
                    // this match searches for a text match in the body of notes
                    qb.Tables = WikiNote.Notes.TABLE_WIKINOTES;
                    qb.SetProjectionMap(NOTES_LIST_PROJECTION_MAP);
                    qb.AppendWhere("body like ? or title like ?");
                    whereArgs = new string[2];
                    whereArgs[0] = whereArgs[1] = "%" + paramUri.LastPathSegment + "%";
                    break;

                case NOTE_NAME:
                    // this match searches for an exact match for a specific note name
                    qb.Tables = WikiNote.Notes.TABLE_WIKINOTES;
                    qb.AppendWhere("title=?");
                    whereArgs = new string[] { paramUri.LastPathSegment };
                    break;

                default:
                    // anything else is considered and illegal request
                    throw new IllegalArgumentException("Unknown URL " + paramUri);
            }

            // If no sort order is specified use the default
            string orderBy;
            if (TextUtils.IsEmpty(sort))
            {
                orderBy = WikiNote.Notes.MOST_RECENTLY_MODIFIED_SORT_ORDER;
            }
            else
            {
                orderBy = sort;
            }

            // Run the query and return the results as a Cursor
            SQLiteDatabase mDb = _dbHelper.ReadableDatabase;
            ICursor c = qb.Query(mDb, projection, null, whereArgs, null, null, orderBy);
            c.SetNotificationUri(Context.ContentResolver, paramUri);
            return c;
        }
Exemple #6
0
        public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs,
	            string sortOrder)
        {
            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

            switch (uriMatcher.Match(uri)) {
            case NOTES:
                qb.Tables = DB_TABLE_NOTES;
                qb.SetProjectionMap(notesProjectionMap);
                break;

            case NOTE_ID:
                qb.Tables = DB_TABLE_NOTES;
                qb.SetProjectionMap(notesProjectionMap);
                qb.AppendWhere(Note.ID + "=" + uri.PathSegments[1]);
                break;

            case NOTE_TITLE:
                qb.Tables = DB_TABLE_NOTES;
                qb.SetProjectionMap(notesProjectionMap);
                // TODO appendWhere + whereArgs instead (new string[] whereArgs = uri.getLas..)?
                qb.AppendWhere(Note.TITLE + " LIKE '" + uri.LastPathSegment +"'");
                break;

            default:
                throw new ArgumentException("Unknown URI " + uri);
            }

            // If no sort order is specified use the default
            string orderBy;
            if (TextUtils.IsEmpty(sortOrder)) {
              	    string defaultSortOrder;
                defaultSortOrder = Preferences.GetString(Preferences.Key.SORT_ORDER);
                if(defaultSortOrder.Equals("sort_title")) {
                    orderBy = Note.TITLE + " ASC";
                } else {
                    orderBy = Note.MODIFIED_DATE + " DESC";
                }
            } else {
                orderBy = sortOrder;
            }

            // Get the database and run the Query
            SQLiteDatabase db = dbHelper.ReadableDatabase;
            ICursor c = qb.Query(db, projection, selection, selectionArgs, null, null, orderBy);

            // Tell the cursor what uri to watch, so it knows when its source data changes
            c.SetNotificationUri(Context.ContentResolver, uri);
            return c;
        }