Page 1 of 1

Blob Insert into Firebird using Devart

Posted: Wed 19 Oct 2011 13:30
by netherledy
Can anyone please point me to a code example of how to insert a blob into a table, without using TClientDataset, for Delphi or C++Builder using DBX and Devart? I am using C++ Builder XE.

The table is huge, so an intermediate TClientDataset memory resident copy of the entire table is not possible. I looked for ways to limit the size of the memory resident copy to the last few rows, I am sure there must be a mechanism, but I couldn't figure it out.

I presume that I need to create a TBlobStream and assign it to a parameter of a TSQLQuery? I can do it with an INSERT statement for integer types, but am having difficulty with the blob data.

Posted: Sat 22 Oct 2011 11:17
by fabio_rbs
Hi, you can try something like this:

Code: Select all

var
  DBXTrn: TDBXTransaction;
  DBXCmd: TDBXCommand;
  DBXPar: TDBXParameter;
  sArqXml: string;
begin
  sArqXml := 'C:\FILE1.XML';   // Any file that you wanna put on blob 

  DBXTrn := DM.DBXCon.DBXConnection.BeginTransaction(TDBXIsolations.ReadCommitted);
  try
    DBXCmd := DM.DBXCon.DBXConnection.CreateCommand;
    try
      DBXCmd.Text := 'INSERT INTO MYTABLE (MYBLOB) VALUES (?)');

      DBXPar := DBXCmd.CreateParameter;
      DBXPar.DataType := TDBXDataTypes.BlobType;
      DBXPar.Value.SetStream(TFileStream.Create(sArqXml, fmOpenRead), True);
      DBXPar.Value.ValueType.ValueTypeFlags := DBXPar.Value.ValueType.ValueTypeFlags or TDBXValueTypeFlags.ExtendedType;

      DBXCmd.Parameters.AddParameter(DBXPar);
      DBXCmd.Prepare;
      DBXCmd.ExecuteUpdate;
      DBXCmd.Close;
    finally
      DBXCmd.Free;
    end;

    DM.DBXCon.DBXConnection.CommitFreeAndNil(DBXTrn);
  except
    DM.DBXCon.DBXConnection.RollBackFreeAndNil(DBXTrn);
    raise;
  end;
end;
Don't forget the DBXCommon unit in your uses clause.

Regards,

Fábio R. Bot Silva.