like operator syntax in sqlite with android -
i'm developing android , need query sqlite using operator , variables.
the piece of code try modify is, implementation of database present @ this link.
so, i'm trying query on table created in link in order select name table. i'm doing this:
cursor c = sampledb.rawquery("select firstname, age " + sample_table_name + " where" +field+ " %"+search+"%" , null);
where field , search 2 variable defined above in way:
final string field = "lastname"; final string search = "makam";
if execute app in output, should see row name , age have selected in query.but, obtain nothing!!!
the logcat of eclipse
shows :
sqlite returned: error code = 1,msg = near "like": syntax error.
but i'm pretty sure syntax it' s correct. me?
use way:
cursor c = sampledb.rawquery("select firstname, age " + sample_table_name + " " +field+ " '%"+search+"%'" , null);
edited: create function
public cursor getsearch(string sample_table_name, string field, string search) { sqlitedatabase sampledb = this.getreadabledatabase(); cursor c = sampledb.rawquery("select firstname, age " + sample_table_name + " " + field + " '%" + search + "%'", null); return c; }
Comments
Post a Comment