Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-09-02
3
Medium Priority
?
463 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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