On Tue, Mar 18, 2008 at 08:07:12PM +0100, A.J.Millan scratched on the wall: > Hi all: > > I would know if there a some way to know the last insert in a know table. > > Some like the result returned by sqlite3_last_insert_rowid(), but referred > to a specific table inside the database connection, and not in all tables > into the database from the database connection.
You could simply look for the largest ROWID in a table. Assuming your tables have no INTEGER PRIMARY KEY column (or if they do, that you never set it explicitly) then, in general, the row with the largest ROWID will be the last one that was inserted. There are a few caveats to that, however. Having an INTEGER PRIMARY KEY AUTOINCREMENT column may help limit these issues. See http://www.sqlite.org/autoinc.html for more details. Of course this depends on a lot of things that are somewhat out of your control. You're depending on the specific way the SQLite uses "behind the scenes" data and the behavior of the allocation of those ID values. If it is really that important to know the last inserted row, it might be best to just have some kind of integer timestamp column that is auto-set when a row is inserted. This makes it easy to look up the last-inserted row regardless of the rest of the table design. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "'People who live in bamboo houses should not throw pandas.' Jesus said that." - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006" _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

