sqlite - How to set the ID number to 1 in an Android SQL query -
i trying query on table in android sqlite. when query table want id number start 1 , increment every row. however, when query on table @ moment, it's showing id number of original table table. suggestions appreciated.
private static string[] = {_id, title, date, time, details}; private static string order_by = time + " asc"; private cursor getappointments() { sqlitedatabase db = appointments.getreadabledatabase(); cursor cursor = db.query(table_name, from, date + "=?", new string[] {date}, null, null, order_by, null); startmanagingcursor(cursor); return cursor; } }
typically, should not concerned value of id, other it's unique , identifies row.
if define table column _id primary key unless if set _id, start 1 when insert first row, next 2 , 3 etc.
if code autoincrement though, may not case, autoincrement make value unique @ database level.
here's extract sqlite autoincrement
the autoincrement keyword imposes cpu, memory, disk space, , disk i/o overhead , should avoided if not strictly needed. not needed.
in sqlite, column type integer primary key alias rowid (except in without rowid tables) 64-bitsigned integer.
on insert, if rowid or integer primary key column not explicitly given value, filled automaticallyunused integer, 1 more largest rowid in use. true regardless of whether or not autoincrement keyword used.
if autoincrement keyword appears after integer primary key, changes automatic rowid assignment algorithm preventreuse of rowids on lifetime of database. in other words, purpose of autoincrement prevent reuse of rowids deleted rows.
i'm assuming don't have expectation _id dynamically change order of extracted rows after query, how question interpreted per
when query table want id number start 1 , increment every row
if question, wouldn't this, rather you'd loop through cursor, ordered according query. if wanted first referenced 1, 2, 3.... loop though cursor creating associated array such number.
Comments
Post a Comment