Hi Lew,

SELECT MAX() + 1

can result in two or more people getting the same next ID.

If you were running the system at the same time I was, we could both run 
that code at almost the same time and end up with the same ID which 
could cause no end of problems.

The standard ways to do this is to

1. use a function like NewID() or NextID() (can't remember the name) 
which you can find in the VFP samples which maintains a table with a row 
for each possible new id, locks the row, increments the ID and returns 
the incremented value.

2. use an autoincrement id

3. use a GUID

Frank.

Frank Cazabon

On 24/08/2012 09:44 AM, Lew Schwartz wrote:
> I never understood why these routines would be any better than max()+1. Are
> they any faster? Also, can't these strings contain inadvertent 'bad' words?
>
> On Fri, Aug 24, 2012 at 4:52 AM, Dave Crozier <[email protected]> wrote:
>
>> Why not use thee routines to produce true Guids like Paul has said, then
>> there is never a possibility of key duplicates:
>>
>> ****************
>> * Start Code
>> *
>> FUNCTION StringFromGUID(cGUID)
>>      LOCAL cBuffer, nBufsize
>>      nBufsize=128
>>      cBuffer = REPLICATE(CHR(0), nBufsize*2)
>>      = StringFromGUID2(cGUID, @cBuffer, nBufsize)
>>      cBuffer = SUBSTR(cBuffer, 1, AT(CHR(0)+CHR(0), cBuffer))
>> RETURN STRCONV(cBuffer, 6)
>>
>> function CreateGuid()
>>           DECLARE INTEGER CoCreateGuid IN ole32 STRING @pguid
>>
>>      DECLARE INTEGER CLSIDFromString IN ole32;
>>          STRING lpsz, STRING @pclsid
>>
>>      DECLARE INTEGER StringFromGUID2 IN ole32;
>>          STRING rguid, STRING @lpsz, INTEGER cchMax
>>
>>          LOCAL cGUID, cGUIDString, cGUID1
>>          cGUID = REPLICATE(CHR(0), 16)  && 128 bits
>>
>>          IF CoCreateGuid(@cGUID) = 0
>>          cGUIDString = StringFromGUID(cGUID)
>>           *? cGUID
>>           *? cGUIDString
>>
>>          * converting from String back to GUID
>>          cGUID1 = REPLICATE(CHR(0), 16)
>>          = CLSIDFromString(STRCONV(cGUIDString,5), @cGUID1)
>>
>>          *? cGuid1
>>          endif
>>
>>          return Substr(cGuidString, 2, Len(cGuidString)-2)
>>          *
>> endfunc
>> *
>> * End Code
>> **************
>>
>> Dave
>>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to