title: Android: Content resolver query returning 0 rows when it ought not to
body: <pre><code>Cursor cursor = resolver.query(
      Data.CONTENT_URI,
      DataQuery.PROJECTION,
      DataQuery.SELECTION,
      new String[] {String.valueOf(rawContactId)},
      null);
  </code></pre>
  
  <p>With PROJECTION being: </p>
  
  <pre><code>public static final String[] PROJECTION = new String[] {
      Data._ID,
      Data.MIMETYPE,
      Data.DATA1,
      Data.DATA2,
      Data.DATA3};
  </code></pre>
  
  <p>and SELECTION being: </p>
  
  <p><code>public static final String SELECTION = Data.RAW_CONTACT_ID + "=?";</code></p>
  
  <p>The rawcontactId does return values, I've made logs to check. To give it some context I'm working with Account sync. The goal here is for it to find the data columns for existing contacts and writing over them with any new data. I'm working from the following sample code provided by android: <a href="http://developer.android.com/resources/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.html" rel="nofollow">http://developer.android.com/resources/samples/SampleSyncAdapter/src/com/example/android/samplesync/platform/ContactManager.html</a></p>
  
  <p>To summarize my problem, I have two contacts via this synced account which are added without any problems, but are not being able to be updated. Anyone have experience with this? Thanks.</p>
  
  <p>EDIT: Here is my rawContact returning method</p>
  
  <pre><code>private static long lookupRawContact(ContentResolver resolver, String username) {
      Log.e("Looking up Raw Contact", username);
      long authorId = 0;
      Cursor cursor = resolver.query(
          Data.CONTENT_URI,
          UserIdQuery.PROJECTION,
          UserIdQuery.SELECTION,
          new String[] {username},
          null);
  
      try {
          if(cursor != null &amp;&amp; cursor.moveToFirst()) {
              authorId = cursor.getLong(UserIdQuery.COLUMN_ID);
          }
      } finally {
          if(cursor != null) {
              cursor.close();
          }
      }
      return authorId;
  }
  </code></pre>
  
  <p>The numbers I get back are like 3061. Here is the UserIdQuery class:</p>
  
  <pre><code>final private static class UserIdQuery {
  
      private UserIdQuery() {
  
      }
  
      public final static String[] PROJECTION = new String[] {RawContacts._ID};
      public final static int COLUMN_ID = 0;
      public static final String SELECTION = RawContacts.ACCOUNT_TYPE + "='" + 
          "com.tagapp.android" + "' AND " + RawContacts.SOURCE_ID + "=?";
  
  }
  </code></pre>
  
  <p>And here is my constructor for a ContactSyncOperations class being used to add a new contact. The source id here is a username, the same as I call in my SELECTION argument.</p>
  
  <pre><code>public ContactSyncOperations(Context context, String username,
          String accountName, BatchOperationForSync batchOperation) {
  
      this(context, batchOperation);
      mBackReference = mBatchOperation.size();
      mIsNewContact = true;
      mValues.put(RawContacts.SOURCE_ID, username);
      mValues.put(RawContacts.ACCOUNT_TYPE, "com.tagapp.android");
      mValues.put(RawContacts.ACCOUNT_NAME, accountName);
      mBuilder = newInsertCpo(RawContacts.CONTENT_URI, true).withValues(mValues);
      mBatchOperation.add(mBuilder.build());
  }
  </code></pre>
  
  <p>Thanks!</p>