Reputation: 15
I try hard to delete a row in my table:
String createQuery3 = "CREATE TABLE foto" +
"(_id integer primary key autoincrement," +
"_id_visita integer, nome_immagine TEXT, nome_immagine_resampled TEXT, " +
"commento_foto TEXT," + "commento_foto_resampled TEXT," +
"FOREIGN KEY(_id_visita) REFERENCES visite (_id));";
through line:
public void cancellaFoto(Long idPaziente, String nomeFoto) {
// TODO Auto-generated method stub
databaseConnector.open(); // open the database
database = databaseConnector.getOpenDatabase();
Log.d(TAG, "FOTO SINGOLA DA CANCELLARE ID_Paziente: " + idPaziente);
Log.d(TAG, "FOTO SINGOLA DA CANCELLARE nomeFoto: " + nomeFoto);
database.delete("foto", "nome_immagine=" + nomeFoto , null) ;
Log.d(TAG, "FOTO SINGOLA DA CANCELLATA" + nomeFoto);
databaseConnector.close(); // close the database
}
but nothing. the risult is:
12-21 09:55:41.961: E/AndroidRuntime(11373): at java.lang.Thread.run(Thread.java:841)
12-21 09:55:41.961: E/AndroidRuntime(11373): Caused by: android.database.sqlite.SQLiteException: unrecognized token: "1419152123776.png" (code 1): , while compiling: DELETE FROM foto WHERE nome_immagine=1419152123776.png;
12-21 09:55:41.961: E/AndroidRuntime(11373): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
but the photo name is correct:
12-21 09:55:41.941: D/FotoDatabaseInterface(11373): FOTO SINGOLA DA CANCELLARE ID_Paziente: 2
12-21 09:55:41.941: D/FotoDatabaseInterface(11373): FOTO SINGOLA DA CANCELLARE nomeFoto: 1419152123776.png
Any Idea? Thanks
Upvotes: 0
Views: 464
Reputation: 152817
In SQL, string literals such as '1419152123776.png'
must be quoted with single quotes.
It's better to use ?
placeholders and variable binding though:
database.delete("foto", "nome_immagine=?", new String[] { nomeFoto }) ;
Upvotes: 3