Kinda weird huh? What I usually do is grab the users phone number and then
append the date to the end of it. Since no two users phone numbers will be
the same, then I never get a duplicate. I notice with using randRange() it
does alot of duplication. If I use it and say

randRange(1, 1000) I will get as an example...There is always a chance of
duplication.

5,4,900,900,350,5


----- Original Message ----- 
From: "Will Tomlinson" <[EMAIL PROTECTED]>
To: "CF-Talk" <[email protected]>
Sent: Wednesday, November 29, 2006 7:08 AM
Subject: Can't figure out why these ID's aren't unique


> Just noticed a flaw in my store app. I'm generating what I THOUGHT were
unique ID's for carts and shoppers. They get plugged into the db for later
use.
>
> There seem to be a few records with the same ID. This ID field isn't the
PK of the table.
>
> When the app starts, a shopper service and cart service are initialized.
This is where I'm creating the ID. I WAS using randrange() and the date
appended to it. Just changed that to timeformat() to get an exact time and
maybe help this problem out.
>
> What's odd is I'm lookin in the cart table, and I see no such duplication.
All the ID's are unique, yet I'm using the same method to generate THOSE
too.
>
> Here's where it's created. Any ideas?
>
> <cfset APPLICATION.cartservice = CreateObject("component",
"cfcs.cartservice").init(dsn=application.settings.dsn)>
> <cfset APPLICATION.shopperservice = CreateObject("component",
"cfcs.shopperservice").init(browser=CGI.http_user_agent)>
>
>
> <cffunction name="init" access="public" output="false"
returntype="shopperservice">
>   <cfargument name="browser" required="yes">
>   <cfset VARIABLES.shopperStats = StructNew()>
>   <!--- Create a shopper ID for this shopper --->
>   <cfset VARIABLES.shopperStats.shopperID = TimeFormat(Now(), "hmmss") &
DateFormat(Now(),"m-dd-yy")>
>   <!--- Setup other variables that come in from onAppStart in App.cfc --->
>   <cfset VARIABLES.shopperStats.shopperBrowser = ARGUMENTS.browser>
>  <cfreturn this>
> </cffunction>
>
> And here's for the cartID. No problem I see with these ID's.
>
> <cffunction name="init" access="public" output="false"
returntype="cartservice">
>   <cfargument name="dsn">
>   <cfset VARIABLES.dsn = ARGUMENTS.dsn>
>   <cfset VARIABLES.finalCartTotal = 0>
>  <!--- Create a cart ID for this cart --->
>  <cfset VARIABLES.cartID = TimeFormat(Now(), "hmmss") &
DateFormat(Now(),"m-dd-yy")>
>  <cfset VARIABLES.totals = StructNew()>
>  <cfset VARIABLES.cartItemsAdded = false>
>
>   <cfreturn this>
> </cffunction>
>
> Thanks,
> Will
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:262018
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to