delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

ex.
Code:
<cflock timeout="60" throwontimeout="yes" type="exclusive" scope="application">
<!--- insert new record --->
<!--- select max(id)... --->
</cflock>


If I have a registration form where a new record is inserted into one table and then want to select that new record's id using a select max(id) query, can I surround my code with cflock to ensure that the max(id) selected is actually the id of the record just inserted? Will the cflock prevent other potential users from inserting a new record until the previous record is inserted and it's id is selected?
ex.
Code:
  1. <cflock timeout="60" throwontimeout="yes" type="exclusive" scope="application">
  2. <!--- insert new record --->
  3. <!--- select max(id)... --->
  4. </cflock>
Copy Code

TOP

I would avoid putting a CFQUERY (or any other "time consuming process") inside of a CFLOCK tag.  You'll likely grind your app server to a halt under any kind of load.  The best way to handle it is as kiteless suggests with the CFTRANSACTION tag.  What database are you using?

TOP

maybe I'm old fashioned but my preferred method to get the id of a record that was just inserted is to
1. when the data is first being inserted, insert a unique identifier along with the other data (could use the cf rand function)
then
2. select the row containing the unique identifier
selecting (max) could give you the worng record if the db is updated in that moment between transactions.

TOP

just wanted to say thanks for all your help and advice.



ex.
Code:
<cflock timeout="60" throwontimeout="yes" type="exclusive" scope="application">
<!--- insert new record --->
<!--- select max(id)... --->
</cflock>

TOP

Back Forum