It is currently 21 April 2025, 16:48 Advanced search

Last_Insert_ID()

Questions and answers on how to best use Instant Developer

Last_Insert_ID()

Postby Gaby_h » 9 September 2013, 23:55

I am using a 1row In Memory table to insert new records (1 record at a time) in a back end table. It works well, however I need Inde to return to me the ID of the record that was inserted. Mysql uses LAST_INSERT_ID() to return the last auto increment value. What expression in Inde returns the ID of the record that was just inserted?
Gaby_h
 
Posts: 888
Joined: 17 July 2013, 18:22
Location: Vancouver, Canada

Re: Last_Insert_ID()

Postby g.lanzi » 10 September 2013, 16:14

The monorow IMDB table are designed to store only one record in the same table. For that they have only one row the have also a special ability, you can access their fields directly. Just like some variables.

One useful feature of the monorow IMDB variables is that if you have a query witha where clause that depends on a variabile of this kind, is will be automatically refreshed if the value of the monorow IMDB table field changes.

You can use a multi row IMDB table. If you do that you can set one IMDB table field as a Primary Key (also a counter one, if you want to do in this way) and write down an insert statement like that

Code: Select all
int -ID = 0;
INSERT INTO table (vID)
set FIELD1 = 'Goofy' // I always use Walt Disney for my examples :)


After that statement the vID integer variable will contain the last ID created for the new row.

If you want to implement a panel that force the user to insert only one row at a time, you can use the "Auto Manage Layout" flag of the panel. With that you will force the panel to automatically switch to detail layout when the user click on the "insert" button.
Giuseppe Lanzi
Director of Support services
Pro Gamma S.p.A.
User avatar
g.lanzi
Pro Gamma
Pro Gamma
 
Posts: 3503
Joined: 29 September 2010, 10:24
Location: Bologna

Re: Last_Insert_ID()

Postby Gaby_h » 10 September 2013, 19:51

Thank you very much. Easier than I thought; really great.
Gaby_h
 
Posts: 888
Joined: 17 July 2013, 18:22
Location: Vancouver, Canada


Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 23 guests