Page 1 of 1

Using PostgreSQL OID blobs in 6.1.5

Posted: 06.09.2007, 23:34
by ZepeDebo
OK, so this is what I had to do to get OID blobs to work with zeos 6.1.5. First, I added the property "oidasblob=yes" to my connection. Then, I altered the code from the example to look something like this:

Code: Select all

procedure CopyImageFromFile(FileName: String; Field: String; TargetTable: TZTable);
var
  BlobStream: TStream;
  FileStream: TStream;
  b: TBookmark;
begin
  with Form1 do
  begin
  if TargetTable.Active  then
  begin
    ZQuery.SQL.Clear;
    ZQuery.SQL.Add('BEGIN');
    ZQuery.ExecSQL;
    b := TargetTable.GetBookmark;
    BlobStream := TargetTable.CreateBlobStream(
      TargetTable.FieldByName(Field), bmWrite);
    try
      FileStream := TFileStream.Create(FileName, fmOpenRead);
      try
        BlobStream.CopyFrom(FileStream, FileStream.Size);
      finally
        FileStream.Free;
      end;
    finally
      BlobStream.Free;
    end;
                       
    TargetTable.Post;
    ZQuery.SQL.Clear;
    ZQuery.SQL.Add('COMMIT');
    ZQuery.ExecSQL;
    TargetTable.GotoBookmark(b);
    TargetTable.Edit;
  end;
  end;
end;
If I don't do the "BEGIN" I get an invalid OID. I watched the connection with PGAdmin and just doing a StartTransaction did not put the connection into a transaction state. Doing a BEGIN and COMMIT did the right thing. Without them, I get an invalid oid error.

After that last Edit, the TargetTable goes back into the dsInsert state.

Am I just doing this wrong?