OID postgresql

Forum related to PostgreSQL

Moderators: gto, cipto_kh, EgonHugeist, olehs

infostar
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 17.07.2010, 10:30

OID postgresql

Postby infostar » 17.07.2010, 10:41

Hi from spain, i need use field OID on postgres not Bytea
how to use lo_export and lo_import with Zeos.

Excuse me, my inglish is very bad, thank you.

Pyh
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 10.12.2009, 11:12
Contact:

Postby Pyh » 19.11.2010, 13:43

ZEOSDBO-6.6.4-stable
Delphi 7

something like this:

Code: Select all

  TBaseZeosConnection = class( TObject)
  private
    FConnection: TZConnection;
    ...
  public
    ...
    function File_Send( const aFileName: string): integer; override;
    procedure File_Recive( const aID: integer; aFileName: string); override;
    procedure File_Delete( const aID: integer); override;
  end;


function TBaseZeosConnection.File_Send( const aFileName: string): integer;
begin

  with ( FConnection.DbcConnection as IZPostgreSQLConnection) do begin

    try
      // start transaction
      FConnection.ExecuteDirect( 'BEGIN'); 
      // Send file
      Result := GetPlainDriver.ImportLargeObject( GetConnectionHandle, PCHAR( aFileName));
      if Result <= 0
      then raise Exception.Create( 'File_Send_Error...');
      FConnection.ExecuteDirect( 'COMMIT');

    except
      FConnection.ExecuteDirect( 'ROLLBACK');
      raise;
    end;

  end;

end;

procedure TBaseZeosConnection.File_Recive( const aID: integer; aFileName: string);
begin // Returns 1 on success, -1 on failure.

  with ( FConnection.DbcConnection as IZPostgreSQLConnection) do begin

    try

      FConnection.ExecuteDirect( 'BEGIN');
      if 1 <> GetPlainDriver.ExportLargeObject( GetConnectionHandle, aID, PCHAR( aFileName))
      then raise Exception.Create( 'File_Recive_Error');
      FConnection.ExecuteDirect( 'COMMIT');

    except
      FConnection.ExecuteDirect( 'ROLLBACK');
      raise;
    end;

  end;

end;

procedure TBaseZeosConnection.File_Delete( const aID: integer);
begin //  Returns 1 if successful, -1 on failure.

  with ( FConnection.DbcConnection as IZPostgreSQLConnection) do begin

    try

      FConnection.ExecuteDirect( 'BEGIN');

      if GetPlainDriver.UnlinkLargeObject( GetConnectionHandle, aID) <> 1
      then raise Exception.Create( 'TBaseZeosConnection.File_Delete_Error');

      FConnection.ExecuteDirect( 'COMMIT');

    except
      FConnection.ExecuteDirect( 'ROLLBACK');
      raise;
    end;

  end;

end;



and so on))
Please note: function postgre lo_XXX not all present in ZEOS

see also ZPlainPostgreSqlDriver.pas,
class "TZPostgreSQL8PlainDriver", functions -

Code: Select all

    function OpenLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
      Mode: Integer): Integer;
    function CloseLargeObject(Handle: PZPostgreSQLConnect;
      Fd: Integer): Integer;
    function ReadLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
      Buffer: PChar; Length: Integer): Integer;
    function WriteLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
      Buffer: PChar; Length: Integer): Integer;
    function SeekLargeObject(Handle: PZPostgreSQLConnect;
      Fd, Offset, Whence: Integer): Integer;
    function CreateLargeObject(Handle: PZPostgreSQLConnect;
      Mode: Integer): Oid;
    function TellLargeObject(Handle: PZPostgreSQLConnect;
      Fd: Integer): Integer;
    function UnlinkLargeObject(Handle: PZPostgreSQLConnect;
      ObjId: Oid): Integer;
    function ImportLargeObject(Handle: PZPostgreSQLConnect;
      FileName: PChar): Oid;
    function ExportLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
      FileName: PChar): Integer;


Return to “PostgreSQL”

Who is online

Users browsing this forum: No registered users and 1 guest