Cannot Update Row In Sqlite In Android But Not Throwing Any Error
Solution 1:
1). Check your Logcat
that you have no any errors.
2). Enable logging to see all SQL statements, which are you doing:
https://gist.github.com/davetrux/9741432
adb shell setprop log.tag.SQLiteLog V
adb shell setprop log.tag.SQLiteStatements V
adb shell stop
adb shell start
Or read this: https://stackoverflow.com/a/19152852/1796309 Or this: https://stackoverflow.com/a/6057886/1796309
Anyway, you need to check that you are doing correct SQL query.
3). If your query is well, but you still can't update your row, you need to do this:
3.1) Go to <android-sdk-dir>/platform-tools
3.2). Make sure that your current build is Debug
(not Release
, or you will get message adbd cannot run as root in production builds
).
I mean you should run your app through this button:
And run next commands:
./adb root
./adb shell
run-as com.mycompany.app //<----------- your applicationId from build.gradle
ls -l
drwxrwx--x u0_a88 u0_a88 2016-01-25 15:44 cache
drwx------ u0_a88 u0_a88 2016-01-25 15:25 code_cache
drwxrwx--x u0_a88 u0_a88 2016-01-25 15:44 databases //<----
drwxrwx--x u0_a88 u0_a88 2016-01-25 15:26 files
cd databases/
ls -l
-rw-rw---- u0_a88 u0_a88 172032 2016-01-25 15:45 <your-app>.db
-rw------- u0_a88 u0_a88 33344 2016-01-25 15:45 <your-app>.db-journal
chmod 777 -R <your-app>.db
exitexit
./adb pull /data/data/<your applicationId from build.gradle>/databases/<your-app>.db ~/projects/
After this, you will have copy of your SQLite database in ~/projects/
directory.
Open it using, for example this: http://sqlitebrowser.org/
Try to execute update query, which you can get from Logcat
.
You will see all SQL errors and you will be able to fix it very fast.
Good luck!
Solution 2:
You don't have a Boolean data type in sqlite use an Integer instead.
publicvoidmarkAsDone(int id){
db = getWritableDatabase();
ContentValues updatedData = newContentValues();
updatedData.put(COLUMN_DONE, 1);
String where = COLUMN_ID + "=?"
db.update(TABLE_NAME,updatedData,where,newString[]{String.valueOf(id)});
}
Solution 3:
I got the answer. Now I am updating boolean value of row in database like this in markAsDone method in DatabaseHelper.
updatedData.put(COLUMN_DONE, Boolean.TRUE);
Then I just changed it to
updatedData.put(COLUMN_DONE, String.valueOf(Boolean.TRUE));
I needed to parse boolean value to string.
Post a Comment for "Cannot Update Row In Sqlite In Android But Not Throwing Any Error"