TMSParam AsGuid?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jmuehlenhoff
Posts: 36
Joined: Fri 30 Apr 2010 11:25

TMSParam AsGuid?

Post by jmuehlenhoff » Tue 08 Apr 2014 14:01

Hi,

It is possible to set a TMSParam to `DataType := ftGuid`.

However there is no `AsGuid` property and I can not see any obvious way to assign a TGUID to that parameter?!

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

Re: TMSParam AsGuid?

Post by AlexP » Wed 09 Apr 2014 08:59

Hello,

Parameters don't have the AsGuid property (the TGuidField field has this property). You can work with GUID parameters as with strings(asString).

jmuehlenhoff
Posts: 36
Joined: Fri 30 Apr 2010 11:25

Re: TMSParam AsGuid?

Post by jmuehlenhoff » Wed 09 Apr 2014 09:38

Ok, I can live with that.

The other thing is, when I visually edit the Params property from the IDE it is not possible to enter a GUID value for a guid parameter (the edit is disabled).

No big deal, but this is a bit inconsistent.

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

Re: TMSParam AsGuid?

Post by AlexP » Wed 09 Apr 2014 10:36

There is no possibility to set complex data types (TGUID = packed record) in the parameter editor, and when assigning data with asString - the parameter type changes to ftString.

jmuehlenhoff
Posts: 36
Joined: Fri 30 Apr 2010 11:25

Re: TMSParam AsGuid?

Post by jmuehlenhoff » Wed 09 Apr 2014 10:47

That means that TGUID must be converted to a string in the Delphi code, is sent to the SQL Server as a string and is then converted by the SQL Server to UNIQUEIDENTIFIER.

As a perfectionist I would like to avoid as many data type conversions as possible.

Don't get me wrong, as long as this has no major performance or correctness problems (which I see no indications for) it is not my first priority.

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

Re: TMSParam AsGuid?

Post by AlexP » Wed 09 Apr 2014 13:17

Independently on the used method (Value, asString or AsGuid), GUID will be mapped to string. However, if you set the parameter type as ftGuid, then GUID will be sent to the server, i.e., backward conversion will be performed.

MSQuery1.SQL.Text := 'insert into test_guid(f_guid) values(:f_guid)';
MSQuery1.ParamByName('f_guid').DataType := ftGuid;
MSQuery1.ParamByName('f_guid').Value := '{5E958A8D-8CA2-4E99-810C-D42409B38E0F}';
MSQuery1.Execute; // GUID will be sent to the server

Post Reply