|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Get last inserted id?
Hi all
I'm hoping to start development with PHP and Firebird on a new project. I've been running some tests, but can't seem to find a way to grab the id of the last INSERTed row. Can anyone help me?
__________________
R.T.F.M - Its the only way to fly... "No matter what you do, or how good it is, someone will always ask for more features. Or to change the colour of something, then change their minds." Personal: experience// 8 Years Web Development technologies// Standards-compliant, valid, & accessible (x)HTML/CSS, XML/XSL/XPath/XQuery/XUpdate, (OOP) PHP/(My)SQL, eXist/Xindice/XMLDBs packages// Photoshop, Illustrator, Flash/Fireworks/Director environment// FC2, MySQL, Lighttpd, PHP5, Mojavi/Agavi site// //refactored.net/ (Coming soon...) quote// Programming is the eternal competition between programmers who try to make apps more and more idiot proof and the universe that makes dumber idiots. So far, the universe is winning... |
|
#2
|
||||
|
||||
|
Is there no way to obtain this then?
|
|
#3
|
|||
|
|||
|
Try with:
SELECT gen_id(gen_name, 0) from rdb$Database where gen_name is generator holding value you need. P.S. I had a problem posting here, so sorry for delay ;-) -- Best regards, Fikret Hasovic http://fikret.fbtalk.net USAID TAMP Senior Programmer * Firebird Foundation member. - Join today at http://www.firebirdsql.org/ff/foundation * JEDI VCS contributor http://jedivcs.sourceforge.net/ * Firebird and Fyracle news http://www.fyracle.org |
|
#4
|
|||
|
|||
|
Although the proposed solution works for single-user systems, I would recommend against it for just that reason.
GEN_ID(generatorname, 0) will return the current value of the generator. This does not have to be the value you just used in the trigger. If another user did the same, you will get that value instead. The best way is to fetch the value first, then use the value for subsequent inserts. SELECT GEN_ID(mygenerator, 1) AS NEW_VALUE FROM RDB$DATABASE INSERT INTO ... VALUES (NEW_VALUE, ...) With regards, Martijn Tonies Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL Server Upscene Productions http://www.upscene.com Database development questions? Check the forum! http://www.databasedevelopmentforum.com
__________________
Martijn Tonies Database Workbench: developer IDE for Firebird, MySQL, InterBase, MSSQL Server and Oracle Upscene Productions http://www.upscene.com |
|
#5
|
|||
|
|||
|
Doesn't work for me. SELECT GEN_ID(mygenerator, 1) AS NEW_VALUE FROM RDB$DATABASE increases the value of generator. when I insert the value of generator is one more.
this is the code i use in my procedure to return last id inserted. INSERT INTO ... VALUES (NEW_VALUE, ...) SELECT GEN_ID(mygenerator, 0) FROM RDB$DATABASE INTO NEW_VALUE (NEW_VALUE is an output variable) |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Get last inserted id? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|