I am working in an older version of IB that does not have the GEN_UUID() 
function, so I am working on implementing the function as a UDF, but it is 
giving me an "arithmetic exception, numeric overflow, or string truncation".  I 
looking at the FB source to see how it is implemented there, but internal 
functions are implemented in noticeably different ways then an UDF.  

Here is what I got:

char* EXPORT fn_GEN_UUID()      
{
        int size = sizeof(GUID) + 1;
        GUID *guidBuff = (GUID*) ib_util_malloc(size);
        ::ZeroMemory(guidBuff, size);

        ::CoCreateGuid(guidBuff);

        return (char *) guidBuff;
}

/* --------------------------------- */

DECLARE EXTERNAL FUNCTION GEN_UUID
    RETURNS CHAR(16) FREE_IT
    ENTRY_POINT 'fn_GEN_UUID' MODULE_NAME 'UDF_GEN_UUID';

CREATE DOMAIN UNIQUEIDENTIFIER AS 
 CHAR(16) CHARACTER SET OCTETS
 NOT NULL COLLATE OCTETS;

CREATE TABLE TEST_UUID 
(
  PKID              INTEGER         NOT NULL,
  UUID_VALUE        UNIQUEIDENTIFIER
);

/* --------------------------------- */

INSERT INTO TEST_UUID ( PKID, UUID_VALUE) VALUES ( 1, GEN_UUID());

Reply via email to