• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps doubt in getString() and getcolumnindex()

Hi frnds...am new to android...i hav a doubt...
Hi friends...
i have a query lik ths...

"select
item.a,item.b,customer.a,customer.b from item,customer
where (some condition)"

can i retrieve data from ths query like ths....
cursor.getString(1);
cursor.getString(2);

will it create any problems?

how is it differentiate with getColumnindex();

please can any1 explain?
 
Cursor maintains a Collection object of columns, when you do getColumnIndex it returns you something from -1..n where 'n' number of columns in your query (in your case that'd be 4). -1 is returned if column name does not exist.

yes you can do cursor.getString(1), so what's the problem? readability, you may add another column in middle of select and not change the access order :-) i.e. readability and long term maintenance.
 
Thanks friend.....
I understud it partially....
I am retrieving data from database(everywher) in this format(cursor.getString(5) etc..
The problem i am facing is...
I have a item "stock" variable in one class which will b updated to db frequently according to ma prgm logic....
when i am retrieving this stock to another class where i need to check some condition....
it s simultaneosly changing the value.....
sometimes it giving updated value sometimes it is not.....am sure that am retrieving from d exact place i want but the thing is it s always geting interchnged...
 
Read up on CursorLoader. You need the cursor to refresh after it is changed. You may have cases where the cursor is refreshing before the new data is actually saved.

Thanks friend.....
I understud it partially....
I am retrieving data from database(everywher) in this format(cursor.getString(5) etc..
The problem i am facing is...
I have a item "stock" variable in one class which will b updated to db frequently according to ma prgm logic....
when i am retrieving this stock to another class where i need to check some condition....
it s simultaneosly changing the value.....
sometimes it giving updated value sometimes it is not.....am sure that am retrieving from d exact place i want but the thing is it s always geting interchnged...
 
Back
Top Bottom