Click here to Skip to main content
14,448,968 members
Rate this:
Please Sign up or sign in to vote.
See more:
MySQL 8
FireDac Components (FDQuery + FDPhyMySqlLink)

Table with two field a BLOB and a TINYBLOB

The image is 7384 byte

When execute the query the error is :
[Firedac][Phys][MySql] data too long for column immagine at row 1


from the MySqlWordBench the operation on Field Blob /TinyBlob the Image is Inserted on DataBase

What I have tried:

 MemStream: TMemoryStream;

begin
  Image1.Picture.LoadFromFile(sFile);

  MemStream := TMemoryStream.Create;
  try
    Image1.Picture.SaveToStream(MemStream);
    MemStream.Seek(0,0);
    FDQuery1.SQL.Text := 'INSERT INTO tb_test (immagine1) VALUES (:img)';
    FDQuery1.ParamByName('img').LoadFromStream(MemStream, ftBlob);
    FDQuery1.ExecSQL;

  finally
    MemStream.Free;
  end;
Posted
Updated 22-Jul-19 8:50am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

Fixed (almost, still a problem with 5 Mb files - eg: 4.987.904 should go smoothly on MEDIUMBLOB instead
Lost Connection during query... to understand, already with 2.7 Mb files you
has the exception).


in MySql
{
TINYBLOB   :     maximum length of 255 bytes
BLOB       :     maximum length of 65,535 bytes
MEDIUMBLOB :     maximum length of 16,777,215 bytes
LONGBLOB   :     maximum length of 4,294,967,295 bytes
}

procedure Tfrm_Articoli.InserisceImmagine(sFile: string);
var jp:TJpegImage;
    MemStream: TMemoryStream;
begin
  sFile := '<foto da inserire>';

  FDQuery1.Open;
  FDTransaction1.StartTransaction;

  //Medium Blob
  sFile := '<foto da inserire>';

  FDTransaction1.StartTransaction;

  try
    jp := TJpegImage.Create;
    jp.LoadFromFile(sFile);
    FDQuery1.Active := true;
    FDQuery1.Insert;
    FDQuery1.FieldByName('immagine1').Assign(jp);
    FDQuery1.Post;
    FreeAndNil(jp);
    FDTransaction1.Commit;
  except
    FDTransaction1.RollBack;
  end;

//versione SQL

  MemStream := TMemoryStream.Create;

  sFile := '<foto da inserire>';
  Image1.Picture.LoadFromFile(sFile);

  Image1.Picture.SaveToStream(MemStream);
  MemStream.Seek(0,0);
  FDQuery1.SQL.Text := 'INSERT INTO tb_test (immagine1) VALUES (:img)';
  FDQuery1.ParamByName('img').LoadFromStream(MemStream, ftBlob);
  FDQuery1.ExecSQL;

..//
end; 
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100