Recent

Author Topic: Getting last id from firebird  (Read 39966 times)

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: Getting last id from firebird
« Reply #45 on: December 14, 2013, 03:00:13 pm »
mangakissa:
There are a number of choices for getting the hidden key which you have listed.

The one choice that is not available is getting the key from the SELECT * FROM tbl; result set. This is just a jumble of everything and there is no way to reliably determine the new key.

If your trying to find the new record in SELECT * FROM tbl; that matches the key use TSQLQuery.Locate()
« Last Edit: December 14, 2013, 03:07:53 pm by goodname »

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Getting last id from firebird
« Reply #46 on: December 14, 2013, 06:02:34 pm »
the alternative, just using autoincrement is just fine. A very minor portion of your db code gets a bit db specific (at least till all dbs implemented returning, which we are now close, the frameworks just need to catch up).
Like I said, I needed a solution 10 years ago. auto-inc sucked, and GUID's worked perfectly since then.

Quote
Maybe there are still valid usecases if you really desire 100% blind portability across databases at rock bottom level, but it goes to far to raise that to a general recommendation.
Auto-inc would never have worked for us, no matter how good the framework support was. We have 250+ franchise businesses - each running their own database. Monthly we import data from them into a "master" head-office database. Auto-inc fields are only good for a single table. We need world/global unique values when importing 250+ databases into a single one - all without having to worry about conflicting ID values. And if you wondered why we need to do this... for pulling nation wide stats at head-office.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Getting last id from firebird
« Reply #47 on: December 14, 2013, 06:06:51 pm »
Use GUID. But this is not usable to different OS.
Uh? Our products (which use GUID's for all records) run under Windows, Linux and FreeBSD. No problems at all, and it 10 years, not a single conflict.

We also have code that imports data into the database, and generates about 80,000 to 100,000 records all at once - again this has never produced a single conflict for us.
« Last Edit: December 14, 2013, 06:10:15 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018