Two issues there, really, it seems, Brian.
1) When you need more truly random numbers, you should call the Randomize function first, and in it you can provide both a seed and an alternative randomization algorithm. See the CF docs, such as (for cf9, which sadly comes up first in google search results):
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6d3e.html
You could also consider using the createuuid function, which creates a different form of random number (with numbers and letters), which may have value.
2) But you refer to getting the identity as a second step and using that. Are you saying THAT ends up being the same? If so, that would not be due to randomization issues, but rather a race condition.
You don’t say how you’re selecting the identity from the insert, but there are multiple ways, some better than others at reducing the likelihood of getting one from another insert. I’ll hold off on details until you clarify what you’re doing and whether this would be helpful. (Or perhaps someone else will chime in anyway.)
/charlie
--
You received this message because you are subscribed to the Google Groups "cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfaussie+u...@googlegroups.com.
To post to this group, send email to cfau...@googlegroups.com.
Visit this group at https://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.
--
Hi Brian.
Well first of all if you are using SQL Server try this to get the new ID in the same transaction rather than doing another query;
<cfquery datasource="[datasource]" username="[username]" password="[password]" name="qry">
SET NOCOUNT ON
INSERT INTO orders
(
** Your order fields **
)
VALUES
(
** Your data **
)
SELECT @@Identity AS orderID
SET NOCOUNT OFF
</cfquery>
<cfset attributes.orderID=qry.orderID>
I am not sure what you use the unique number for other than for something to put onto the receipts or something?
However, if you want to obscure the ID in a link you could encrypt it. I have done this is the past where I sent users and email but didn’t want them to be able to just increment the link to see someone else’s order, e.g. displayorder.cfm?orderID=1234
So I did this:
<cfset myKey="[** your generated AES key **]">
<cfset AESorderID=urlencodedformat(encrypt(attributes.orderID,myKey,"AES"))>
Because the orderID is unique the encrypted value should be unique as well.
See http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c2f.html
I am not sure if that is what you actually wanted but I hope it helps!
From: cfau...@googlegroups.com [mailto:cfau...@googlegroups.com] On Behalf Of Brian Knott
Sent: Wednesday, 27 January 2016 9:31 AM
To: cfau...@googlegroups.com
Subject: [cfaussie] SQL identity issue
Hi everyone.
--
You could also generate a hash of their name and address as the seed, assuming there isn't 2 customers with the same name and address (and you already have this data at this point)
<
cfquery
datasource=
"#DSN#"
result=
"myResult"
>
INSERT
INTO MyTable (col1)
VALUES (
'col1'
)
</
cfquery
>
<!--- Tag based output --->
<
cfoutput
>Inserted ID is: #myResult[
"GENERATEDKEY"
]#</
cfoutput
>
--
You received this message because you are subscribed to the Google Groups "cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfaussie+u...@googlegroups.com.
To post to this group, send email to cfau...@googlegroups.com.
Visit this group at https://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.