Any ideas on how to generate a GUID in PB 2017 with DB2 as the database.
Thanks,
KB
Any ideas on how to generate a GUID in PB 2017 with DB2 as the database.
Thanks,
KB
My EmailSMTP uses the Windows API functions mentioned in other answers to generate a UUID.
Here another way with external functions:
// external functions
Function long UuidCreate ( Ref os_UUID pId ) Library "rpcrt4.dll"
Function long UuidToString ( Ref os_UUID Uuid, Ref ulong StringUuid ) Library "rpcrt4.dll" Alias For "UuidToStringW"
Function long RpcStringFree ( Ref ulong pString ) Library "rpcrt4.dll" Alias For "RpcStringFreeW"
Subroutine CopyMemory ( Ref string Destination, ulong Source, long Length ) Library "kernel32.dll" Alias For "RtlMoveMemory"
// structure
type os_uuid from structure
unsignedlong data1
integer data2
integer data3
blob data4
end type
//Function of_generate_guid
os_UUID lstr_UUID
Constant Long RPC_S_OK = 0
Constant Long SZ_UUID_LEN = 36
ULong lul_ptrUuid
String ls_Uuid
lstr_UUID.Data4 = Blob(Space(8), EncodingAnsi!)
If UuidCreate(lstr_UUID) = RPC_S_OK Then
If UuidToString(lstr_UUID, lul_ptrUuid) = RPC_S_OK Then
ls_Uuid = Space(SZ_UUID_LEN)
CopyMemory(ls_Uuid, lul_ptrUuid, SZ_UUID_LEN * 2)
RpcStringFree(lul_ptrUuid)
ls_Uuid = Upper(ls_Uuid)
End If
End If
Return ls_Uuid
1. Create a global external function
FUNCTION long uuidCreate(ref s_uuid astr_uuid) LIBRARY "Rpcrt4.dll" ALIAS FOR "UuidCreate"
*********************************************************************************************************************
2. Create a global function f_generate_uuid
Function f_generate_uuid(String as_type)
It seems that there are a number of way to generate GUID in DB2, have you looked at the link below:
https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/generating_universally_unique_identifiers_uuid63?lang=en
You should be able to utilise any of these methods within PB.
Regards
David