Skip to main content
Inspiring
April 27, 2006
Answered

Order Tracker

  • April 27, 2006
  • 3 replies
  • 480 views
Hello,
I am creating a database in which to store my orders, I have designed my order number to be the a combination of the letters 'ORD' and a number. The number would be based on a variable that is initialized and incremented by 1 for each order recieved.

My problem is that I can't seem to decide which variable is best for this. I had initially thought it would be an application variable, but I have read that these are good for variables that rarely change.

I would appreciate suggestions on a good way to implementing an increasing variable that is independent of the user and will not be re-initialized any time the application is restarted.

Thanks
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer BKBK
    When I design in a similar context, I treat the application scope as just another store of data, much like the database. From this viewpoint, storing ord1234 in the database and in Application.1234 is doing the same thing twice.

    There is a second, perhaps, stronger, design consideration. The variable Application.x could be applicable to your application only if x passes what I call the "necessity" test. Does the statement, "My application's ", make sense when you replace by a literal description of what x stands for? If so, then Applcation.x could be of use to your application. If not, then x should not be in the Application scope.

    Some descriptions that pass the test are:

    - data source
    - number of visitors
    - admin e-mail

    Some descriptions that generally fail are:

    - user's name
    - order number
    - shopping cart

    Finally, my advice would be to generate random order numbers, for example, like this

    <cfset orderNumber = "ORD" & Right(createuuid(),12)>,

    and store them in the database alongside client data.

    3 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    April 27, 2006
    When I design in a similar context, I treat the application scope as just another store of data, much like the database. From this viewpoint, storing ord1234 in the database and in Application.1234 is doing the same thing twice.

    There is a second, perhaps, stronger, design consideration. The variable Application.x could be applicable to your application only if x passes what I call the "necessity" test. Does the statement, "My application's ", make sense when you replace by a literal description of what x stands for? If so, then Applcation.x could be of use to your application. If not, then x should not be in the Application scope.

    Some descriptions that pass the test are:

    - data source
    - number of visitors
    - admin e-mail

    Some descriptions that generally fail are:

    - user's name
    - order number
    - shopping cart

    Finally, my advice would be to generate random order numbers, for example, like this

    <cfset orderNumber = "ORD" & Right(createuuid(),12)>,

    and store them in the database alongside client data.

    AbdlahAuthor
    Inspiring
    April 27, 2006
    Thanks for the explanation and suggestion, I will try the random number generation.

    Just a quick question, I know that there is a very small chance that the same random number is generated multiple times, but should this happen the application will fail to store data since it will not allow duplicate primary keys. Is there a way to ensure this doesn't happen?
    BKBK
    Community Expert
    Community Expert
    April 27, 2006
    The longer the random string the less likely that that would happen. Each position in the string Right(createuuid(),12) is occupied by one of the 16 characters [A-F, 0-9]. The string is therefore 48-bit (as 16^12 = 2^48). Assuming everything is working normally, the chance of Coldfusion generating the same 12-character string twice is about 1 in 281000 000 000 000.

    In any case, you could reduce the risk further by doing something like

    <cfset orderNumber = "ORD" & Right(createuuid(),16)>

    Coldfusion now identifies the order numbers with the last 16 characters of the generated UUID. That is, the 4th and last block in the sequence xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx. The order numbers are now 64-bit.