GUID in Firebird

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
chkaufmann
Posts: 82
Joined: Sat 01 Jul 2006 11:42

GUID in Firebird

Post by chkaufmann » Tue 17 Jun 2014 13:51

What is the preferred format to save a GUID in Firebird 2.5 using UniDAC?

Is there a format that will return fields of type "ftGuid" or do I need my own Data Type Mapping?

How should the Data Type Mapping look like?

cu Christian

PavloP
Devart Team
Posts: 149
Joined: Fri 24 Jan 2014 12:33

Re: GUID in Firebird

Post by PavloP » Wed 18 Jun 2014 09:41

To store GUID in Firebird, you can use the varchar data type. To retrieve fields of the "ftGuid" type, you can use Data Type Mapping.
For instance, to set mapping of a field with "GUID" name to the ftGUID type, use the following code:

Code: Select all

UniTable1.DataTypeMap.AddFieldNameRule('GUID',ftGuid);
More details about Data Type Mapping can be found at: http://www.devart.com/unidac/docs/index ... apping.htm

chkaufmann
Posts: 82
Joined: Sat 01 Jul 2006 11:42

Re: GUID in Firebird

Post by chkaufmann » Wed 18 Jun 2014 10:05

Meanwhile I tried to setup a guid for Oracle. The common data type here seems to be RAW(16).

There are different problems now:
  • The column type RAW(16) is returned as TVarBinaryField and I did not succeed to make a mapping to ftGuid.
  • Even if I read this column using "AsBytes" it's converted to a variant "array of byte" and I remember from an earlier project that this is terrible slow.
So I'm not sure, if I should implement my own TGuidField class for that. And where should I register id?

Same question for Firebird because the default TGuidField class is based on TStringField and uses a 38 character representation. 32 characters would be far enough.

Or did already somebody "unify" the GUID handling for all databases (Firebird, Oracle, MySql, PostgreSQL, MS SQL Server)?

cu Christian

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: GUID in Firebird

Post by AlexP » Thu 19 Jun 2014 10:13

Hello,

Currently, you can map the type in the query using the RAWTOHEX Oracle function:

Code: Select all

SELECT RAWTOHEX(f_fuid) FROM t_table
In this case, in Delphi the field will be mapped as ftString. We have added mapping from Raw to ftGuid, This feature will be included in the next version.

Yes, TGuidField uses 38 symbols, therefore use varchar(38) fields for storing GUID in Firebird.

chkaufmann
Posts: 82
Joined: Sat 01 Jul 2006 11:42

Re: GUID in Firebird

Post by chkaufmann » Thu 19 Jun 2014 11:12

I did some more research and tests. Finally I use the following data types for GUID's:

MS SQL Server: UNIQUEIDENTIFIER
Oracle: RAW(16)
Firebird: CHAR(16) CHARACTER SET OCTETS

For Firebird I found a post in the dev newsgroups where this was described as the data type that will be used, if native support for guid will be added to Firebird.

Performance with "AsBytes" (Firebird, Oracle) isn't that bad at all. For now I handle the "unification" in my own wrapper classes, but of course it would be nice to have this in UniDac. But for real full integration I see limitations coming from Delphi:
- TVarRec.VType doesn't have/support a "vtGuid"
- The base class TField has no AsGuid property

cu Christian

Post Reply