Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-08

TDBEdit shows 4 characters from a Char(1) field

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

This was brought to my attention in the tiOPF newsgroups. A Firebird 2 database was created using UTF8 as the default character set. A field of type CHAR(1) was created. We inserted a standard ANSI character. eg: 'a' into the field.

We the field value is displayed in a TDBEdit, it has 3 spaces appended to the end. Why? Is this a SqlDB, Firebird or TDBEdit issue?

We then created a field of type VARCHAR(1) and again inserted the ANSI character 'a' into it. TDBEdit now displays it correctly, with no appending spaces.

I'm going to try and access the field without the TDBEdit control (from code) to see what it's length is....

We first suspected FBLib to be the issue. But since then I tried it in Lazarus using SqlDB and the IBConnection component. No change. I'm using Lazarus v0.9.25 r15901M i386-linux-gtk, but this was tested from Windows as well. FPC version 2.2.3

Below is the database and table details. Note that we created a database with a character set of UTF-8.

CREATE DATABASE 'localhost:/tmp/test.fdb'

USER 'SYSDBA' PASSWORD 'masterkey'

PAGE_SIZE 4096

DEFAULT CHARACTER SET UTF8;

CREATE TABLE TABLE1(
TEXT1 Char(1),
TEXT2 Char(2),
TEXT3 Varchar(1),
TEXT4 Varchar(2)
);

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
I'm going to try and access the field without the TDBEdit control (from code) to see what it's length is....

And this was the result:

s = <a > with length = 4

So it seems the issue is not in Lazarus, but SqlDB? Maybe I should raise this issue in the fpc-devel mailing list. I'm first going to read up a bit more on utf-8 support in Firebird 2 - maybe FB has some strange behaviour.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Martin Schreiber
to Graeme Geldenhuys
Graeme Geldenhuys wrote 14 lines
On 8/5/08, Graeme Geldenhuys wrote: > I'm going to try and access the field without the TDBEdit control > (from code) to see what it's length is.... And this was the result: s = <a > with length = 4 So it seems the issue is not in Lazarus, but SqlDB? Maybe I should raise this issue in the fpc-devel mailing list. I'm first going to read up a bit more on utf-8 support in Firebird 2 - maybe FB has some strange behaviour.

Firebird returns the storage size in bytes and not the character length as field size. MSEgui DB components convert from utf-8 or the system encoding to widestring while fetching the field data. The field character length is get from Firebird metadata and applied to tmsestringfield as field size for 16 bit characters.
You are right, this does not work for Klingon. :-)

Martin

Reply by email

Martin Schreiber
to Martin Schreiber
Martin Schreiber wrote 8 lines
Firebird returns the storage size in bytes and not the character length as field size. MSEgui DB components convert from utf-8 or the system encoding to widestring while fetching the field data. The field character length is get from Firebird metadata and applied to tmsestringfield as field size for 16 bit characters. You are right, this does not work for Klingon. :-)

Correction:
MSEgui stores string data in dataset as variable length strings (widestrings), because there is no fix storage size for strings in tmsebufdataset it should work for Klingon too. :-)

Martin

Reply by email

Graeme Geldenhuys
to Martin Schreiber: Firebird returns the storage size in bytes and not the character length as field size.…
Martin Schreiber wrote 9 lines
> read up a bit more on utf-8 support in Firebird 2 - maybe FB has some > strange behaviour. > Firebird returns the storage size in bytes and not the character length as field size. MSEgui DB components convert from utf-8 or the system encoding to widestring while fetching the field data. The field character length is get from Firebird metadata and applied to tmsestringfield as field size for 16 bit characters.

Thanks Martin. When I did a test with CHAR(2) and the Length was 8, I figure it must be using bytes or something. After that I found some more information regarding this and confirming what you said.

Maybe SqlDB developers need to take a peak at MSEgui's DB code as well. Thanks again!

Thinking about this issue, it's going to cause quite an uproar in my applications! Ummm...

You are right, this does not work for Klingon. :-)

:-)
After I finished learning German, I'm starting on Klingon!

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Joost van der Sluis
to Graeme Geldenhuys

Op dinsdag 05-08-2008 om 13:40 uur [tijdzone +0200], schreef Graeme Geldenhuys:

On 8/5/08, Martin Schreiber wrote: Maybe SqlDB developers need to take a peak at MSEgui's DB code as well. Thanks again!

MSEgui's DB code is a fork of sqldb. We know that code quite well.. ;)

Joost.

Reply by email

Graeme Geldenhuys
to Joost van der Sluis
Joost van der Sluis wrote
MSEgui's DB code is a fork of sqldb. We know that code quite well.. ;)

:-) Didn't know that, sorry.

I'll try and investigate this issue further... to find out exactly what needs to be changed. Currently our product is English based, but we already have to foreign clients interested it it and it would need to support Unicode in the database. I'll submit patched if I can.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email