Solved

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

Posted on 2001-09-02
3
458 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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