0

I have been struggling to get data from my sqlite database for the last 4 days because for some reason the queries I am using do not work. Here is my function:

public void updateBadgesRecord(int rowId, String id, String name, String description, String image_url, String club_id, String created_at) 
{

    Log.i("image_url in updateBadgesRecord", image_url);
    ContentValues args = new ContentValues();
    if(id != null){
    args.put(KEY_BADGES_ID, id);
    }
    if(name != null){
    args.put(KEY_BADGES_NAME, name);
    }
    if(description != null){
    args.put(KEY_BADGES_DESCRIPTION, description);
    }
    if(image_url != null){
    args.put(KEY_BADGES_IMAGEURL, image_url);
    }
    if(club_id != null){
    args.put(KEY_BADGES_CLUBID, club_id);
    }
    if(created_at != null){
    args.put(KEY_BADGES_CREATEDAT, created_at);
    }


    //return db.update(DATABASE_TABLE_BADGES, args, KEY_ROWID + "=" + rowId, null) > 0;
    db.update(DATABASE_TABLE_BADGES, args, KEY_ROWID + "= ?",  new String[]{String.valueOf(rowId)});

}

Running this method appears to produce no errors.

But when I try and get all the data from this table:

public Cursor getBadgeRecord(int rowId) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE_BADGES, new String[] {KEY_ROWID,
            KEY_BADGES_ID, KEY_BADGES_NAME, KEY_BADGES_DESCRIPTION, KEY_BADGES_IMAGEURL, KEY_BADGES_CLUBID, KEY_BADGES_CREATEDAT}, 
            KEY_ROWID + "=" + rowId, null, null, null, null, null);

    if (mCursor != null) {
        mCursor.moveToFirst();
    }

    int columnIndex = mCursor.getColumnIndex("image_url");
    Log.i("mCursor", columnIndex+"<--- column index" + " | row id"+ rowId);
    return mCursor;
}

I get a Cursor record count of 0. What could be causing this? I have tried various different queries that should work so I am now at the point of giving up and not storing data with an sqlite database. Please help me.

4

1 回答 1

2

db.update(...)更新现有行。你可能想做db.insert(...) 链接

于 2013-05-26T11:30:35.667 回答