Recent

Author Topic: Problems with BLOB stream  (Read 3584 times)

spenna

  • Newbie
  • Posts: 4
    • http://www.studiosperotto.it
Problems with BLOB stream
« on: August 06, 2014, 10:57:00 am »
I'm trying to load very large BLOBS to SQLServer database, using Lazrus & ZeosLib.
I need to upload the files in chunks, so I've tryed this source, wich works perfectly in Delphi:

procedure TForm1.SaveFileToBlob(Filename: TFilename);
const
  bufSize = 16384;
var
  sStream   : TFileStream;
  pBuf      : Pointer;
  cnt,totCnt: Integer;
begin
  // total bytes reset
  totCnt:=0;
  // open the file stream for reading
  sStream:=TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
  try
    try
      // reserve space for buffer
      GetMem(pBuf, bufSize);
      // read first chunk
      cnt:=sStream.Read(pBuf^, bufSize);
      totCnt:=cnt;

      while (cnt > 0) do
        begin
          Application.ProcessMessages;
          qry_Blob.Close;
          qry_Blob.ParamByName('id').AsInteger:=1;
          qry_Blob.ParamByName('data').SetBlobData(pBuf,cnt);
          //
          qry_Blob.ExecSQL;
          // read next chunk
          cnt:=sStream.Read(pBuf^, bufSize);
          inc(totCnt,cnt);
          // show total bytes processed
          Label1.Caption:=Format('Bytes caricati: %d - %d MB',[totCnt, totCnt div (1024*1204)]);
          Form1.Refresh;
          Application.ProcessMessages;
        end;
    finally
      FreeMem(pBuf, bufSize);
    end;
  finally
    sStream.Free;
  end;

  ShowMessage('Done');
end;

When I put this in Lazarus I get a SEGMENTATION FAULT error.

Someone can help? Any idea?


 

TinyPortal © 2005-2018