Android Content provider Cursor returns 0 -


i have looked @ couple of days , can't work out why content provider return 0 using arguments passing it.

here's contentresolver code:

string[] expenditureprojection = {             businessopsdatabase.col_expend_cat_id,             businessopsdatabase.col_expend_date,             businessopsdatabase.col_expend_amount,             businessopsdatabase.col_expend_desc,             businessopsdatabase.col_sterling_exchange,             businessopsdatabase.col_company_id,             businessopsdatabase.currency_id,             businessopsdatabase.col_mod_date     };     // defines string contain selection clause     string selectionclause = null;      // array contain selection arguments     string[] selectionargs = {expend_id.trim()};      selectionclause = businessopsexpenditureprovider.expenditure_id + "=?";      log.d(tag, expend_id+" selected list.");      cursor expendcursor = getcontentresolver().query(             businessopsexpenditureprovider.content_uri, expenditureprojection, selectionclause, selectionargs, null);     if (null == expendcursor) {         log.d(tag, "expenditure cursor: null");     } else if (expendcursor.getcount() < 1) {         log.d(tag,"expenditure cursor: search unsuccessful: "+expendcursor.getcount());     } else {         log.d(tag,"expenditure cursor: contains results");          int i=0;         expendcursor.movetofirst();         // loop through cursor , populate country array         while (expendcursor.isafterlast() == false)         {             expend_date_edit.settext(expendcursor.getstring(1));             expend_amount_edit.settext(expendcursor.getstring(3));             expend_desc_edit.settext(expendcursor.getstring(4));              i++;             expendcursor.movetonext();         }     } 

here's content provider query method:

@override public cursor query(uri uri, string[] projection, string selection,                     string[] selectionargs, string sortorder) {     sqlitedatabase db = mdb.getwritabledatabase();      // convenience class build query     sqlitequerybuilder qb = new sqlitequerybuilder();      qb.settables(businessopsdatabase.table_expenditure);      switch (surimatcher.match(uri)) {         case expenditure:             if(selection != null && selectionargs != null){                 //values.get("company_contact");             string segment = uri.getlastpathsegment();             log.d(tag, "last path segment: "+ segment);             string whereclause = businessopsdatabase.expenditure_id + "="+ selectionargs[0];             log.d(tag, "where clause: "+whereclause);             }             break;         case expenditure_id:             // if request individual status, limit result set id             qb.appendwhere(businessopsdatabase.expenditure_id + "=" + uri.getlastpathsegment());             break;         default:             throw new illegalargumentexception("unsupported uri: " + uri);     }       // query underlying database     cursor c = qb.query(db, projection, selection, selectionargs, null, null, null);      // notify context's contentresolver if cursor result set changes     c.setnotificationuri(getcontext().getcontentresolver(), uri);      // return cursor result set     return c; } 

i'm printing whereclause log , see '_id=3' should fine because have pulled off copy of sqlite database , can see expenditure table has _id 3 row in it. ideas?

what epic problem has been. found error in contentresolver code.

selectionclause = businessopsexpenditureprovider.expenditure_id + "=?"; 

i using expenditure_id variable provider rather database class. line reads.

selectionclause = businessopsdatabase.expenditure_id + "=?"; 

and works!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -