I need to store a record using rawQuery()
method, because I want to insert the current date and time (datetime()
), but I also need to insert strings that contain quotes.
So I wrote this code:
String sql="INSERT INTO sms VALUES ( null, ?1, ?2, ?3, datetime())";
dbw.rawQuery(sql, new String[]{str1,str2,str3});
But it doesn't store anything... what's wrong?
[EDIT]
In this way I don't get errors, but the record is not inserted.
String mitt="mitt", dest="dest", text="text";
String sql="INSERT INTO sms VALUES ( null, ?, ?, ?, datetime('NOW'))";
dbw.rawQuery(sql, new String[]{mitt,dest,text});
At this moment, the only method that works to insert a record (with quotes problem) is execSQL(String s)
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…