Search code examples
javaandroidsqlandroid-contentprovider

How to query a ContentProvider for value that is not null on Android?


I have a ContentProvider, and I would like to make a query that returns the rows of a table where the values of a specific column is not null. In SQL you can use the column IS NOT NULL, but I cannot figure out what is the equivalent statement in case of ContentProviders.

I have tried so far:

  1. SQL like syntax.

    getContentProvider().query(uri,
            null,
            Contract.Table.COLUMN + " is not null",
            null,
            null);
    
  2. SQL like syntax with selection arguments.

    getContentProvider().query(uri,
            null,
            Contract.Table.COLUMN + " is not null",
            new String[0],
            null);
    
  3. Is on equal with real null value.

    getContentProvider().query(uri,
            null,
            Contract.Table.COLUMN + " != ?",
            new String[]{null},
            null);
    
  4. Is not equal with "null" string.

    getContentProvider().query(uri,
            null,
            Contract.Table.COLUMN + " != ?",
            new String[]{"null"},
            null);
    

Thank you!


Solution

  • ContentProviders are not standardized. Each of them may interpret query parameters in any given way. (In fact, most content providers only use a few parameters at all.)