android - SQL cursor error -


i have been using notepad sqlhelper (notesdbadapter) model, of works, doesn't. can cursor 'fetchallrecords() crashes if try call passing argument , using 'where'. argument passed cursor fails. code in activity;

    public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.listselectedfile);          //button id clicked in previous activity     bundle bundle = getintent().getextras();     int btnid = bundle.getint("buttonid");     toast.maketext(this, "buttonid selected in main:= " + btnid, toast.length_long) .show();       mdbhelper = new sectionsdbadapter(this);     mdbhelper.open();     filldata();  }       private void filldata() {         // of notes database , create item list         //cursor c = mdbhelper.fetchallrecords();       <=== works fine         cursor c = mdbhelper.fetchrecordsbysource("uk"); <=== fails in dbhelper         startmanagingcursor(c);          string[] = new string[] { sectionsdbadapter.key_desc };         //string[] = new string[] { sectionsdbadapter.key_source }; <=== can fetch column table         int[] = new int[] { r.id.tv_full_width };  //the r.id.xxx= view in .xml file          // create array adapter , set display using our row         simplecursoradapter records =             new simplecursoradapter(this, r.layout.section_row_full_width, c, from, to);  //the .xml file containing r.id.xxxx         setlistadapter(records);     } 

in dbhelper; call works , returns full table;

    public cursor fetchallrecords() {      return mdb.query(database_table, new string[] {     key_rowid, key_desc, key_depth, key_tweb,      key_bf1, key_tf1, key_bf2, key_tf2,      key_imajor, key_iminor,      key_plmajor, key_plminor,      key_jtorsion, key_area,       key_warping, key_cychannel,      key_shape, key_source,      key_units},null, null, null, null, null); } 

this call fails on cursor (the argument passed successfully);

    public cursor fetchrecordsbysource(string source) throws sqlexception {     log.v("in fetchrecordsbysource", "source = " +source);            cursor mcursor = mdb.query(true, database_table, new string[] {     key_rowid, key_desc}, key_source + " = " + source, null, null, null, null, null);     if (mcursor != null) {         mcursor.movetofirst();     }     return mcursor; } 

there nothing obvious me in eclipse debug, but, newby, have not got necessary perspective.

can spot error?

in code have, if source non-numeric value, needs surrounded single quotes, this:

key_rowid, key_desc}, key_source + " = '" + source + "'", null, null, null, null, null) 

but better off if pass filter arguments ?; avoids (among other things) sql injection attacks

key_rowid, key_desc}, key_source + " = ?", new string[] { source }, null, null, null, null) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -