> Hi guys,
>
> I'm inserting a record to a database, but once I have inserted the
> record I want to email the user their details including their UserID
> which is an autonumber (primary).
>
> To grab the last inserted row should I use the CFLOCK around my query
> and my cfmail?  Is there such a thing as Last.UserID which will give me
> the last insert of UserID?
>

No, cftransaction is what you want to use. One way to solve your problem
would be:

<cftransaction action="">   <cfquery ....>
  INSERT ....
  </cfquery>

  <cfquery ....>
  SELECT MAX(id)
  FROM foo
  </cfquery>
</cftransaction>

However there are also other "more elegant" ways of solving this problem as
well. You could write a stored proc that does the insert and returns the
value for you. Also, and I could be wrong on this, I *think* that JDBC has a
way of returning the row id just inserted, so you may want to look in to
that as well. Again, I could be way off on that, but I could swear I read
that somewhere.

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to