AW: [android-developers] Re: How does a Cursor work?

2008-12-12 Thread visionera gmbh
hi satya,
great comments! thanx for the information. 
it might be a clever alternative to implement the count(*) functionality by 
means of a prepared (compiled) statement, if you need the number of results.
the cursor will do the iteration job, the prep statement the fast initial 
counting.

marcus





Von: Satya Komatineni satya.komatin...@gmail.com
An: android-develop...@googlegroups..com
Gesendet: Donnerstag, den 11. Dezember 2008, 17:45:32 Uhr
Betreff: [android-developers] Re: How does a Cursor work?


Taisa,
Hopefully you have found some answers on this since you have posted.
If you did find any numbers indicating one way or the other, I would
like to know.

I looked at some source code of Android to see what is under the hood.
Here are some thoughts based on what I saw.

The Cursor object is an interface that is allowing both forward and
backward movement. In addition the interface also supports the
getCount(). Both seem to indicate that all rows might be read
upfront or at the earliest moment.

The implementation of this cursor interface using SQLiteCursor seem to
be using a windowing concept to read a set of rows depending on the
window you are in. So it is possible that moving forward in a cursor
should be pretty efficient.

However calling getCount() may force a complete read of the internal cursor.

So semantics of the Cursor interface is not delineating a clear
forward only and random access semantics. But I believe the
implementation is efficient enough if you follow the forward only
semantics. This implies reading getCount early on is not a good
thing if you are trying to read every row and do something with it.

It may not be a bad idea to wrap the cursor interface and don't expose
the getCount() and random movement methods and make the contract
explicit to the clients.

Hope that helps.

On Mon, Dec 8, 2008 at 1:51 PM, Taísa Cristina taisa.san...@gmail.com wrote:
 Hi,

 when a database query retrieves a Cursor, what does it have in fact? I mean,
 does it have the whole result set in memory or keep a kind of pointer to
 each result row, and when I do cursor.moveToNext() it points to the next
 row? Or anything else?

 I need to deal with a long list of data, and I really wanna know how
 efficient is a Cursor retrieved from a database query.

 Thanks,
 Taísa


 




  
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



AW: [android-developers] Re: Cannot delete rows from sqlite database

2008-12-04 Thread visionera gmbh
hi,

you have to use setTransactionSuccessful() as in

int nRows = 0;
mDb.beginTransaction();
try {
  nRows = mDb.delete(mytable, KEY_ITEM + = + rowId,null);
  mDb.setTransactionSuccessful(); // implies commit at endTransaction
} catch( SQLException anyDbError }
  // error logging ...
} finally {
  mDb.endTransaction();
}
return nRows  0;


worx for me
marcus




Von: Jack C. Holt [EMAIL PROTECTED]
An: Android Developers android-developers@googlegroups.com
Gesendet: Donnerstag, den 4. Dezember 2008, 19:03:19 Uhr
Betreff: [android-developers] Re: Cannot delete rows from sqlite database


See
http://code.google.com/android/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction()

On Nov 17, 3:28 pm, techvd [EMAIL PROTECTED] wrote:
 Hi,

 I'm having a strange issue deleting rows from a sqlite database.
 Here's the code snippet:

 mDb.beginTransaction();
 int nRows = mDb..delete(mytable, KEY_ITEM + = + rowId,
 null);
 mDb.endTransaction();
 return nRows  0;

 The database is opened for write. The code above executes perfectly;
 it even returns the number of rows deleted. However, the rows are
 still in the table (even after I exit the app restart, etc.). Am I
 missing anything here. The rest of the code is boilerplate and I can
 read the data from the tables fine.

 Thanks!


  
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---