Board index » delphi » Re: why does this work with a varchar but not a char?

Re: why does this work with a varchar but not a char?


2004-01-29 03:58:41 AM
delphi172
Harald Feigel writes:
Quote
Now Edit1.Text is empty which is ok. BUT !!! ALARM, ALARM: Edit2.Text
contains one space character.

Is that a bug? I made use of "Trim Char=TRUE" in my params list of the
TSQLConnection, otherwise Edit2.Text (the TEdit which contains the
Char(20) field) would contain 20 space characters.
IMHO, the *only* correct behavior for CHAR is to *not* use TrimChar
and have the 20 spaces. If you want trimmed char fields, use VARCHAR.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : delphi.weblogs.com
InterBase Performance Monitor -- Analyze and control your IB7
server: delphi.weblogs.com/IBPerformanceMonitor
 
 

Re: why does this work with a varchar but not a char?

Hi all,
posted about the same question some threads below. But have found something
intersting. Assume, i have simple table in Interbase (currently IB 5.5):
CREATE TABLE TEST (
Id INTEGER,
FieldA VARCHAR(20),
FieldB CHAR(20))
Now i insert a record into that table with Interbase Windows ISQL like:
INSERT INTO TEST (FieldA, FieldB) VALUES (1, "","");
Now i write a Delphi7 app using dbExpress and a TSQLConnection and TQuery.
The TQuery does the following:
SELECT * FROM Test WHERE ID = 1
I have a TEdit on my form and write:
Edit1.Text := SQLQuery1.FieldByName('FieldA').AsString;
Edit2.Text := SQLQuery1.FieldByName('FieldB').AsString;
Now Edit1.Text is empty which is ok. BUT !!! ALARM, ALARM: Edit2.Text
contains one space character.
Is that a bug? I made use of "Trim Char=TRUE" in my params list of the
TSQLConnection, otherwise Edit2.Text (the TEdit which contains the Char(20)
field) would contain 20 space characters.
Bill Todd posted to install the dbExpress service packs and driver updates.
But i didn't find any out there.
Can someone explain this strange behaviour?
Thanks,
Harry
 

Re: why does this work with a varchar but not a char?

I know that if a field is a char(20), it always will write on database
20 chars, it is, the field always will use 20 chars, with blank spaces
if necessary to complete.
Roberto Novakosky
 

Re: why does this work with a varchar but not a char?

Ops, a correction:
I know that if a field is a char(20), it always will write on database
20 chars, it is, the field always will use 20 chars, with "reserved"
spaces
if necessary to complete.
It is good to fields where the values are changed contantly,
server database do not need to change the fisical (do garbage) place on
disk to rewrite, but expense some space on the record to this.
Roberto Novakosky