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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -