BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String results are not trimmed and cause problems-Solution?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Jankins
Guest





PostPosted: Thu Aug 21, 2003 3:44 pm    Post subject: String results are not trimmed and cause problems-Solution? Reply with quote



I have a table with a field called 'MyCharField' of CHAR[14]

I have a standard edit box called 'MyEditBox'

Using an ADO query I select MyCharField and compare it to MyEditBox.Text
like this:

If MyCharField = MyEditBox.Text THEN
Do This Stuff
ELSE
Do This Other Stuff

Using watches, I discovered this:

MyCharField = 'ok ' (Length=14)
and
MyEditBox.Text='ok' (Length=2)

Ergo, the comparison returns FALSE.

This procedure worked just fine, until we made two changes. The changes
were:

#1 - Our server died and the tables were restored from a backup tape to a
new OS/SQL installation (the restored table, for reasons we don't know,
dropped the Identity key (the field was there, it simply was not flagged as
and autoinc identity), but that has since been corrected).

#2 - I switched the SQL components from BDE to ADO.

Both of those changes took place before the software was found to be
producing unexpected results - so I'm not sure which change caused the
returns of untrimmed strings.

Can someone tell me how to make SQL/ADO return CHAR fields (and STRING
fields) trimmed?

Thank you,
Dan (at) emscoelectric (dot) com



Back to top
Jankins
Guest





PostPosted: Thu Aug 21, 2003 3:53 pm    Post subject: Re: String results are not trimmed and cause problems-Soluti Reply with quote



Thanks Eric for the quick reply - is the untrimmed result due to ADO? I'm
somewhat certain that the software 'worked' with the BDE. . .or does my
testing phase suck :)

Dan


"Eric Hill" <eric (AT) ijack (DOT) net> wrote

Quote:
If it's in the database as a CHAR(5) field, you'll get 5 characters with
space padding.

If it's in the database as a VARCHAR(5) field, you'll get what's in the
cell.

Either change the definition from CHAR[14] to VARCHAR[14] and run an
update, or change your SQL statements to SELECT TRIM(COLUMN) so the spaces
are trimmed in the query.

Eric






Back to top
Ignacio Vazquez
Guest





PostPosted: Thu Aug 21, 2003 3:58 pm    Post subject: Re: String results are not trimmed and cause problems-Soluti Reply with quote



" Jankins" <NoSpam (AT) here (DOT) com> wrote in message
3f44eae2$1 (AT) newsgroups (DOT) borland.com...
Quote:
Thanks Eric for the quick reply - is the untrimmed result due to ADO? I'm
somewhat certain that the software 'worked' with the BDE. . .or does my
testing phase suck Smile

No, the trimmed result is due to BDE. The BDE is, as its name impiles, a
database engine, and therefore can have fairly different behavior from a
data access library such as ADO.

Cheers,
Ignacio

--
No, don't send me e-mail directly. No, just don't.




Back to top
Wayne Niddery [TeamB]
Guest





PostPosted: Thu Aug 21, 2003 4:20 pm    Post subject: Re: String results are not trimmed and cause problems-Soluti Reply with quote

Jankins wrote:
Quote:
Thanks Eric for the quick reply - is the untrimmed result due to ADO?
I'm somewhat certain that the software 'worked' with the BDE. . .or
does my testing phase suck Smile

As convenient as it's been, it is the BDE that has always *incorrectly*
trimmed char fields when returning them to the client.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"It is error alone which needs the support of government. Truth can
stand by itself." - Thomas Jefferson



Back to top
Bill Todd
Guest





PostPosted: Thu Aug 21, 2003 4:28 pm    Post subject: Re: String results are not trimmed and cause problems-Soluti Reply with quote

In this case, what the BDE is doing is "wrong". By definition CHAR
fields are padded to their full length with spaces and VARCHAR fields
are not. The data access library should, in both cases, return what is
stored in the field, not make arbitrary changes on its own. If you
define a field as CHAR you are saying that you want the value padded
with spaces.


--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.