android - SQLite returning an empty cursor even if the data exist -


i using sqlite in android application store data. each time when start application data server , store in client.the existing data updates , new data inserts db.

but in many case blank cursor db when access existing item db querying "select * table itemid = x". if extract db device/emulator before updating it, can see data exist in db.

this problem happen if many data server , compare existing data. comparison done in loop , each time cursor , close before moving next comparison.

try{ int[] ids = getids(); // required ids for(i =0; i<ids.length, i++) { //  cursor c = db.rawquery("select * table id = "+ids[i]); if(c == null || (c != null && c.getcount() == 0)) {  // new data }else if(c.getcount()>0) { // existing data } } }catch(exception e){     e.printstacktrace(); }finally{ if(c!=null && !c.isclosed()) { c.close() } c = null; } 

i noticed, 1st time cursor data after blank cursor.

after query, if cursor contains more 0 rows, section:

{ // existing data } 

will executed "size" times. if cursor null or not contains row, section:

{  // new data } 

will executed "size" times.

this because query static. making, each iteration in loop, same query. if want should put call rawquery method outside of loop.

moreover:

if(c == null || c != null && c.getcount() == 0) 

is equivalent to:

if(c == null || c.getcount() == 0) 

the if condition @ line:

else if(c.getcount()>0) 

can omitted.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -