On Wednesday 04 March 2009, Jaume Casado wrote: > Hi there. > > I'm looking for a function or method in the gb.db component to obtain the ID > of the last element inserted into the database. With the methods Create, > Edit y Find, we can run our Gambas app independently from the chosen engine > database. That's why I wanna know if there is any similar solution to get > the last insert id (of an autoincrement field in a table). Now I am working > with sqlite3 and I don't find the manner. Thus, I did it with the specific > sql query: > > hResult = hConn.Exec("SELECT last_insert_rowid() AS id") > RETURN CInt(hResult["id"]) > > But doing it like this is not database engine independent, because in MySQL > the query was: > > SELECT LAST_INSERT_ID(); > > Searching a little, I've found that the MySQL component includes it already: > 22:23 on Oct 25, 2008 gambas Commit by dvillalobos :: r1652 > /gambas/trunk/gb.db.mysql/src/gb.db.mysql/ (.component .info .project > _MySQL.class): > (link<http://gambas.svn.sourceforge.net/viewvc/gambas?view=rev&revision=1652>) > > > [GB.DB.MYSQL] > NEW: Added the function LastInsertId to _MySQL class, that returns the last > insert id for the current user. > > Then, Gambas lets you to get the "last insert id" in a transparent manner? > > Thank you a lot, > Jaume > >
I do belive dvillalobos did use 'LastInsertId' for the gambas name. It is translated in background to the MySQL 'SELECT LAST_INSERT_ID();' and the mantainer of the sqlite version can/should use the same gambas name and translate it to 'SELECT last_insert_rowid()'. Result will be a common name not conflicting with the sql command itself. Best regards, Ron_1st -- A: Delete the text you reply on. Q: What to do to get my post on top? --- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? --- A: Top-posting. Q: What is the most annoying thing in e-mail? ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user