java - How to create sequential number but not ROWID in Android SQLite database? -


i working on app contains android sqlite database. add , delete rows in database. when delete row, based on rowid. found out, despite delete row, rowid remains. example if have 3 rows in database , delete 2nd row, third row not change 2 remains 3. if add row, 4.

so question is, how when delete row, , add new 1 number of added row equal deleted row. example if delete first row, database show me next other rows 1,2,3... , not 2,3,4...

sorry, maybe little bit complicated, hope makes sense.

here code:

public hotornot open() throws sqlexception{ ourhelper = new dbhelper(ourcontext); ourdatabase = ourhelper.getwritabledatabase(); return this; } public void close(){ ourhelper.close(); }  public long createentry(string name, string hotness) { // todo auto-generated method stub contentvalues cv = new contentvalues(); cv.put(key_name, name); cv.put(key_hotness, hotness); return ourdatabase.insert(database_table, null, cv); }  public string getdata() { // todo auto-generated method stub string[] columns = new string[]{ key_rowid, key_name, key_hotness}; cursor c = ourdatabase.query(database_table, columns, null, null, null, null, null); string result = "";  int irow = c.getcolumnindex(key_rowid); int iname = c.getcolumnindex(key_name); int ihotness = c.getcolumnindex(key_hotness);  (c.movetofirst(); !c.isafterlast(); c.movetonext()){     result = result + c.getstring(irow) + " " + c.getstring(iname) + " " + c.getstring(ihotness) + "\n"; } return result; }  public string getname(long l) throws sqlexception{ // todo auto-generated method stub string[] columns = new string[]{ key_rowid, key_name, key_hotness}; cursor c = ourdatabase.query(database_table, columns, key_rowid + "=" + l, null, null, null, null); if(c != null){     c.movetofirst();     string name = c.getstring(1);     return name; } return null; }  public string gethotness(long l) throws sqlexception{ // todo auto-generated method stub string[] columns = new string[]{ key_rowid, key_name, key_hotness}; cursor c = ourdatabase.query(database_table, columns, key_rowid + "=" + l, null, null, null, null); if(c != null){     c.movetofirst();     string hotness = c.getstring(2);     return hotness; } return null; }  public void updateentry(long lrow, string mname, string mhotness) throws sqlexception{ // todo auto-generated method stub contentvalues cvupdate = new contentvalues(); cvupdate.put(key_name, mname); cvupdate.put(key_hotness, mhotness); ourdatabase.update(database_table, cvupdate, key_rowid + "=" + lrow, null); }  public void deleteentry(long lrow1) throws sqlexception{ // todo auto-generated method stub ourdatabase.delete(database_table, key_rowid + "=" + lrow1, null); } } 

i know can't done using rowid, because unique each row. please write code how solve problem, because beginner in android , in sqlite.

thanks in advance

sqlite keeps track of largest rowid table has ever held using special sqlite_sequence table.

you can update sqlite_sequence table-

update sqlite_sequence set seq = <n> name = <table_name> 

n rowid - 1

similar question.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -