Print Thread
Losing Trailing Spaces from Fields
#48634 02/20/14 09:39 AM
Joined: Feb 2014
Posts: 3
A
Member
OP Offline
Member
A
Joined: Feb 2014
Posts: 3
Hello,

Got a problem where I am losing spaces from strings stored in my database.

For example if I have a string field which has the following text in it 'Monkies ' and I connect a db aware component in delphi directly to that field then it will display as 'Monkies' without the space at the end.

I've tried this with a new delphi application containing nothing more than a TOracleSession, TOracleDataSet, TDataSource to get the data, using the simplest of queries to get nothing but the exact field from an exact record. And I`ve tried displaying it on a form using a TDBText, TDBEdit, TDBMemo and they all do exactly the same thing.

If if add to the query to include a second field a the length the the problem field then it will show as 8 (correct) but if I add a calculated field to the dataset in delphi then it show as 7.

It seems as though there is a Trim being done when the data is retrieved but I can' find an option to turn that off.

It's causing a real problem where I need to be able to see the space.

Any help or suggestions would be appreciated cheers...

(Delphi 2009 on Windows7)

Re: Losing Trailing Spaces from Fields
AndrewKindred #48635 02/20/14 12:18 PM
Joined: Aug 1999
Posts: 22,173
Member
Offline
Member
Joined: Aug 1999
Posts: 22,173
The TOracleDataSet does indeed trim trailing spaces by default. To disable this, set TOracleSession.Preferences.TrimStringFields to False.


Marco Kalter
Allround Automations
Re: Losing Trailing Spaces from Fields
Marco Kalter #48638 02/20/14 01:35 PM
Joined: Feb 2014
Posts: 3
A
Member
OP Offline
Member
A
Joined: Feb 2014
Posts: 3
Cheers for that Marco, great to know why it's happening.

Is there any way to turn it off for a specific DataSet or Query? Or a different method of making the query so that I get the "actual" field content back and not the trimmed version? (without having to change the session obviously)

The problem I have relates to it NOT always trimming text that is written to the field, only when it reads it.

Actually, is there an option for making it trim text that is written to the database (aside from doing that manually with events)?

---

To give you a real world example of my problem...

Say I have two records (in separate tables) related to a TV Programme. One for the Programme and one for the Series it is part of. The Series record has a TITLE field and the programme record has a TITLE and a SUB_TITLE field. where the SUB_TITLE field is used when the programme TITLE is the same as the series TITLE.

Example:
Series TITLE = 'Doctor Who'
Programme TITLE = 'Doctor Who'
Programme SUB_TITLE = 'Episode 42'
So for Series Title + Programme Title you'd get 'Doctor Who - Episode 42'.

Now say I have an DBEdit box for the Programme Title showing the current field content from the record as 'Doctor Who' and a user adds a space and tries to save it. This DOESN'T work as it seems to compare the equivalent of Trim('Doctor Who') with Trim('Doctor Who '), thinks there's no change and so leaves the record as is.

BUT, if the user changed the title to 'Doctor Who 2014', saved it, realised that was daft and then changed it to 'Doctor Who ' and saved it, then that WOULD work as Trim('Doctor Who 2014') with Trim('Doctor Who ') are different. However it writes the UNTRIMMED text to the record.

Now I have the situation where in the record there is a space but in my application DBEdit box you can't see it, and can't remove it.

So now in the example I have:
Series TITLE = 'Doctor Who'
Programme TITLE = 'Doctor Who '
Programme SUB_TITLE = 'Episode 42'
So for Series Title + Programme Title you'd now get 'Doctor Who - Doctor Who '.

I know that I could do Trims when comparing the TITLE's to determine the use of SUB_TITLE, but it's a pain to have to do this in every case whilst not being able to see and remove spaces in DBEdits.

Hope that made sense :o)

Cheers....


Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.034s Queries: 15 (0.008s) Memory: 2.5115 MB (Peak: 3.0397 MB) Data Comp: Off Server Time: 2024-03-28 18:04:57 UTC
Valid HTML 5 and Valid CSS