LobLocator writes garbage

jimpoe

Member²
I'm sure it is the way I'm using it but why doesn't this work?

Value is a Widestring and contains RTF text. When debugging, Value contains the proper value. I'm using an update statement in an OracleQuery component.

procedure TAMSBusinessServer.SetQuoteTermCond(QuoteId: SYSINT;
const Value: WideString);
var
LOB : TLobLocator;
begin
with qryQuoteClob do begin
Close;

DeleteVariables;

SQL.Text := Format( sSQLIdentifier, [ Self.Name + #46 + Name ] ) + CR + sSetQuoteTermCond;

DeclareVariable( F_QUOTE_ID, otInteger );
DeclareVariable( F_QUOTE_TERM_COND, otCLOB );

SetVariable( F_QUOTE_ID, QuoteId );

LOB := TLOBLocator.Create( ssnAMS, otCLOB );
try
SetComplexVariable( F_QUOTE_TERM_COND, LOB );
Execute;
LOB.Seek(0, soFromBeginning );
LOB.Write( PChar( Value ), Length( Value ));
ssnAMS.Commit;
Close;
finally
LOB.Free;
end;
end;
end;
 
Do the NLS settings of your database and Net8 correspond to your widestring character data? Otherwise I guess that the data will be interpreted as 8 bit characters instead of 16 bit characters.

------------------
Marco Kalter
Allround Automations
 
I don't think that is it. I tried using an intermediate string variable and still get the garbage.

S := Value
LOB.Write( PChar( S ), Length( S ));
 
Oracle will happily strip bit 8 from your characters with the wrong NLS, but this can hardly be the problem since RTF is a 7 bit standard.
Does the garbage manifest itself when viewed in an RTF reader (such as Word or Wordpad), or when viewed as raw text? In the first case, is it guaranteed that the RTF output is well-formed? A missing or misplaced curly bracket can render a document unusable.
Finally, at the risk of sounding ignorant since I have never had the need to work with LOBs, aren't you generally supposed to trim when finished writing? Some RTF readers are not at all happy with extra characters after the end of document.

------------------
Frans
 
I can't compile this code with PChar(s). The compiler says "Variable required". If I use PChar(s)^ or s[1] instead, it works just fine.

------------------
Marco Kalter
Allround Automations
 
Back
Top