View comments | RSS feed

CreateUUID

Description

Creates a Universally Unique Identifier (UUID). A UUID is a 35-character string representation of a unique 128-bit integer.

Returns

A ColdFusion format UUID, in the format xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx, where x is a hexadecimal digit (0-9 or A-F). (The character groups are 8-4-4-16.)

Category

Other functions

Function syntax

CreateUUID()

Usage

The ColdFusion UUID generation algorithm uses the unique time-of-day value, the IEEE 802 Host ID, and a cryptographically strong random number generator to generate UUIDs that conform to the principles laid out in the draft IEEE RFC "UUIDs and GUIDs."

The ColdFusion UUID format is as follows:

xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16).

This does not conform to the Microsoft/DCE standard, which is as follows:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12)

There are UUID test tools and a user-defined function called CreateGUID, which converts CFML UUIDs to UUID/Microsoft GUID format, available on the web at www.cflib.org.

Use this function to generate a persistent identifier in a distributed environment. To a very high degree of certainty, this function returns a unique value; no other invocation on the same or any other system returns the same value.

UUIDs are used by distributed computing frameworks, such as DCE/RPC, COM+, and CORBA. In ColdFusion, you can use UUIDs as primary table keys for applications in which data is stored in shared databases. In such cases, using numeric keys can cause primary-key constraint violations during table merges. Using UUIDs, you can eliminate these violations.

Example

<h3>CreateUUID Example</h3>
<p> This example uses CreateUUID to generate a UUID when you submit the form. 
You can submit the form more than once. </p> <!--- Checks whether the form was submitted; if so, creates UUID. ---> <cfif IsDefined("Form.CreateUUID") Is True> <hr> <p>Your new UUID is: <cfoutput>#CreateUUID()#</cfoutput></p> </cfif> <form action = "createuuid.cfm"> <p><input type = "Submit" name = "CreateUUID"> </p> </form>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


MACRStockHolder said on Aug 14, 2007 at 1:09 PM :
For the example code to work correctly on all types of web servers you need to add [method="post"] to the HTML form definition.
AeonCube said on Jan 25, 2008 at 4:36 AM :
Here is the full code to work on most computers with the post, just for those who want to copy & paste.

<h3>CreateUUID Example</h3>
<p> This example uses CreateUUID to generate a UUID when you submit the form.
You can submit the form more than once. </p>
<!--- Checks whether the form was submitted; if so, creates UUID. --->
<cfif IsDefined("Form.CreateUUID")>
<hr>
<p>Your new UUID is: <cfoutput>#CreateUUID()#</cfoutput></p>
</cfif>
<form method="post" action = "createuuid.cfm">
<p><input type = "Submit" name = "CreateUUID"> </p>
</form>
halL said on Jan 25, 2008 at 7:54 AM :
The above code corrects the error of omitting the form tag action attribute in the example in the documentation.
Also, its cfif tag contents is cleaner.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000436.htm