stringfield vs widestring field

The stable tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.
Post Reply
tygrys
Junior Boarder
Junior Boarder
Posts: 33
Joined: 09.12.2005, 18:31
Location: Poland

stringfield vs widestring field

Post by tygrys »

My database is using ANSI encoding (WIN1250)
My Delphi is unicode - XE.

I have a code:

Code: Select all

      
      Query.SQL.Text := 'SELECT Tekst FROM table';
      with TStringField.Create(Query) do 
      begin
        FieldName := 'Tekst';
        Name := 'tableTekst';
        Index := 0;
        DataSet := Query;
      end;
      Query.FieldDefs.Update;
      Query.Open;

I get the EDatabaseError: 'Type mismatch for field 'Tekst', expecting: String actual: WideString'.

I need to set ControlsCodePage to cGET_ACP to let it work as needed. But as said before in 7.0 Beta thread, for unicode Delphi this should be set to cCP_UTF16. I'm confused here.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

tygrys,

IMHO, this behavior is expected. Well it might be possible you don't know how Delphi-Unicode behaves in this case? The TStringField doesn't allow the UnicodeString. Delphi does cast all Strings down to AnsiStrings. Your Database-Encoding with 1250 doesn't matter for Zeos. The implementations we have do savely convert all codepages up to the UnicodeString. You won't have any speed decrease here. Controls CP GetAcp starts allways from the premisse the TStringField is used and all character/text-fields are TStringField/TMemoField.

Whaich means assign a TStringField with a UnicodeString Delphi cast the Strings down to AnsiStrings in the FieldBuffers and on reading vice versa. Curious? Yes it is.

If your create a TWideString-Field instead, than your code should work too.. Right?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
tygrys
Junior Boarder
Junior Boarder
Posts: 33
Joined: 09.12.2005, 18:31
Location: Poland

Post by tygrys »

EgonHugeist wrote: Which means assign a TStringField with a UnicodeString Delphi cast the Strings down to AnsiStrings in the FieldBuffers and on reading vice versa. Curious? Yes it is.
This is a right path, because table field is if fact AnsiString and the control use unicodestrings. So the conversion is right at this moment.
EgonHugeist wrote: If your create a TWideString-Field instead, than your code should work too.. Right?
Yes, but there is no need to have a WideString TField to hold AnsiString data - as it is AnsiString on the database side. I do not want a TWideStringField here, because if I switch to other data access components they will assume a TStringField here - and a transition will be painfull. Now I have only to implement connection and query create methods.

There was no such problem with Zeos 7.0 Beta EH branch, at least to November edition I used before.

Can you confirm that if I work only with Ansi strings on the database side I can safely use cGET_ACP in Delphi XE? Are there any side effects of this? Or I miss something here ?
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

tygrys,

I don't know anything about side effects. Our current tests don't show me something like that. Thats why i introduced the TZControlsCodepage-option. It's your choice what you want.. This enum simple tells Zeos which FieldTypes should be assumed. This option is much more interesting with the Ansi-Compilers where Wide/ANSI/UTF8 support is much more interesting.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
mac_srv
Senior Boarder
Senior Boarder
Posts: 50
Joined: 23.01.2015, 00:04

Re: stringfield vs widestring field

Post by mac_srv »

Hi,

I have the same problem (please let me know if I might start a new thread):

EDatabaseError: 'Type mismatch for field 'Name', expecting: String actual: WideString'.

My C++Builder code is querying a Firebird 2.5 database/table with VARCHAR(20) fields, mapped as TStringFields and linked to TZQuery in a TDataModule.

Here is my basic connection description:

ControlsCodePage = cGET_ACP
Firebird 2.5
ZeosLib 7.2.0-beta
RAD 2009

Reading this thread, I've expected that cGET_ACP should avoid this error.

Note: the same code is working with BDS 2006, so I think it is really the case of ControlsCodePage usage, isn't it?

Thank you in advance,

Marcelo.
mac_srv
Senior Boarder
Senior Boarder
Posts: 50
Joined: 23.01.2015, 00:04

Re: stringfield vs widestring field

Post by mac_srv »

Hi,

I'm sorry about the last post. I now realized a mistake and I would like to share it in order to not misleading other readers.

Setting "ControlsCodePage = cGET_ACP" works properly as expected.

I've done a mistake into my code just before setting a "ROLENAME" property:

Code: Select all

ZConnection->Properties->Clear();  //Here is the problem. Comment or delete this line.
...
ZConnection->Properties->Add("ROLENAME=" + PrmRoleName);
Thanks anyway.

Marcelo.
raosistemas
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 03.09.2009, 11:35
Location: Jundiaí
Contact:

Re: stringfield vs widestring field

Post by raosistemas »

in my SQL the solution is the same?
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: stringfield vs widestring field

Post by EgonHugeist »

Indeed, it is..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply