Page 1 of 1
TMSParam AsGuid?
Posted: Tue 08 Apr 2014 14:01
by jmuehlenhoff
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?!
Re: TMSParam AsGuid?
Posted: Wed 09 Apr 2014 08:59
by AlexP
Hello,
Parameters don't have the AsGuid property (the TGuidField field has this property). You can work with GUID parameters as with strings(asString).
Re: TMSParam AsGuid?
Posted: Wed 09 Apr 2014 09:38
by jmuehlenhoff
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.
Re: TMSParam AsGuid?
Posted: Wed 09 Apr 2014 10:36
by AlexP
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.
Re: TMSParam AsGuid?
Posted: Wed 09 Apr 2014 10:47
by jmuehlenhoff
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.
Re: TMSParam AsGuid?
Posted: Wed 09 Apr 2014 13:17
by AlexP
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