Skip to main content
March 27, 2008
Question

isValid("uuid",i) Problems

  • March 27, 2008
  • 5 replies
  • 805 views
Hi,

I'm in the process of building me a CMS. The fields are dynamic and pulled from a database, because of this, it made sense to make each fields name a UUID. So far so good.

So what I do is take the form.fieldnames scope and loop it, using the name of the field (UUID) and some logic to put this in the DB. However, there are other elements on the form that I do not want in the DB, such as the submit button etc, that the form.fieldnames scope puts in.

In order to avoid this, before my insert query, I check the Index of my loop (a list loop from form.fieldnames) to see if the index is a valid UUID. This would mean I would then KNOW it's the kind of field I want to put in.

However, i then noticed some fields were not getting inserted - taking this condition out...they got inserted...BUT, I need to use this condition...and it's failing but I cannot understand why.

Below is a screenshot of some output I got from the loop in my CFC method...
http://www.glasshouseboutique.com/

As you can see, they look like valid ColdFusion UUID's to me, but some return No and some Yes.

Code =

<cfloop index="i" list="#arguments.saveFields#" delimiters=",">

<cfif isValid("uuid",i)>
<cfquery name="checkExists" datasource="#request.dsn#" username="#request.username#" password="#request.password#">
<!---- Query Insert here --->
</cfquery>
</cfif>

<cfoutput>#i# ---- Valid UUID = <strong>#isValid("uuid",i)#</strong><br /></cfoutput>

</cfloop>


I'm puzzled!!

Thanks,
Mikey.
    This topic has been closed for replies.

    5 replies

    Inspiring
    March 28, 2008
    How are you generating your UUIDs? Because the ones that are getting a
    "no" certainly *aren't* UUIDs... they've got non-hexadecimal digits in
    them! (like "T" and "U"!).

    --
    Adam
    Participating Frequently
    March 27, 2008
    We had same kind of problems on Linux boxes.

    I would prefer using GetTickCount function to generate unique IDs.
    Participant
    March 27, 2008
    This is from livedocs on CF CreateUUID(). Looks like you could test for a valid CF UUID first if you wanted then convert it if it fails the test. Another option would be to write you own validator meaning that you know that the submit button and other various unwanted fields are not going to be 35 characters long and have 3 dashes in them.

    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.

    March 27, 2008
    Hi, thanks for your reply. I'm afraid to say I have tried this too:

    #isValid("uuid",trim(i))#

    I still get the same results...I'm stumped.

    I have a feeling that maybe some of these UUID's weren't generated by CF, but rather cut and paste from other places to test with in the initial stages of the project. Either way, they are formatted correctly, but could this have problems?

    How does ColdFusion create these UUID's and guarantee they are unique - does it have some kind of internal log or DB that keeps track of them?

    Any suggestions welcome.

    Thanks,
    Mikey.
    Participant
    March 27, 2008
    If the data is being pulled from a DB you may try triming the data before your pass it to the isValid() function. I 've had this same issue before and my query was pulling extra spaces from the DB fields.

    Cheers