Wrongly trim trailing spaces

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
wobben
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 25.09.2008, 11:16
Contact:

Wrongly trim trailing spaces

Post by wobben »

After inserting varchar values into the database tables, where values contained trailing spaces, the values were always trimmed when returned. Even if the trailing spaces were in the database table. Even when ANSI_PADDING was set for Sql Server.

After much debugging, I found the reason why. It's an absolete codeline which always removes trailing spaces. Removing the codeline fixes the behaviour.

Code: Select all

function TZAdoResultSet.GetString(ColumnIndex: Integer): string;
var
  NL: Integer;
begin
  Result := '';
  LastWasNull := IsNull(ColumnIndex);
  if LastWasNull then Exit;
  Result := FAdoRecordSet.Fields.Item[ColumnIndex - 1].Value;
  NL := Length(Result);
  while (NL > 0) and (Result[NL] = ' ') do Dec(NL);   // <<< PLEASE REMOVE THIS LINE
  SetLength(Result, NL);
end;
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

wobben,

We've stopper maintaining the 6 series.. We've not enougth manpower. Would you like doing this job?

May i ask you for purpose of ANSI_PADDING?

I think you're right with removing this line. On the other hand.. I have the impression somebody added it with a good reason. Is it possibe other providers adding spaces to the string values? I'll run the tests with you patch tonight and see what happens...
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
wobben
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 25.09.2008, 11:16
Contact:

Post by wobben »

ANSI_PADDING regulates the trailing spaces in varchar fields. For this reason the older code may have needed these lines, but nowadays most dbms's support some kind of ANSI_PADDING control. The driver should not perform this without any developer support for turning it off.

I love the Zeos stuff, but use it very little, having the responsibility for maintaining v6 is a little much to ask for.

Maybe sometime in the future if more of my efforts get sponsorship. ;-)
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

wobben,

is theire a way to find out if ANSI_PADDING is set? I've omited these lines on Testing-7.1 and added a test to confirm this behavior. Now you write me some old servers do return fields filled with spaces. It would be nice to know which one or how to check this option... Do you know some more details about it or is theire a link for it?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
wobben
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 25.09.2008, 11:16
Contact:

Post by wobben »

Perhaps you may start of at this link?

http://msdn.microsoft.com/en-us/library/ms187403.aspx
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

wobben,

i've already found this link. It tells me the porpose and how to switch ANSI_PADDING. But i'm asking how to find out if ANSI_PADDING is ON or OFF.

If we can't determine ANSI_PADDING then i propose to use:
TZConnection.Properties.Values['ANSI_PADDING'] := 'ON' or 'OFF'; to tell Zeos how to work with the related (var)char/(var)binary fields. So we've an option to keep control about the behavior. What do you think?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
wobben
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 25.09.2008, 11:16
Contact:

Post by wobben »

Since Microsoft decided to turn it on, always, it would not make much sense to stay with the trimming code lines. However, they offer session properties to check if this is turned on of off:

http://msdn.microsoft.com/en-us/library/ms175001.aspx
Post Reply