0

Well I am trying to update a value in database false to true;

this is my code

public void updatecheck( int id){
     mDb = mDbHelper.getWritableDatabase();

       ContentValues newValues = new ContentValues();
       newValues.put("check", true);
       mDb.update(channel, newValues, "id"+" = ?", new String [] {String.valueOf(id)}); 

}

But I am taking this error,

02-28 15:15:37.515: E/AndroidRuntime(5539): android.database.sqlite.SQLiteException: near "check": syntax error (code 1): , while compiling: UPDATE Genelkultur2012 SET check=? WHERE id = ?

SOLVED:

new codes

 ContentValues newValues = new ContentValues();
         newValues.put("tamam", true);
         mDb.update(channel, newValues, "id"+" = ?", new String [] {String.valueOf(id)}); 

2 Answers 2

3

CHECK is a reserved keyword in SQL. Either rename the column or quote it in backticks.

Sign up to request clarification or add additional context in comments.

Comments

1

newValues.put("check", true);

You're trying to store true, a Boolean data type, which is not supported by SQLite. You'll instead have to store them in one of the following types:

  1. NULL. The value is a NULL value.
  2. INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
  3. REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
  4. TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
  5. BLOB. The value is a blob of data, stored exactly as it was input.

I'd suggest to store Boolean members as 0 or 1. More info here: http://www.sqlite.org/datatype3.html

3 Comments

it looks normal. there is no problem with "true"
Actually you were right because boolean makes some problem. I have changed boolean to 0,1 but as a text
So a boolean data type was indeed causing issues? And oh what type?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.