Solved

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

Posted on 2001-09-02
3
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6449746
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
ID: 6456303
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
ID: 9294117
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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