[Gambas-user] last instert ID in sqlite3

Jaume Casado minterior at ...626...
Wed Mar 4 17:34:15 CET 2009


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


-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/E/IT/M/TW d-- s: a- C+++$ UL++ P L+++ E- W+++$
N- !o(--) K- w--(---) !O M-(+) V?(-) PS PE Y+ PGP>+
t@ 5? X+ R tv- b+@ DI-- D G++ e h++(--) r++>+++ y?
------END GEEK CODE BLOCK------

--
-- Free software my friend ;-)
--



More information about the User mailing list