Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No such column" when running update on SQLite

I'm trying to update a row in my database. Here is the code I am trying to use to update:

public void addFBComments(int id){ 
    SQLiteDatabase db = this.getWritableDatabase(); 
    String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id;

    db.execSQL(query);
}

When I run the command, it throws this error:

08-18 15:42:10.145: E/AndroidRuntime(10493): FATAL EXCEPTION: Thread-922
08-18 15:42:10.145: E/AndroidRuntime(10493): android.database.sqlite.SQLiteException: no such column: HELLO (code 1): , while compiling: UPDATE fb_feed SET fb_comments= HELLO  WHERE _id=3

Here is the TABLE_FB_FEED:

private static final String TABLE_FB_FEED_CREATE = "create table " + TABLE_FB_FEED + 
" ("
        + COL_FB_ID + " integer primary key autoincrement not null," 
        + COL_FB_MESSAGE + " text," 
        + COL_FB_CAPTION + " text,"
        + COL_FB_POSTER_ID + " text,"
        + COL_FB_POST_ID + " text,"
        + COL_FB_LIKES + " text,"
        + COL_FB_POSTER_NAME + " text,"
        + COL_FB_COMMENTS + " text," // this is the column i want to update
        + COL_FB_LIKES_NUM + " text,"
        + COL_FB_TIMESTAMP + " text,"
        + COL_FB_PROFILE_PICTURE_URI + " text,"
        + COL_FB_PICTURE_URI + " text," 
        + COL_FB_NAME + " text," 
        + COL_FB_PREVIOUS_PAGE_URI + " text,"
        + COL_FB_NEXT_PAGE_URI + " text," 
        + COL_FB_POST_TYPE + " text," 
        + COL_FB_LINK_NAME + " text," 
        + COL_FB_COMMENTS_NUM + " text," 
        + COL_FB_STORY + " text," 
        + COL_FB_DESCRIPTION + " text,"
        + COL_FB_COMMENTS_BEFORE + " text,"
        + COL_FB_COMMENTS_AFTER + " text,"
        + COL_FB_LIKES_PROFILE_PIC + " text,"
        + COL_FB_COMMENTS_PROFILE_PIC + " text);";

Why is it throwing the query? I thought I was doing everything correctly.

like image 694
user3776241 Avatar asked Jun 20 '26 20:06

user3776241


1 Answers

in your code you need to add single quotes:

String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
    +"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id

or

String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
    +"='HELLO' WHERE " + COL_FB_ID+"="+id

this is another example

"UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=myidValue");
like image 56
Jorgesys Avatar answered Jun 23 '26 11:06

Jorgesys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!