Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Re: Generate a user Id that is not already in the database ?


Message #1 by Martin Lee <access@o...> on Thu, 02 May 2002 20:36:35 +0800
Just a follow up question:

Are GUID's always composed of Alphanumeric characters and "{}-" only?

We are planning to redesign a site and are thinking of maintaining state by 
passing a GUID in the querystring. We were thinking of stripping  "{}-" 
from the GUID before inserting into the database so we would only have to 
validate for alphanumeric characters.

Thanks,

Martin



At 11:17 AM 5/1/2002 +1000, you wrote:
>Even if you use random autonumbers (not sequential autonumbers)?
>Alternatively, why not generate a GUID?
>
><%
>Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
>intGUID = TypeLib.GUID
>Set TypeLib = Nothing
>%>
>
>The GUID is a null terminated string, so you might want to chop the last
>character off the end if you want to append something.
>
>The problem I see with the code you have already is when many people access
>the same code simultaneously - you're getting "dirty reads" after the new ID
>is created for the 1st person.
>
>Cheers
>Ken

Message #2 by "Ken Schaefer" <ken@a...> on Wed, 1 May 2002 11:17:36 +1000
Even if you use random autonumbers (not sequential autonumbers)?
Alternatively, why not generate a GUID?

<%
Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
intGUID = TypeLib.GUID
Set TypeLib = Nothing
%>

The GUID is a null terminated string, so you might want to chop the last
character off the end if you want to append something.

The problem I see with the code you have already is when many people access
the same code simultaneously - you're getting "dirty reads" after the new ID
is created for the 1st person.

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <vincent_cpr@y...>
Subject: [asp_databases] Re: Generate a user Id that is not already in the
database ?


: > Have you ever heard of "autonumber"?
:
: Cheers
: Ken
:
: I don't use the automnumbering ... I have problems with the autonumbers
: when I compact my database. What's the alternative to generate unique
: user id's efficiently ?
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: <vincent_cpr@y...>
: Subject: [asp_databases] Generate a user Id that is not already in the
: database ?
:
:
: : Is the code (marked with *) a right way to generate a user id that's not
: : already in the database, or are there better ways to do so ?
: :
: :
: : Function GenerateUserID
: : 'Generates a user Id that is not already in the database.
: : Dim sUserId, IsValidNew
: : IsValidNew = False
: : sUserID = ""
: :
: : While NOT IsValidNew
: :
: : * sql = "SELECT MAX(UserID) from Users Where UserID = '"
: :                 * &  sUserID & "'"
: : * Set Rs = conn.Execute (sql)
: : * sKlantID = Rs + 1
: :
: : 'Query how many times the UserId is in the database
: : (should be 0 or 1)
: : sql = "SELECT COUNT(*) FROM Users Where UserID = '" &
: : sUserID & "'"
: : Set Rs = conn.Execute (sql)
: :
: : If NOT (rs.EOF and rs.BOF) Then
: : If Rs(0) = 0 Then
: : 'Does not exist
: : IsValidNew = True
: : Else
: : 'Already exists!
: : IsValidNew = False
: : End If
: :
: : Else
: : 'If if fails to perform the operation suppose it
: : is correct
: : 'this is to avoid an infinite loop
: : IsValidNew = True
: : End If
: :
: : 'Close an clean up recordset
: : rs.Close
: : set rs = nothing
: : Wend
: : GenerateUserID = sUserID
: :
: : End Function
:
:


  Return to Index