> 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?

If mySQL is case sensitive like Oracle, you could take the uName() function
from TAPI to do this... <cfset myid = request.tapi.uName("",10)> (the order
of the arguments may not be right here, this is from memory and I don't
usually use the arguments. The function was originally created for the
purpose of creating random strings to be used as names of temporary
functions in JavaScript and as such generates a string of x random mixed
case characters, discluding some commonly confused characters (0oOliI1) with
a pre-defined prefix (to prevent the possibility of the string beginning
with a number which would make it useless as a function name). You can set
the prefix to an empty string and the number of characters to 10 (default is
35) to produce something slightly less structured and of course you can add
back in the 0oOliI1 characters to increase your variance. Url in my sig
below.

Or you could use a non random string (guaranteed to be unique every time)
like an autonumber/increment. Do this by exclusively locking around the
function that generates the number (either from the db or from the file
system), and then simply set your string with this number <cfset myid =
"CT-" & numberformat(myautonumber,0000000)> To get the number from mySQL
just create a table for your autonumber id's and use a <cftransaction
isolation="serializeable"> around two queries -- one to retreive the current
number and another to increment it by one. To get the number from the file
system is similar -- just create a file to contain the number and use
<cflock name="#expandpath(myfilepath)#" type="exclusive"
timeout="30"><cffile action="read" file="#expandpath(myfilepath)#"
variable="myuniqueid"><cffile action="write" file="#expandpath(myfilepath)#"
output="#incrementvalue(myuniqueid)#"></cflock> In CFMX you can create a UDF
to perform this task using <cffunction> so you can create more unique id's
if you need them and reduce the amount of typing to get them.

hth


s. isaac dealey                954-776-0046

new epoch                      http://www.turnkey.to

lead architect, tapestry cms   http://products.turnkey.to

tapestry api is opensource     http://www.turnkey.to/tapi

certified advanced coldfusion 5 developer
http://www.macromedia.com/v1/handlers/index.cfm?ID=21816

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

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

Reply via email to