hi there use function insert/delete record in sqlite android.
// adding new bookmark
public void addbookmark(bookmark bookmark) { sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(key_title, bookmark.gettitle()); // bookmark name values.put(key_url, bookmark.geturl()); // bookmark phone // inserting row db.insert(table_bookmarks, null, values); db.close(); // closing database connection } // deleting single bookmark
public void deletebookmark(bookmark bookmark) { sqlitedatabase db = this.getwritabledatabase(); db.delete(table_bookmarks, key_id + " = ?", new string[] { string.valueof(bookmark.getid()) }); db.close(); } now want keep last 100 record in db. (i want check when insert new record.if count more 100...the code remove oldest records.
something aql code:
delete table_bookmarks key_id not in (select key_id table_bookmarks order key_id desc limit 100) i think top code true how can use in code:
// adding new bookmark , keep 100 record always.
public void addbookmarkandkeep100(bookmark bookmark) { sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(key_title, bookmark.gettitle()); // bookmark title values.put(key_url, bookmark.geturl()); // bookmark url // inserting row db.insert(table_bookmarks, null, values); db.delete(?); db.close(); // closing database connection }
Comments
Post a Comment