Uniqueidentifier string format

Uniqueidentifier string format

Postby rosa » Wed 25 May 2011 07:42

Hello,

I noticed that dbExpress creates TStringField for the UniqueIdentifier fields. Can I change the format of the resulting string somehow? In particular I'd like to remove curly brackets.
rosa
 
Posts: 2
Joined: Wed 25 May 2011 07:29

Postby AndreyZ » Wed 25 May 2011 11:36

Hello,

To remove curly brackets from the uniqueidentifier column, you can use persistent fields and the OnGetText event handler in the following way:
Code: Select all
procedure TMainForm.ClientDataSetuidGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
  Text := Copy(Sender.AsString, 2, Length(Sender.AsString) - 2);
end;
AndreyZ
 

Postby rosa » Thu 26 May 2011 08:46

AndreyZ wrote:Hello,

To remove curly brackets from the uniqueidentifier column, you can use persistent fields and the OnGetText event handler in the following way:
Code: Select all
procedure TMainForm.ClientDataSetuidGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
  Text := Copy(Sender.AsString, 2, Length(Sender.AsString) - 2);
end;


This is of course possible, but I can't use such approach(persistent fields) in my case. The application would have to handle every uniqueidentifier field this way explicitly, but it simply doesn't know them:-(( Moreover, the described solution might work with dbGrid, but not when applying filters on the dataset - I guess.
I'd rather have dbExpress driver (or the underlaying sql server client library) configured to behave the required way for every uniqueidentifier field in the database implicitly - if possible.
rosa
 
Posts: 2
Joined: Wed 25 May 2011 07:29

Postby AndreyZ » Thu 26 May 2011 12:19

You can cast uniqueidentifier fields to string in the following way:
Code: Select all
SQLQuery.SQL.Text := 'select cast(uid as varchar(40)) uid from tablename';
ClientDataSet.Open;
AndreyZ
 


Return to dbExpress driver for SQL Server

cron