 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jankins Guest
|
Posted: Thu Aug 21, 2003 3:44 pm Post subject: String results are not trimmed and cause problems-Solution? |
|
|
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
|
Posted: Thu Aug 21, 2003 3:53 pm Post subject: Re: String results are not trimmed and cause problems-Soluti |
|
|
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
|
Posted: Thu Aug 21, 2003 3:58 pm Post subject: Re: String results are not trimmed and cause problems-Soluti |
|
|
" 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
|
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
|
Posted: Thu Aug 21, 2003 4:20 pm Post subject: Re: String results are not trimmed and cause problems-Soluti |
|
|
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
|
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
|
Posted: Thu Aug 21, 2003 4:28 pm Post subject: Re: String results are not trimmed and cause problems-Soluti |
|
|
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 |
|
 |
|
|
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
|
|