Page 1 of 1
Wrongly trim trailing spaces
Posted: 21.01.2013, 11:34
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;
Posted: 22.01.2013, 17:50
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...
Posted: 12.02.2013, 12:56
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.
Posted: 12.02.2013, 16:26
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?
Posted: 14.02.2013, 14:42
by wobben
Posted: 15.02.2013, 10:02
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?
Posted: 15.02.2013, 12:11
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