Topic: BLOB example

Can you point me to some sample code that demonstrates storing and retrieving a blob such as the contents of a .mp3 or .jpg file?

Re: BLOB example

Hello Michael!

We can use TMemoryStream to insert binary data into a database.

uses
  SQLite, SQLite3Wrap; 

procedure TForm1.Button1Click(Sender: TObject);
var
  DB: TSQLite3Database;
  Stmt: TSQLite3Statement;
  Stream: TMemoryStream;
  Size: Integer;
begin
  DB := TSQLite3Database.Create;
  try
    // Create table to store BLOB data
    DB.Open('blob_test.db');
    DB.Execute('CREATE TABLE blob_table (data BLOB)');

    // Insert custom binary data by using TMemoryStream
    Stmt := DB.Prepare('INSERT INTO blob_table (data) VALUES (?)');
    try
      Stream := TMemoryStream.Create;
      try
        // Load external JPG file and insert it to BLOB cell
        Stream.LoadFromFile('image.jpg');
        Stmt.BindBlob(1, Stream.Memory, Stream.Size);
      finally
        Stream.Free;
      end;

      Stmt.Step;
    finally
      Stmt.Free;
    end;

    // Read BLOB data into TMemoryStream, and then use it as we want
    Stmt := DB.Prepare('SELECT data FROM blob_table');
    try
      if Stmt.Step = SQLITE_ROW then
      begin
        // Get binary data size
        Size := Stmt.ColumnBytes(0);

        Stream := TMemoryStream.Create;
        try
          // Set memory stream size and load it from BLOB field
          Stream.SetSize(Size);
          Stream.Write(Stmt.ColumnBlob(0)^, Size);

          // Load memory stream content into TImage component
          Stream.Position := 0;
          Image1.Picture.LoadFromStream(Stream);
        finally
          Stream.Free;
        end;
      end;
    finally
      Stmt.Free;
    end;
  finally
    DB.Free;
  end;
end;

This code is tested on Lazarus. In Delphi, loading JPEG image into TImage may differ, but the idea is the same.

Re: BLOB example

This message is posted here using XRumer + XEvil 4.0

XEvil 4.0 is a revolutionary application that can solve almost any antibot protection.
Captcha Solution Google (ReCaptcha-1, ReCaptcha-2), Facebook, BING, Hotmail, Yahoo,
Yandex, VKontakte, Captcha Com - and over 8400 other types!

You read this - it means it works! wink
Details on the official website of XEvil, there is a free demo version.

Check YouTube video "XEvil ReCaptcha2"