2

I am trying to insert text messages from an inbox to a SQLite Database, but due to some special characters/symbols it doesn't insert properly.

I went through some question in Stackoverflow but nothing seems useful.

I got this code, but it is not working.

data.execSQL("INSERT INTO recor(text) VALUES('"+DatabaseUtils.sqlEscapeString(messag)+"')");

My database has only one field in it and am trying to insert details of messages along with it. I am putting the details (type, time, number, message) to a single string message and recor is my table name.

This is what I get as toast when I use a try catch loop.

Error is near:

"FROM":syntax error:INSERT INTO recor(text) VALUES("FROM 15555215556 Message:-MSG")

9
  • maybe it is just a typo and you mean record instead of recor ? Commented Jul 8, 2012 at 18:18
  • no 'recor' is my table name... Commented Jul 8, 2012 at 18:19
  • then maybe recor.text instead of recor(text) Commented Jul 8, 2012 at 18:20
  • is 'messag' also the correct variable? Commented Jul 8, 2012 at 18:20
  • @Jimpanzee: that would have been my next question :) Commented Jul 8, 2012 at 18:21

2 Answers 2

2

Uses the DatabaseAdapter's insert method instead. e.g.

ContentValues values = new ContentValues();
values.put(COLUMN_NAME, value);
dbAdapter.insert(TABLE_NAME, null, values);

it looks like your column name is 'text'? this must be wrong, as text is a keyword in sqlite.

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

2 Comments

i can't imagine that text can't be a column name in sqlite
yup me too @padde... i dont think text does much problem here... problem is when some symbols come it doesn't get inserted..
0

Your final SQL string seems to include two sets of quotes around the string you are inserting, so I assume the DatabaseUtils.sqlEscapeString method adds its own quotes around the string.

Therefore, your code should be:

data.execSQL("INSERT INTO recor(text) VALUES("+DatabaseUtils.sqlEscapeString(messag)+")");

Comments

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.