views:

27

answers:

0

Hi,

I have created a custom content provider in application A and have another application B access this content provider in A. Below are my code snippets:

In content provider in application A:

public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    int table = um.match(uri);
    SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();;

    // configure where to query from
    if (table == MYKEYS || table == MYKEY_ID) {
        sqlBuilder.setTables(DATABASE_TABLE_MY);
        if (table == MYKEY_ID)
            sqlBuilder.appendWhere(
            _ID + " = " + uri.getPathSegments().get(1)); 
    }

    else if (table == FDKEYS || table == FDKEY_ID) {
        sqlBuilder.setTables(DATABASE_TABLE_FD);
        if (table == FDKEY_ID)
            sqlBuilder.appendWhere(
            _ID + " = " + uri.getPathSegments().get(1));
    }

    else 
        throw new IllegalArgumentException("Unknown URI: " + uri);

    if (sortOrder==null || sortOrder=="")
        sortOrder = DEFAULT_SORT_ORDER;

    // query
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
    Cursor c = sqlBuilder.query(
               db, 
               projection, 
               selection, 
               selectionArgs, 
               null, 
               null, 
               sortOrder);

    //register to watch a content URI for changes
    c.setNotificationUri(getContext().getContentResolv er(), uri);

    return c;
}

This is how I declare my content provider in application A manifest file:

<provider android:name=".KeysProvider"
android:authorities="com.android.keychain.keysprovider"/>

This is how I make a query in application B:

String[] whereArgs = new String[]{"Private Key"};
Cursor c = managedQuery(MYTABLE_URI, null, "name", whereArgs, null); 

When I run the the code for application B, I have the following errors:

07-02 12:53:58.153: ERROR/DatabaseUtils(9195): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x126558

I really don't know what's wrong here. It works fine when I tried to access this same content provider from within application A. Also, looking from the log, it seems that from application B (at managedQuery line), it is able to go to this content provider in application A (KeysProvider) but dies when trying to make a query (at line: Cursor c = sqlBuilder.query ... ). Anyone knows what's the problem here?

Thanks very much in advance

related questions