Page 1 of 1

TField.Size different from db when varchar

Posted: 24.10.2014, 02:21
by rrricci
Hello all, some time ago, there was a long discussion about this issue, and searching this forum, i found this link http://zeoslib.sourceforge.net/viewtopi ... =33&t=3611 where at the last message our friend EgonHugeist gave a solution. However, I would like to know if this solution is valid for Lazarus 1.2.X., because I use it with zeos version 7.1.3 and the problem still persists. I mean, if the table contains a varchar(10) column, when I add it to the TZQuery, it comes with 40 at Size property. is there any workaround for this issue?

Thanks.

Renato

Re: TField.Size different from db when varchar

Posted: 27.10.2014, 00:52
by EgonHugeist
Hi Renato,

uh this post was long ago. From my oppinion .. NO if you use UTF8-Fields and i'm starting from the premisse you are doing that LCL+UTF8 is recommend, i think.

Thought i've been trying to align the DisplaySize instead?

Re: TField.Size different from db when varchar

Posted: 27.10.2014, 02:06
by rrricci
Thanks for replying..
Ohh yes! You were trying to align Size and Display properties. Sorry.

Correct, I use LCL + UTF8 fields.
DB Field Size: varchar(10)
TField.Size after import: 40

My question is: most people use to use the Size property to control the maxlength of a DbEdit, and with the current behavior of Zeos, the Size property comes with 4 times more than the value we defined at table(UTF8 in my case), which means that, maxlength is now 4 times larger then table field and when we try to insert and commit a record larger than 10, a exception message raises saying: 'Value too long for type character varying (10)'.

With this scenario, I understand that from now on, the only way to avoid those error messages is setting the maxlength of each dbedit to the equivalent database field size. Am I right?

PS.: I also tried the same thing with other components, and all of them bring TField.Size 10 (just like table field size). Why is Zeos behavior different from others?

Thanks again!
Renato

Re: TField.Size different from db when varchar

Posted: 28.10.2014, 00:42
by EgonHugeist
rrricci wrote:PS.: I also tried the same thing with other components, and all of them bring TField.Size 10 (just like table field size). Why is Zeos behavior different from others?
May i start from the premisse you're talking about SQLDB? These components ?have? some problems in this domain.

Note VARCHAR(10) = 10Chars x MaxBytes/Char. On PostgreSQL it means at least 40Bytes. This is made because of UTF8 overlongs which need to fit into the DataBase. Ever played with MBCS encodings vs. UCS2 etc?
In all cases we need to reserve enough space to be able to store MBCS chars in TField-Buffer..

Re: TField.Size different from db when varchar

Posted: 28.10.2014, 01:51
by rrricci
Yes, you got it. I was talking about SqlDB.

Ok. I understood now.. So I think the only way to control maxlength is set directly to the dbedit field one by one.

For those who's having the same problem, may be interesting to read this article: http://forum.lazarus.freepascal.org/ind ... l#msg36739

Thanks.

Renato