JasonMP wrote:
> I use a do/while that runs through one of my tables based on the
> number of entries on another table and makes changes.
>
> Example:
>
> Integer i = 1;
>
> Cursor c = db.querryFunction();
> Integer rowCount = c.getCount();
>
> do{
> //does work on the database
> db.updateRow(table, args, KEY_ROWID + "=" + i, null);
> i++;
> }
> while(i <= rowCount);
>
>
> if my autoincrements skips numbers then I can get an error trying to
> update a row that doesn't exist.
I wouldn't recommend that structure in general. Making assumptions on
the nature of primary keys always struck me as dangerous.
AUTOINCREMENT is not going to be reliable for your situation, in any case:
"Note that 'monotonically increasing' does not imply that the ROWID
always increases by exactly one. One is the usual increment. However, if
an insert fails due to (for example) a uniqueness constraint, the ROWID
of the failed insertion attempt might not be reused on subsequent
inserts, resulting in gaps in the ROWID sequence. AUTOINCREMENT
guarantees that automatically chosen ROWIDs will be increasing but not
that they will be sequential."
(from http://www.sqlite.org/autoinc.html)
Personally, I'd avoid making the assumptions on the primary key values,
and do your updates based on real primary keys. But, that's just me.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android Training in Germany, 18-22 January 2010: http://bignerdranch.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
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