Recent

Author Topic: ODBC/TSQLQuery:TWideStringField.AsString returns '???'  (Read 4926 times)

tk

  • Sr. Member
  • ****
  • Posts: 367
ODBC/TSQLQuery:TWideStringField.AsString returns '???'
« on: October 01, 2009, 12:49:17 pm »
Hi,
I'm testing a connection to my MSSQL database via Lazarus TODBCConnection/TSQLQuery/TSQLTransaction. I cannot display my nvarchar columns properly. For example in my TDBEdit I get '???' for these columns and any record. I discovered the problem is located at TWideStringField.AsString which returns '???' instead of valid text. The same result I get for TWideStringField.AsWideString.

Has anybody similar experience?

Thx

Zoran

  • Hero Member
  • *****
  • Posts: 1655
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ODBC/TSQLQuery:TWideStringField.AsString returns '???'
« Reply #1 on: October 01, 2009, 06:53:05 pm »
Try using UTFEncode function.
Perhaps putting the Field's OnGetText event would be the best for you. Something like this:

Quote
procedure TForm1.SQLQuery1Field1GetText(Sender: TField;
  var aText: string; DisplayText: Boolean);
begin
  aText := UTF8Encode(Sender.AsString);
end;

After that you can use Field1.AsString normally.

tk

  • Sr. Member
  • ****
  • Posts: 367
Re: ODBC/TSQLQuery:TWideStringField.AsString returns '???'
« Reply #2 on: October 01, 2009, 11:21:17 pm »
I tried now and didn't get expected results. It seems to be a FPC problem. The dataset (or something else) assigns a TWideStringField for a table field that is natively not UTF16. I tried the following code and got expected text in S for this case:

Code: [Select]
var
  S: string;
...
SetLength(S, AField.DataSize);
AField.GetData(@S[1], True);
...

Of course I cannot use this because in other cases where fields are natively in UTF16 format this would not work. Perhaps I should place new issue in FPC bugtracker later.

Zoran

  • Hero Member
  • *****
  • Posts: 1655
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: ODBC/TSQLQuery:TWideStringField.AsString returns '???'
« Reply #3 on: October 02, 2009, 09:00:37 am »
Did you look in the LConvEncoding unit? Apart from functions for converting particular character sets, in that unit you can also find the function named GuessEncoding. I haven't tried this function, maybe it can help you determine whether the string you got from database is UTF16 or not, and if not, which encoding it is.

I don't know... I hope that someone better experienced in this than me will have to say something to help you.
« Last Edit: October 02, 2009, 09:02:17 am by zoran »

calvarez

  • Newbie
  • Posts: 3
Re: ODBC/TSQLQuery:TWideStringField.AsString returns '???'
« Reply #4 on: November 06, 2009, 02:04:57 pm »
I'm trying to connect to a MSSQL server from Linux. You could connect mssql from linux?

Thanks for your time.

 

TinyPortal © 2005-2018