He's just not doing a select max, which of course is a disaster.  The method Christian 
described is imho best: easy on resources and safe.  What the author was talking about 
looks workable but requires a lot of overhead (see below).  Just brought it up as an 
item of interest.

<cfloop condition="true">
        <cftry>
                <cftransaction>
                        <cf_max_ID 
                                datasource="#application.mainDSN#"
                                tablename="users"
                                primarykey="userid">
                        <cfquery 
                                name="addhistory" 
                                datasource="#application.mainDSN#">
                                insert into users
                                (userid,firstname,lastname,email)
                                values
                                (#max_ID#,
                                '#trim(attributes.firstname)#',
                                '#trim(attributes.lastname)#',
                                '#attributes.email#')
                        </cfquery>
                </cftransaction>
                <cfbreak>
                <cfcatch type="database">

                </cfcatch>
        </cftry>
</cfloop>

<!--- 
cf_max_id 
required attributes 
--->
<cfparam name="attributes.datasource">
<cfparam name="attributes.tablename">
<cfparam name="attributes.primarykey">

<cfquery 
name="getmaxID" 
datasource="#attributes.datasource#">
select max(#attributes.PrimaryKEY#) as Max_ID
from #attributes.tablename#
</cfquery>

<cfif len(getmaxID.Max_ID)>
        <cfset caller.Max_ID = getmaxID.Max_ID + 1>
<cfelse>
        <cfset caller.Max_ID = "1">
</cfif>



---------- Original Message ----------------------------------
From: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
date: Mon, 17 Mar 2003 15:20:39 -0700

>Using the maxid trick has problems though.  In some databases, it will create a race 
>condition.  The only way to alleviate it is to set the transaction isolation level to 
>"serializable".
>
>----- Original Message -----
>From: Matt Robertson <[EMAIL PROTECTED]>
>Date: Monday, March 17, 2003 2:53 pm
>Subject: Re: Using createUUID()
>
>> Chris,
>> 
>> I've used the method you describe for awhile and prefer it.  Your 
>> post reminded me of another method that seems safe, but I never 
>> went there.  CF_MaxID:
>> 
>> http://tinyclick.com/?T02MT2 
>> 
>> You need a transaction block inside of a try/catch block inside of 
>> a loop to make it bombproof (:O) per the included docs, but it'll 
>> apparently work without adding a second indexed field to your table.
>> 
>> -------------------------------------------
>> Matt Robertson,     [EMAIL PROTECTED]
>> MSB Designs, Inc. http://mysecretbase.com
>> -------------------------------------------
>> 
>> 
>> ---------- Original Message ----------------------------------
>> From: Christian Cantrell <[EMAIL PROTECTED]>
>> Reply-To: [EMAIL PROTECTED]
>> date: Mon, 17 Mar 2003 15:22:12 -0500
>> 
>> >I posted some information on the createUUID function on my weblog 
>> today 
>> >based on an application I was working on over the weekend:
>> >
>> >http://www.markme.com/cantrell/weblog/index.cfm?m=3&d=17&y=2003
>> >
>> >Christian
>> >
>> >On Monday, March 17, 2003, at 07:55 AM, FlashGuy wrote:
>> >
>> >> Hi,
>> >>
>> >> I need to generate a unique ID for every form I submit. The 
>> createUUID 
>> >> # generated is just too long for my needs. My ID only needs to 
>> be 10 
>> >> characters in length. Something like:
>> >>
>> >> CT-0001001
>> >>
>> >> I'm using MySQL. Can I have mysql generate the unique ID? How 
>> could I 
>> >> do this with CF?
>> >
>> >
>> 
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to