Page 1 of 1

Unicode in ExecuteDirect()

Posted: Mon 13 Dec 2010 14:42
by dualsoft
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.

Posted: Tue 14 Dec 2010 09:17
by dualsoft
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.

Posted: Tue 14 Dec 2010 12:18
by AndreyZ
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.

Posted: Tue 14 Dec 2010 13:47
by dualsoft
Thank you very much.
I think the problem is from SQL Server because from SQL Server Management Studio the problem is same.

Posted: Tue 14 Dec 2010 14:00
by AndreyZ
Yes, this is not SDAC problem.
If any other questions come up, please contact us.