title: How to use selection args to query specific rows from a contentprovider in android
body: <p>i have constructed a basic content provider that stores SMS messages for learning purposes, so far i can read(without selection args), insert, update and delete.</p>
  
  <p>However i have been stumped trying to figure out how to format the selection args for the WHERE clause in my provider:</p>
  
  <p>Basicly my application needs to search for a specific timestamp (in long format) and return its _id</p>
  
  <p>say your database has an entry like this that your trying to access:</p>
  
  <p>2|1|1410293471300|test type 1||testing|0</p>
  
  <p>and the entire database looks like this:</p>
  
  <p>_id|CLIENTTRXID|CREATED_AT|TYPE|MESSAGEPRIO|MESSAGE|ACCEPTED</p>
  
  <p>1|1|1410293471000|test type 1||testing|0</p>
  
  <p>2|1|1410293471300|test type 1||testing|0</p>
  
  <p>3|1|1410293471600|test type 1||testing|0</p>
  
  <p>in sql the query would be 
  "select _id from alerts where CREATED_AT=1410293471300;"</p>
  
  <p>the code i was hoping would do the equivalent:</p>
  
  <pre><code>//normally i would get the string dynamically but to make it equal to the sql
  String date = "1410293471300";
  String[] selectionArgs = new String[]{ date };
  
  Cursor cursor = getContext().getContentResolver().query(AlertContract.CONTENT_URI, null, AlertContract.Column.CREATED_AT, selectionArgs, AlertContract.DEFAULT_SORT);
  </code></pre>
  
  <p>seems to always produce the following error no matter what i try as selectionArgs</p>
  
  <pre><code>Exception caught﹕ Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
  </code></pre>
  
  <p>here is the query method of my contentprovider:</p>
  
  <pre><code>    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
      SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
      qb.setTables( AlertContract.TABLE);
  
      switch (sURIMatcher.match(uri)) {
          case AlertContract.STATUS_DIR:
              break;
          case AlertContract.STATUS_ITEM:
              qb.appendWhere(AlertContract.Column.ID + "=" + uri.getLastPathSegment());
              break;
          default:
              throw new IllegalArgumentException( "illegal uri: " + uri);
      }
      String orderBy = (TextUtils.isEmpty(sortOrder)) ? AlertContract.DEFAULT_SORT : sortOrder;
      SQLiteDatabase db = dbHelper.getReadableDatabase();
      Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
  
      //register for uri changes
      cursor.setNotificationUri(getContext().getContentResolver(), uri);
  
      Log.d(TAG, "queried records: "+cursor.getCount());
      return cursor;
  }
  </code></pre>
  
  <p>Presumably im missing something extremely obvious, and will feel quite silly for having posted this question.</p>
  
  <p>But for the moment i would very much appreciate any help, as i am quite stumped.</p>