I try to update database table and this is my code:
public void updatefiletable(String filename, String v1, String v2){
AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(this);
SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(AndroidOpenDbHelper.COLLUMN_NAME_FILE_CLOUD, v1);
values.put(AndroidOpenDbHelper.COLLUMN_NAME_FILE_DATE_UPLOADING, v2);
sqliteDatabase.update(AndroidOpenDbHelper.TABLE_FILE, values, AndroidOpenDbHelper.COLUMN_NAME_FILE_NAME+"="+filename, null);
sqliteDatabase.close();
}
when I call my method with file_name values egal priv_priv_secondfile_2012-06-15.pdf I get that in the logcat:
android.database.sqlite.SQLiteException: unrecognized token: "15.pdf": ,
while compiling: UPDATE file_table SET file_cloud_column=?,
file_date_upload_column=?
WHERE file_name_column=priv_priv_secondfile_2012-06-15.pdf
how can I fix it?
You need to escape the filename parameter. The punctuation in the filename is confusing SQLite. You could do it by surrounding the filename in 'single quotes'
in the string you pass in to SQLite, but it's cleaner and safer to pass it as a separate argument, like this:
sqliteDatabase.update(AndroidOpenDbHelper.TABLE_FILE, values,
AndroidOpenDbHelper.COLUMN_NAME_FILE_NAME+"=?", new String[] {filename});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With