Blob Insert into Firebird using Devart

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for InterBase & Firebird in Delphi and C++Builder
Post Reply
netherledy
Posts: 1
Joined: Wed 19 Oct 2011 13:06

Blob Insert into Firebird using Devart

Post by netherledy » Wed 19 Oct 2011 13:30

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.

fabio_rbs
Posts: 9
Joined: Wed 27 Oct 2010 23:19

Post by fabio_rbs » Sat 22 Oct 2011 11:17

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.

Post Reply