<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi everyone - hope you all had a good break. Looks 
like summer has finally arrived (now that everyone's back at work)! 
Anyway...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I'm using Firebird (and transactions) for the first 
time. I'm connecting to a remote database via the Firebird Server with no 
problems, but I have a question about transactions:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>When I insert a new record, I use a trigger and a 
generator to generate a new unique ID for the new record - I also query the 
generator to see what the new value is that was returned by the trigger. The 
code snippet&nbsp;is as follows:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=1>&nbsp;&nbsp;&nbsp; orderTransaction.Active 
:= True;<BR>&nbsp;&nbsp;&nbsp; <STRONG>with</STRONG> orderQuery 
<STRONG>do</STRONG> <EM><FONT color=#008000>//insert the 
record</FONT><BR></EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<STRONG>begin</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
ExecQuery;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRONG>with</STRONG> 
IBCurrentGeneratorValueQuery <STRONG>do</STRONG> <FONT color=#008000><EM>// this 
query fetches the current value of the 
generator</EM></FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<STRONG>try</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transaction 
:= orderTransaction;&nbsp; <FONT color=#008000><EM>// share the same transaction 
as the order</EM></FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Open;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result:=FieldByName(<FONT 
color=#000080>'newID'</FONT>).asInteger; <EM><FONT color=#008000>//&nbsp;get the 
generator value</FONT></EM><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<STRONG>except</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
result:=-1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<STRONG>end</STRONG>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
orderTransaction.Commit;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<STRONG>end</STRONG>;<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>The question is, if multiple clients access the 
database server at the same time, will <FONT face="Courier New" 
size=1>IBCurrentGeneratorValueQuery </FONT>still return the correct value, or if 
another concurrent transaction on another thread increments the generator, will 
this query return the wrong value?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>When I was using MySQL (with PHP) I could use 
mysql_insert_id() to query the new key value. I&nbsp;guess&nbsp;that if I could 
get hold of the newly inserted row I could just get the field value, but the 
same concurrency issue applies and I'm not sure how to get the record I just 
inserted.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Cheers,</FONT></DIV>
<DIV><FONT face=Arial size=2>Phil.</DIV></FONT></BODY></HTML>