string - How to insert a text with single quots to sqlite db in android? -
i facing issue in inserting issue in inserting text single quotes in sqlite db in android. returning next error.
06-21 15:21:55.644: e/androidruntime(16328): android.database.sqlite.sqliteexception: near "re": syntax error (code 1): , while compiling: select * tbl_chathistory chat_date = '1.403344315631e12' , chat_time = '1.403344315635e12' , chat_text = 'you're'
please help.
**************** edited *************************
public boolean checkchatexists(string date, string time, string chat) { boolean result = false; string selectquery = "select * tbl_chathistory chat_date = '"+date+"' , chat_time = '"+time+"' , chat_text = '"+chat+"'"; sqlitedatabase database = this.getwritabledatabase(); cursor cursor = database.rawquery(selectquery, null); if (cursor.movetofirst()) { result = true; } else { result = false; } cursor.close(); homecoming result; }
in sql string literals can escape '
''
.
it improve utilize parametrized queries. replace string literals ?
, provide values in bindargs
array. example:
string selectquery = "select * tbl_chathistory chat_date = ? , chat_time = ? , chat_text = ?"; cursor cursor = database.rawquery(selectquery, new string[] { date, time, chat });
android string sqlite
No comments:
Post a Comment