This is the code to write Blob Data to a Blob Field (this works).
LOB := TLOBLocator.Create(BlobDataSet.Session, otBLOB);
MS:= TMemoryStream.Create;
MS.WriteComponent(Layout);
mssize := MS.Size;
SQL := ' INSERT INTO TBLLAYOUT '
+ ' ( ID , ... , LAYOUT, LAYOUTSIZE ) '
+ ' VALUES '
+ ' ( '
+ ' :ID '
...
+ ' , empty_BLOB()'
+ ', ' + IntToStr(MS.Size)
+ ' )Returning LAYOUT into :LAYOUT';
Query.SQL.Text:= SQL;
// Assign it to the returning variable
Query.ClearVariables;
Query.DeclareVariable('ID', otFloat);
Query.DeclareVariable('Layout', otBLOB);
Query.SetVariable('ID', seqnr);
Query.SetComplexVariable('LAYOUT', LOB);
Query.Execute;
// After the insert, use the LOB Locator
// to write the data
LOB.Write(MS, mssize);
With the code below I wanted to read the data from a blob field into a Layout(TComponent), but that doesn't work.
LOB := TLOBLocator.Create(tab.Session, otBLOB);
SQL := 'SELECT Layout, LAYOUTSIZE FROM TBLLAYOUT '
+ 'WHERE ID = 197';
Query.SQL.Text := SQL;
Query.Execute();
if not Query.EOF then
begin
layoutsize := StrToInt(FloatToStr(FQuery (Query,'LAYOUTSIZE'),0));
LOB:= Query.LOBField('LAYOUT');
LOB.Seek(0, soFromBeginning);
anz := LOB.Read(MS, layoutsize);
MS.Position := 0;
MS.ReadComponent(Layout);
end;
LOB := TLOBLocator.Create(BlobDataSet.Session, otBLOB);
MS:= TMemoryStream.Create;
MS.WriteComponent(Layout);
mssize := MS.Size;
SQL := ' INSERT INTO TBLLAYOUT '
+ ' ( ID , ... , LAYOUT, LAYOUTSIZE ) '
+ ' VALUES '
+ ' ( '
+ ' :ID '
...
+ ' , empty_BLOB()'
+ ', ' + IntToStr(MS.Size)
+ ' )Returning LAYOUT into :LAYOUT';
Query.SQL.Text:= SQL;
// Assign it to the returning variable
Query.ClearVariables;
Query.DeclareVariable('ID', otFloat);
Query.DeclareVariable('Layout', otBLOB);
Query.SetVariable('ID', seqnr);
Query.SetComplexVariable('LAYOUT', LOB);
Query.Execute;
// After the insert, use the LOB Locator
// to write the data
LOB.Write(MS, mssize);
With the code below I wanted to read the data from a blob field into a Layout(TComponent), but that doesn't work.
LOB := TLOBLocator.Create(tab.Session, otBLOB);
SQL := 'SELECT Layout, LAYOUTSIZE FROM TBLLAYOUT '
+ 'WHERE ID = 197';
Query.SQL.Text := SQL;
Query.Execute();
if not Query.EOF then
begin
layoutsize := StrToInt(FloatToStr(FQuery (Query,'LAYOUTSIZE'),0));
LOB:= Query.LOBField('LAYOUT');
LOB.Seek(0, soFromBeginning);
anz := LOB.Read(MS, layoutsize);
MS.Position := 0;
MS.ReadComponent(Layout);
end;