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.
tygrys
Junior Boarder
Junior Boarder
Posts: 33
Joined: 09.12.2005, 18:31
Location: Poland

stringfield vs widestring field

Postby tygrys » 19.02.2013, 07:28

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 Dev Team
Zeos Dev Team
Posts: 1701
Joined: 31.03.2011, 22:38

Postby EgonHugeist » 19.02.2013, 11:41

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?
King regards, Michael

You want to help? 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

Postby tygrys » 19.02.2013, 13:40

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 Dev Team
Zeos Dev Team
Posts: 1701
Joined: 31.03.2011, 22:38

Postby EgonHugeist » 19.02.2013, 14:59

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.
King regards, Michael

You want to help? 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
Fresh Boarder
Fresh Boarder
Posts: 21
Joined: 23.01.2015, 00:04

Re: stringfield vs widestring field

Postby mac_srv » 29.04.2015, 18:48

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
Fresh Boarder
Fresh Boarder
Posts: 21
Joined: 23.01.2015, 00:04

Re: stringfield vs widestring field

Postby mac_srv » 05.05.2015, 00:51

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

Postby raosistemas » 23.03.2016, 09:24

in my SQL the solution is the same?

User avatar
EgonHugeist
Zeos Dev Team
Zeos Dev Team
Posts: 1701
Joined: 31.03.2011, 22:38

Re: stringfield vs widestring field

Postby EgonHugeist » 30.03.2016, 03:54

Indeed, it is..
King regards, Michael

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

Image


Return to “ZeosLib 7.0 Stable Forum”

Who is online

Users browsing this forum: No registered users and 1 guest