Forums Últimos mensajes - Powered by IBM
 

obtener equivalante a newid() de sql

21/07/2008 - 03:40 por Javier | Informe spam
Saludos!

En mi aplicacion obtengo atravez de la ejecucion del NEWID usando SPT. lo
cual en un preseso en que el resultado sean muchos registros que grabar hace
necesario la ejecucion reiterada y si la coneccion es via VPN esto relentiza
el proceso

Es posible generar una cadena unica como la que genera sql server con la
funcion NEWID(). esta genera un resultado unico, alguien ha desarrollado una
funcion similar sabe como hacerlo.

resultado de de newid: "7CF11DA3-18D3-4AE1-A11D-68ACBCA25D1B"

Javier
 

Leer las respuestas

#1 Carlos Alloatti
22/07/2008 - 03:09 | Informe spam
On 20 jul, 22:40, Javier wrote:
Saludos!

En mi aplicacion obtengo atravez de la ejecucion del NEWID usando  SPT. lo
cual en un preseso en que el resultado sean muchos registros que grabar hace
necesario la ejecucion reiterada y si la coneccion es via VPN esto relentiza
el proceso

Es posible generar una cadena unica como la que genera sql server con la
funcion NEWID(). esta genera un resultado unico, alguien ha desarrollado una
funcion similar sabe como hacerlo.

resultado de de newid: "7CF11DA3-18D3-4AE1-A11D-68ACBCA25D1B"

Javier



Fijate estas funciones (a pesar de que hay funciones API para pasar de
cadena binaria de 16 bytes a representacion hexadecimal, hacerlo con
código VFP es más rapido)


********************************************************************************
*!* GUID FUNCTIONS
********************************************************************************
*!* http://www.ietf.org/rfc/rfc4122.txt
*!* http://en.wikipedia.org/wiki/Global...Identifier
*!* http://en.wikipedia.org/wiki/Univer...Identifier

********************************************************************************
*!* Returns a new binary 16 byte GUID

*!* In Windows NT 4.0, Windows Me/98, and Windows 95 DCOM release,
UuidCreate returns
*!* RPC_S_UUID_LOCAL_ONLY when the originating computer does not have
an ethernet/token ring
*!* (IEEE 802.x) address. In this case, the generated UUID is a valid
identifier, and is guaranteed
*!* to be unique among all UUIDs generated on the computer. However,
the possibility exists that
*!* another computer without an ethernet/token ring address generated
the identical UUID.
*!* Therefore you should never use this UUID to identify an object
that is not strictly local to
*!* your computer. Computers with ethernet/token ring addresses
generate UUIDs that are guaranteed
*!* to be globally unique.
********************************************************************************
Function ctlNewGuid()

Local m.lcGuid As String

m.lcGuid = Replicate(Chr(0xFF), 16)
apiUuidCreate(@m.lcGuid)

Return m.lcGuid
Endfunc

********************************************************************************
Function ctlNewGuidNil()

Local m.lcGuid As String

m.lcGuid = Replicate(Chr(0xFF), 16)
apiUuidCreateNil(@m.lcGuid)

Return m.lcGuid
Endfunc

********************************************************************************
Function ctlNewGuidSequential()

Local m.lcGuid As String

m.lcGuid = Replicate(Chr(0xFF), 16)
apiUuidCreateSequential(@m.lcGuid)

Return m.lcGuid
Endfunc

********************************************************************************
*!* Returns a new 32 char GUID string
*!* Format "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
********************************************************************************
Function ctlNewGuidString32()
Return ctlGuidToString32(ctlNewGuid())
Endfunc

********************************************************************************
*!* Returns a new 36 char GUID string
*!* Format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
********************************************************************************
Function ctlNewGuidString36()
Return ctlGuidToString36(ctlNewGuid())
Endfunc

********************************************************************************
*!* Returns a new 38 char GUID string
*!* Format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
********************************************************************************
Function ctlNewGuidString38()
Return ctlGuidToString38(ctlNewGuid())
Endfunc

********************************************************************************
*!* Converts a binary 16 byte GUID to a 32 char GUID string
*!* format "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
********************************************************************************
Function ctlGuidToString32(pcGuid As String)

Local m.lcGuidString As String

m.lcGuidString = ""

*!* Reorder GUID bytes
m.lcGuidString = ;
Substr(m.pcGuid, 4, 1) + ;
Substr(m.pcGuid, 3, 1) + ;
Substr(m.pcGuid, 2, 1) + ;
Substr(m.pcGuid, 1, 1) + ;
Substr(m.pcGuid, 6, 1) + ;
Substr(m.pcGuid, 5, 1) + ;
Substr(m.pcGuid, 8, 1) + ;
Substr(m.pcGuid, 7, 1) + ;
Substr(m.pcGuid, 9, 8)

*!* Convert bytes to encoded HexBinary
m.lcGuidString = Strconv(m.lcGuidString, 15)

Return m.lcGuidString
Endfunc

********************************************************************************
*!* Converts a binary 16 byte GUID to a 36 char GUID string
*!* format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
*!* This is faster that using the StringFromGuid2 API call
********************************************************************************
Function ctlGuidToString36(pcGuid As String)

Local ;
m.lcGuidString As String, ;
m.lcGuid As String

m.lcGuidString = ""

*!* Convert bytes to encoded HexBinary
m.lcGuid = Strconv(m.pcGuid, 15)

*!* Reorder GUID bytes, Add hyphens
m.lcGuidString = ;
Substr(m.lcGuid, 07, 02) + ;
Substr(m.lcGuid, 05, 02) + ;
Substr(m.lcGuid, 03, 02) + ;
Substr(m.lcGuid, 01, 02) + ;
"-" + ;
Substr(m.lcGuid, 11, 02) + ;
Substr(m.lcGuid, 09, 02) + ;
"-" + ;
Substr(m.lcGuid, 15, 02) + ;
Substr(m.lcGuid, 13, 02) + ;
"-" + ;
Substr(m.lcGuid, 17, 04) + ;
"-" + ;
Substr(m.lcGuid, 21, 12)

Return m.lcGuidString
Endfunc

********************************************************************************
*!* Converts a binary 16 byte GUID to a 38 char GUID string
*!* format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
*!* This is faster that using the StringFromGuid2 API call
********************************************************************************
Function ctlGuidToString38(pcGuid As String)

Local ;
m.lcGuidString As String, ;
m.lcGuid As String

m.lcGuidString = ""

*!* Convert bytes to encoded HexBinary
m.lcGuid = Strconv(m.pcGuid, 15)

*!* Reorder GUID bytes, Add brackets, hyphens
m.lcGuidString = ;
"{" + ;
Substr(m.lcGuid, 07, 02) + ;
Substr(m.lcGuid, 05, 02) + ;
Substr(m.lcGuid, 03, 02) + ;
Substr(m.lcGuid, 01, 02) + ;
"-" + ;
Substr(m.lcGuid, 11, 02) + ;
Substr(m.lcGuid, 09, 02) + ;
"-" + ;
Substr(m.lcGuid, 15, 02) + ;
Substr(m.lcGuid, 13, 02) + ;
"-" + ;
Substr(m.lcGuid, 17, 04) + ;
"-" + ;
Substr(m.lcGuid, 21, 12) + ;
"}"

Return m.lcGuidString
Endfunc

********************************************************************************
*!* Converts char GUID string to a binary 16 byte GUID
*!* format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
*!* format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
*!* format "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
********************************************************************************
Function ctlGuidFromString(pcGuidString As String)

Local ;
m.lcGuid As String, ;
m.lcGuidString As String

m.lcGuid = ""

*!* Strip brackets and hyphens
m.lcGuidString = Chrtran(m.pcGuidString, "{-}", "")

*!* Reorder GUID string chars
m.lcGuid = ;
+ Substr(m.lcGuidString, 7, 2) ;
+ Substr(m.lcGuidString, 5, 2) ;
+ Substr(m.lcGuidString, 3, 2) ;
+ Left(m.lcGuidString, 2) ;
+ Substr(m.lcGuidString, 11, 2) ;
+ Substr(m.lcGuidString, 9, 2) ;
+ Substr(m.lcGuidString, 15, 2) ;
+ Substr(m.lcGuidString, 13, 2) ;
+ Right(m.lcGuidString, 16)

*!* Convert bytes to decoded HexBinary
m.lcGuid = Strconv(m.lcGuid, 16)

Return m.lcGuid
Endfunc

********************************************************************************
*!* Used just to check the other functions
*!* StringUuid parameter of UuidToString:
*!* Pointer to a pointer to the string into which
*!* the UUID specified in the Uuid parameter will be placed.
*!* UuidToString returns a string in the following format:
*!* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx" (lowercase)
********************************************************************************
Function ctlGuidToStringApi1(m.pcGuid As String)

Local m.lnPointer As Integer

m.lnPointer = 0
apiUuidToString(m.pcGuid, @m.lnPointer)

Return Sys(2600, m.lnPointer, 36)
Endfunc

********************************************************************************
*!* Used just to check the other functions
********************************************************************************
Function ctlGuidToStringApi2(m.pcGuid As String)

Local ;
m.lcGuidString As String, ;
m.lcLen As Integer

*!* Set up buffer: 39 chars * 2 (unicode)
m.lcGuidString = Space(78)
m.lcLen = 78

apiStringFromGUID2(m.pcGuid, @m.lcGuidString, m.lcLen)

*!* Remove double null and convert from Unicode:
Return Strconv(Left(m.lcGuidString, 76), 6)

Endfunc

********************************************************************************
*!* Used just to check the other functions
********************************************************************************
Function ctlGuidFromStringApi(m.pcGuidString As String)

Local ;
m.lcUuid As String, ;
m.lcGuidString As String

*!* Strip brackets and hyphens
m.lcGuidString = Chrtran(m.pcGuidString, "{-}", "")

*!* Add hyphens
m.lcGuidString = ;
LEFT(m.lcGuidString, 8) ;
+ "-" ;
+ Substr(m.lcGuidString, 9, 4) ;
+ "-" ;
+ Substr(m.lcGuidString, 13, 4) ;
+ "-" ;
+ Substr(m.lcGuidString, 17, 4) ;
+ "-" ;
+ Right(m.lcGuidString, 12)

m.lcUuid = Replicate(Chr(0xFF), 16)
apiUuidFromString(m.lcGuidString, @m.lcUuid)
Return m.lcUuid

Endfunc

Function apiUuidCreate(Uuid)
Declare Integer UuidCreate In rpcrt4 As apiUuidCreate ;
String @Uuid
Return apiUuidCreate(@m.Uuid)
Endfunc

Function apiUuidCreateNil(Nil_Uuid)
Declare Integer UuidCreateNil In rpcrt4 As apiUuidCreateNil ;
String @Nil_Uuid
Return apiUuidCreate(@m.Nil_Uuid)
Endfunc

Function apiUuidCreateSequential(Uuid)
Declare Integer UuidCreateSequential In rpcrt4 As
apiUuidCreateSequential ;
String @Uuid
Return apiUuidCreateSequential(@m.Uuid)
Endfunc

Function apiUuidFromString(StringUuid, Uuid)
Declare Integer UuidFromString In rpcrt4 As apiUuidFromString ;
String StringUuid, ;
String @Uuid
Return apiUuidFromString(m.StringUuid, @m.Uuid)
Endfunc

Function apiUuidToString(Uuid, StringUuid)
Declare Integer UuidToString In rpcrt4 As apiUuidToString ;
String Uuid, ;
Integer @StringUuid
Return apiUuidToString(m.Uuid, @m.StringUuid)
Endfunc

Function apiStringFromGUID2(rguid, lpsz, cchMax)
Declare Integer StringFromGUID2 In ole32 As apiStringFromGUID2;
String rguid, ;
String @lpsz, ;
Integer cchMax
Return apiStringFromGUID2(m.rguid, @m.lpsz, m.cchMax)
Endfunc

Estas funciones han sido escritas por mí, cualquier cosa me preguntas.

Carlos Alloatti

Preguntas similares