actually, the use of <cflock> and <cftransaction> together is the
recommended practice... under extremely heavy load <cftransaction> doesn't
return the proper unique id to the client 100% of the time but <cflock>
does.  Though <cflock> alone does guarantee the proper return value in CFML
pages, it does not use database transactions, which means transactions
currently being executed by other applications can cause false returns.
This is why <cftransaction> should be used as well. You can find out more
about transactions, locking, and stored procedures in CFML applications at:
http://www.macromedia.com/devnet/mx/coldfusion/articles/cftransaction.html

~Simon

Simon Horwith
CTO, Etrilogy Ltd.
Member of Team Macromedia
Macromedia Certified Instructor
Certified Advanced ColdFusion MX Developer
Certified Flash MX Developer
CFDJList - List Administrator
http://www.how2cf.com/

  -----Original Message-----
  From: Dave Carabetta [mailto:[EMAIL PROTECTED]
  Sent: 01 February 2004 15:27
  To: CF-Talk
  Subject: Re: CFLOCK:....Sunday (still not left computer all weekend,
flatmates will start thinking i have problems)

  > 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