Hello,
I am trying to use Guid from a c# application.
I store a Guid to fb database using
“INSERT INTO PROJECTS (ProjGID, PROJCODE, PROJTITLE) VALUES (char_to_uuid('7104D437-ACD5-4781-918F-3A049DB1CFCA'), 'proj', 'projtitle')”.
ProjGID is defined as char(16) character set octets
Following that I load the data using
"Select uuid_to_char(PROJGID) as id , Projects.ProjGID from Projects"
In the DataTable I get the two values but they differ. The correct one is the one returned by uuid_to_char. The Projects.ProjGID is a Guid DataType but the value is different.
Any ideas?
Yannis
I had the same problem and I created this function
CREATE OR ALTER FUNCTION UUID_TO_GUID(
REAL_UUID CHAR(16))
RETURNS VARCHAR(36)
AS
declare variable i integer;
declare variable c integer;
declare variable hex_uuid varchar(36);
BEGIN
hex_uuid = '';
-- 1 2 3 4- 5 6- 7 8- 910-111213141516
--b2b3a6ee-f411-434c-a807-40588ad2a63c lower(uuid_to_char)
-- 4 3 2 1- 6 5- 8 7- 910-111213141516
--eea6b3b2-11f4-4c43-a807-40588ad2a63c dotnet guid
--eea6b3b2-11f4-4c43-a807-40588ad2a63c result
i = 3;
while (i>=0) do begin
c = ascii_val(substring(real_uuid from i+1 for 1));
if (c < 0) then c = 256 + c;
hex_uuid = hex_uuid
|| substring('0123456789abcdef' from bin_shr(c, 4) + 1 for 1)
|| substring('0123456789abcdef' from bin_and(c, 15) + 1 for 1);
i = i - 1;
end
hex_uuid = hex_uuid ||'-';
i = 5;
while (i>=4) do begin
c = ascii_val(substring(real_uuid from i+1 for 1));
if (c < 0) then c = 256 + c;
hex_uuid = hex_uuid
|| substring('0123456789abcdef' from bin_shr(c, 4) + 1 for 1)
|| substring('0123456789abcdef' from bin_and(c, 15) + 1 for 1);
i = i - 1;
end
hex_uuid = hex_uuid ||'-';
i = 7;
while (i>=6) do begin
c = ascii_val(substring(real_uuid from i+1 for 1));
if (c < 0) then c = 256 + c;
hex_uuid = hex_uuid
|| substring('0123456789abcdef' from bin_shr(c, 4) + 1 for 1)
|| substring('0123456789abcdef' from bin_and(c, 15) + 1 for 1);
i = i - 1;
end
hex_uuid = hex_uuid ||'-';
i = 8;
while (i < 10) do
begin
c = ascii_val(substring(real_uuid from i+1 for 1));
if (c < 0) then c = 256 + c;
hex_uuid = hex_uuid
|| substring('0123456789abcdef' from bin_shr(c, 4) + 1 for 1)
|| substring('0123456789abcdef' from bin_and(c, 15) + 1 for 1);
i = i + 1;
end
hex_uuid = hex_uuid ||'-';
i = 10;
while (i < 16) do
begin
c = ascii_val(substring(real_uuid from i+1 for 1));
if (c < 0) then c = 256 + c;
hex_uuid = hex_uuid
|| substring('0123456789abcdef' from bin_shr(c, 4) + 1 for 1)
|| substring('0123456789abcdef' from bin_and(c, 15) + 1 for 1);
i = i + 1;
end
return hex_uuid;
end
Select UUID_TO_GUID (PROJGID) as id , Projects.ProjGID from Projects
De : firebird-n...@googlegroups.com [mailto:firebird-n...@googlegroups.com] De la part de ymaka...@gmail.com
Envoyé : mardi 8 mai 2018 18:57
À : firebird-net-provider
Objet : Re: Guid in firebird
--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
To post to this group, send email to firebird-n...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/5c16d538-25d1-4d81-91e7-95a1c02a47f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I am using char(16) character set octets and it works
--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
To post to this group, send email to firebird-n...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/e8b752f2-b089-4c44-a1c3-8008dbf3e667%40googlegroups.com.