Tech Tip: Remember that UUID formats may differ when using external data sources
PRODUCT: 4D | VERSION: 12.3 | PLATFORM: Mac & Win
Published On: September 23, 2011
When inserting a UUID into an external data source, such as Microsoft SQL Server, it is important to format the UUID as the external data source is expecting it.
In the case of Microsoft SQL Server one must add hyphens to the string value to match the canonical representaion of a UUID format. This can be easily accomplished like this:
C_TEXT(sqluiid;mssqluiid) sqluiid:=Generate UUID mssqluiid:=Substring(sqluiid;1;8)+"-"+Substring(sqluiid;9;4)+"-"+Substring(sqluiid;13;4)+"-"+Substring(sqluiid;17;4)+"-"+Substring(sqluiid;21;12) SQL LOGIN("ODBC:mssql";"user";"pass";*) Begin SQL INSERT INTO sales (uuid,a,b,c) VALUES (:mssqluiid,:param2,:param3,:param4); End SQL SQL LOGOUT |
This would convert a plain text UUID like this: FA72EEA3814DF7469E976400534D78EA
To its canonical format (8-4-4-4-12) like this: FA72EEA3-814D-F746-9E97-6400534D78EA
Other data sources may prefer a different format. In any case, it is always important to check with the data source structure you are connecting to in order to make sure you have the correct format.