Hi,
How can I receive the last inserted ID-number after a 'INSERT INTO' command in TMySQL?
Thanks,
Marc
Last inserted ID in MySQL
-
- Posts: 1163
- Joined: Mon Oct 17, 2005 5:41 am
- Location: Belgium
- Contact:
Last inserted ID in MySQL
Regards,
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
- Rick Lipkin
- Posts: 2668
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Last inserted ID in MySQL
Marc
You may have to open a recordset with just a select statement on ID-number .. like ( assuming ID-number is a number that is incremented by 1 and not a random number.
"Select [ID-number] from Table order by [ID-number]"
Open Recordset
oRs:MoveLast()
My best guess ..
Rick Lipkin
You may have to open a recordset with just a select statement on ID-number .. like ( assuming ID-number is a number that is incremented by 1 and not a random number.
"Select [ID-number] from Table order by [ID-number]"
Open Recordset
oRs:MoveLast()
My best guess ..
Rick Lipkin
-
- Posts: 1163
- Joined: Mon Oct 17, 2005 5:41 am
- Location: Belgium
- Contact:
Re: Last inserted ID in MySQL
Rick,
I was also thinking of something like that, but what if more people inserting records at the same time on a network?
I saw something like LAST_INSERT_ID() in the MySQL manual, but this function is not recogniced by my xHarbour-version.
Thanks,
Marc
I was also thinking of something like that, but what if more people inserting records at the same time on a network?
I saw something like LAST_INSERT_ID() in the MySQL manual, but this function is not recogniced by my xHarbour-version.
Thanks,
Marc
Regards,
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
- Rick Lipkin
- Posts: 2668
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Last inserted ID in MySQL
Marc
A couple of suggestions on concurrency .. I have used a table that contains only 'ID-number' and when a person starts the Add process .. I append the Next number to the ID Table and store that number to a variable and when your form is ready to save .. you already have the number reserved and if someone gets in there concurrently, they get the next number in the ID table....
or
You could store the last used ID-number in a table and during the Insert routine .. increment the Last Used ID-number and append your record ..
Rick
A couple of suggestions on concurrency .. I have used a table that contains only 'ID-number' and when a person starts the Add process .. I append the Next number to the ID Table and store that number to a variable and when your form is ready to save .. you already have the number reserved and if someone gets in there concurrently, they get the next number in the ID table....
or
You could store the last used ID-number in a table and during the Insert routine .. increment the Last Used ID-number and append your record ..
Rick
- Daniel Garcia-Gil
- Posts: 2365
- Joined: Wed Nov 02, 2005 11:46 pm
- Location: Isla de Margarita
- Contact:
Re: Last inserted ID in MySQL
Hello
launch a select statement
example:
oQry = oServer:Query( "SELECT LAST_INSERT_ID() AS lastinsert" )
to retrieve the value oQry:lastinsert
launch a select statement
example:
oQry = oServer:Query( "SELECT LAST_INSERT_ID() AS lastinsert" )
to retrieve the value oQry:lastinsert
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
-
- Posts: 1163
- Joined: Mon Oct 17, 2005 5:41 am
- Location: Belgium
- Contact:
Re: Last inserted ID in MySQL
Daniel,
I have try it, and its working!!
Thanks,
Marc
I have try it, and its working!!
Thanks,
Marc
Regards,
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc
FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite