Unicode in ExecuteDirect()

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
dualsoft
Posts: 7
Joined: Wed 28 Oct 2009 11:17

Unicode in ExecuteDirect()

Post by dualsoft » Mon 13 Dec 2010 14:42

I have D2011 and DbxSda 4.75.27
I write into one nvarchar field with SQLConnection.ExecuteDirect().
With parameters is all ok:

Code: Select all

  ps := TParams.Create(nil);
  p := ps.AddParameter;
  p.Name := '1';
  p.DataType := ftWideString;
  p.ParamType := ptInput;
  p.Value := 'ȘȚщЩ';
  SQLConnection1.Execute('UPDATE table SET Field=?', ps);
  ps.Free;
But directly writing unicode characters do not work:

Code: Select all

SQLConnection1.ExecuteDirect('UPDATE table SET Field=''ȘȚщЩ''')
All unicode characters is replaced with ?

In MySQL and utf8 I do not have this problem.
Last edited by dualsoft on Tue 14 Dec 2010 11:32, edited 1 time in total.

dualsoft
Posts: 7
Joined: Wed 28 Oct 2009 11:17

Post by dualsoft » Tue 14 Dec 2010 09:17

Same problem with TSQLQuery when I use unicode in WHERE clause for example. The result dataset is empty probably because unicode characters is changed with ?
When I work with Params all is OK.

AndreyZ

Post by AndreyZ » Tue 14 Dec 2010 12:18

Hello,

You should use this code:

Code: Select all

SQLConnection1.ExecuteDirect('UPDATE table SET Field=N''ȘȚùÙ''')
In this case you explicitly define that Field is nvarchar.

dualsoft
Posts: 7
Joined: Wed 28 Oct 2009 11:17

Post by dualsoft » Tue 14 Dec 2010 13:47

Thank you very much.
I think the problem is from SQL Server because from SQL Server Management Studio the problem is same.

AndreyZ

Post by AndreyZ » Tue 14 Dec 2010 14:00

Yes, this is not SDAC problem.
If any other questions come up, please contact us.

Post Reply