Page 1 of 1

improvement for TDAParam.LoadFromFile (DBAccess.pas)

Posted: Fri 17 Oct 2008 10:52
by Eurocg
Hello UniDac Team

Some application e.g. MS Word open files exclusive. If so i can not use TUniParams as Blob to save this file to DB.

Why? See your source (DBAccess):

Code: Select all

procedure TDAParam.LoadFromFile(const FileName: string; BlobType: TBlobType);
var
  Stream: TStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead); // <<< Work not for exlusive open files
  try
    LoadFromStream(Stream, BlobType);
  finally
    Stream.Free;
  end;
end;
Please change this with next Update.

Code: Select all

Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);

Posted: Mon 20 Oct 2008 14:46
by Plash
We will not add this change to UniDAC because it will allow to write data to the file at the same time when UniDAC reads it.

Posted: Mon 20 Oct 2008 15:10
by Eurocg
It's a pity. You not have to change the default function for it.

I mean you can overload the function or define a third parameter with default value, or declare a new funktion:

Code: Select all

type
  TOpenMode = (fmOpenRead, fmOpenWrite, ...)

// overlaod
procedure LoadFromFile(const FileName: string; BlobType: TBlobType); overload;
procedure LoadFromFile(const FileName: string; BlobType: TBlobType; OpenMode : TOpenMode); overload;

// default parameter
procedure LoadFromFile(const FileName: string; BlobType: TBlobType; OpenMode : TOpenMode default =fmOpenRead ); 

// or new function
procedure LoadFromFileShare(const FileName: string; BlobType: TBlobType); 
So I must make this change after each update of UNIDAC. That is also ok.
Thx