Search code examples
androidsqliteandroid-contentprovider

Why would a ContentProvider query which should return results return 0 rows?


I use a ContentProvider in my app. I'm attempting to do a query with the following code:

String where = MyColumns.USER_ID + " = ?"
        + " and " + MyColumns.DAY + " >= ?"
        + " and " + MyColumns.DAY + " < ?"
        + " and " + MyColumns.STATUS + " <> ?";

Cursor mycursor = getContentResolver().query(DbDefinitions.URI_MY_TABLE,
                    MyColumns.getDisplayColumns(),
                    where,
                    new String[] {
                        String.valueOf(params.mUserId),
                        String.valueOf(today.getTimeInMillis()/1000L),
                        String.valueOf(tomorrow.getTimeInMillis()/1000L),
                        DbDefinitions.STATE_DELETING
                    },
                    MyColumns.DAY + " asc");

Debugging through the ContentProvider, the Cursor object contains the following values for mQuery.mSql and mQuery.mBindArgs:

SELECT _id, user_id, column3, day, column5, status, column7, column8, column9
FROM my_table
WHERE user_id = ? and day >= ? and day < ? and status <> ? ORDER BY day asc;

[1691, 1386576000, 1386662400, STATE_DELETING]

The mCount is 0.

However, if I copy and paste this query into terminal (connected to the db), I get a row back:

3|1691|6|1386604595|1386597600|STATE_OK||some test text|14

Yes, they are hitting the same database. All of the other data in the database shows up in my app. I've just added this 1 table and the data from this table alone is not coming back in queries.

There are no exceptions during the query.

Ideas?


Solution

  • I figure out the problem. When I created the table, I did not specify a column type on the "day" column. Apparently, sqlite3 lets you get away with this. I assume it defaults to a text column

    ..., day not null, ...