Subject Re: [IBO] Re: Right-trimming defaults
Author David Trudgett
At 2001-03-22 18:44 -0700, "Jason Wharton" <jwharton@...> wrote:

>Have a look at these methods.. This should do it:

I haven't looked much at the internals of IBO before, so take my comments,
or lack thereof, with a grain of salt.


>function TIB_Column.GetAsRawString: string;
>var
> tmpLen: word;
>begin
> if FNewColumnInd^ = IB_NULL then
> Result := ''
> else
> case SQLType of
> SQL_Text,
> SQL_Text_:
> Result := Copy( Pchar( FNewColumnBuffer ), 1, SQLLen );
> SQL_Varying,
> SQL_Varying_: with SQL_VARCHAR( FNewColumnBuffer^ ) do
> begin
> tmpLen := vary_len_low + vary_len_high * 256;
> SetLength( Result, tmpLen );
> Move( vary_string, pchar( Result )^, tmpLen );

How do multi-byte character sets get handled? Obviously, for starters,
we're just dealing with AnsiStrings at the moment. Will future versions
have to use WideStrings for Unicode support?


> end
> else
> Result := AsString;
> end;
>end;

That looks like it will do the job.



>procedure TIB_Column.SetAsRawString( const NewValue: string );
>var
> StrLen: smallint;

Shouldn't that be "word" also?

> tmpVal: string;
>begin
> tmpVal := NewValue;
> StrLen := Length( tmpVal );
> case SQLType of
> SQL_Text,
> SQL_Text_:
> begin
> if StrLen > SQLLen then
> raise Exception.Create( 'String truncation: ' + BestFieldName );

I don't know where BestFieldName is coming from, but it sounds interesting...

I've got no problem with the exception being raised. Putting square pegs
into round holes didn't work even in kindy.


> SysBeforeModify;
> FillChar( FNewColumnBuffer^, DataSize, FPadChar );
> if ( StrLen = 0 ) and FBlankIsNull then
> SysSetIsNull( true )
> else
> SysSetIsNull( false );
> Move( tmpVal[1], FNewColumnBuffer^, StrLen );
> SysAfterModify;
> end;
> SQL_Varying,
> SQL_Varying_: with SQL_VARCHAR( FNewColumnBuffer^ ) do
> begin
> if StrLen > SQLLen then
> raise Exception.Create( 'String truncation: ' + BestFieldName );
> SysBeforeModify;
> FillChar( vary_string, SQLLen, FPadChar );
> if ( StrLen = 0 ) and FBlankIsNull then
> SysSetIsNull( true )
> else
> SysSetIsNull( false );
> vary_len_low := StrLen mod 256;
> vary_len_high := StrLen div 256;
> Move( tmpVal[1], vary_string, StrLen );
> SysAfterModify;
> end
> else
> AsString := tmpVal;
> end;
>end;


Thanks!


David Trudgett