Subject | AW: [IBO] Re: Storing PDF into Firebird Blobs |
---|---|
Author | Herbert Senner |
Post date | 2012-05-20T17:57:02Z |
Hi Terry,
I use some functions to do that.
The first function reads from file fromFile and writes to
IB_Column toField.
function WriteFromFileToBlob(fromFile: string; toField: TIB_Column):
Boolean;
var
fStream: TFileStream;
blobStream: TIB_BlobStream;
begin
Result := False;
fStream := TFileStream.Create(fromFile, fmOpenRead or fmShareDenyNone);
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fStream, fStream.Size) > 0;
finally
FreeAndNil(blobStream);
FreeAndNil(fStream);
end;
end;
The second function reads from stream fromSteam and writes to
IB_Column.
function WriteFromStreamToBlob(fromStream: TStream; toField: TIB_Column):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := False;
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fromStream, fromStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
Reading from a blob into a stream or a file is just the other way round:
function ReadFromBlobToStream(AField: TIB_Column; toStream: TStream):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
try
Result := toStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
end;
function ReadFromBlobToFile(AField: TIB_Column; fileName: string): Boolean;
var
blobStream: TIB_BlobStream;
fStream: TFileStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
fStream := TFileStream.Create(fileName, fmOpenWrite or
fmShareDenyWrite);
try
Result := fStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(fStream);
FreeAndNil(blobStream);
end;
end;
end;
In your case, I would call the function
WriteFromFileToBlob(PDFFileName, TargetColumn);
Hope this helps.
Herbert
If I look at the Help file it gives some code for using CreateBlobStream but
I am unable to get it to work.
Has anyone another example I could use.
Terry
[Non-text portions of this message have been removed]
I use some functions to do that.
The first function reads from file fromFile and writes to
IB_Column toField.
function WriteFromFileToBlob(fromFile: string; toField: TIB_Column):
Boolean;
var
fStream: TFileStream;
blobStream: TIB_BlobStream;
begin
Result := False;
fStream := TFileStream.Create(fromFile, fmOpenRead or fmShareDenyNone);
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fStream, fStream.Size) > 0;
finally
FreeAndNil(blobStream);
FreeAndNil(fStream);
end;
end;
The second function reads from stream fromSteam and writes to
IB_Column.
function WriteFromStreamToBlob(fromStream: TStream; toField: TIB_Column):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := False;
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fromStream, fromStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
Reading from a blob into a stream or a file is just the other way round:
function ReadFromBlobToStream(AField: TIB_Column; toStream: TStream):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
try
Result := toStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
end;
function ReadFromBlobToFile(AField: TIB_Column; fileName: string): Boolean;
var
blobStream: TIB_BlobStream;
fStream: TFileStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
fStream := TFileStream.Create(fileName, fmOpenWrite or
fmShareDenyWrite);
try
Result := fStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(fStream);
FreeAndNil(blobStream);
end;
end;
end;
In your case, I would call the function
WriteFromFileToBlob(PDFFileName, TargetColumn);
Hope this helps.
Herbert
If I look at the Help file it gives some code for using CreateBlobStream but
I am unable to get it to work.
Has anyone another example I could use.
Terry
[Non-text portions of this message have been removed]