Solved

Interbase: How to get the last generator value of newly inserted record?

Posted on 2001-09-02
3
451 Views
Last Modified: 2010-04-06
I'm using Interbase as database server for my Client/Server application. I use combination of trigger and generator for creating the primary key for each table. My problem is, how could I receive the generator value of just-inserted record? Please do remember that we have many users using the application concurrently, receiving the generator value is easy, but I don't know which one is for my session. Currently, I create a stored procedure for inserting value into the database, then return me with the value of the generator. But this way, my code will use stored procedure and will not be compatible with other database. Is there any better idea? I have to migrate this application to other database in the near future, it would be a huge problem if I do it this way.

If you can't answer this question, perhap you can tell me how to get the database connection session id (the id that uniquely generated for each user connection to the database). If I can get the session ID, it wouldn't be hard problem to keep generator value in database along with session ID.
0
Comment
Question by:kittichai
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
the bahaviour of all autogenerated values is, that there are unknown at the moment of inserting. for getting the last given value you must refetch the last inserted record to reread the automatically given number.

for myself, i read the autogenerated value into the delphifrontend, and supply this value in the beforepost-event for the field for ehat it is needed. this gives me the control for the value and i avoid by this way a refetch of the actually inserted record.

even if you know your session-id, you can't get the correct last for you generated value in a concurrent multiuser-enviroment without refteching the last inserted record, because the generating is session-independent.

meikl ;-)
0
 
LVL 9

Accepted Solution

by:
ITugay earned 300 total points
Comment Utility
Hi kittichai,
meikl :-)

I know one more way. You can add field 'USER_NAME' to the table and write trigger to put username there on insert event. To extract last record you can use something like this:

select max(id_record) from thetable where USER_NAME like 'SYSDBA'

-------
Igor.
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

split points between kretzschmar and ITugay

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now