PostgreSQL
PrevChapter 43. ラージ(巨大な)オブジェクト(Large Objects)Next

ラージオブジェクト・インターフェース

The facilities Postgres provides to access large objects, both in the backend as part of user-defined functions or the front end as part of an application using the interface, are described below. ラージオブジェクトにアクセスするために Postgres が提供する機能、すなわちユーザ 定義関数としてバックエンドで実行されるもの、および インターフェー スを使ってアプリケーションの一部として実行されるものの両方を以下 で説明します。 (For users familiar with Postgres 4.2, PostgreSQL has a new set of functions providing a more coherent interface. ( Postgres 4.2に親しんでいるユーザのた めに、PostgreSQL では、新しい、 より筋の通ったインターフェースを提供する関数のセットを持っていま す。 The interface is the same for dynamically-loaded C functions as well as for XXX LOST TEXT? WHAT SHOULD GO HERE??. このインターフェースは ??? (訳註: この箇所は原文でも抜けている) だけでなく、動的にロードされる C 関数と同じものです。) (校正者への註: sgmlに変換した人の魂の叫びが書いてありますね ^_^) The Postgres large object interface is modeled after the UNIX file system interface, with analogues of open(2), read(2), write(2), lseek(2), etc. Postgres ラージオブジェクトインターフェースは open(2)read(2)write(2)lseek(2)など といった UNIX ファイルシ ステム・インターフェースに類似したモデルとなっています。 User functions call these routines to retrieve only the data of interest from a large object. ラージオブジェクトから特定のデータだけを取り出すために、ユーザの 関数はこれらルーチンをコールします。 For example, if a large object type called mugshot existed that stored photographs of faces, then a function called beard could be declared on mugshot data. たとえば、顔写真を格納している mugshot (顔写真、手配写真)と呼ばれ るラージオブジェクト型があり、また beard (ひげ)と呼ばれる関数が mugshot データに宣言されているとします。 Beard could look at the lower third of a photograph, and determine the color of the beard that appeared there, if any. beard (ひげ)関数は写真の下 3 分の 1 を見て、もしそこにひげがあれ ばその色を測定します。 The entire large object value need not be buffered, or even examined, by the beard function. ラージオブジェクト全体の値は beard 関数によりバッファリングされる 必要はなく、またチェックされる必要もありません。 Large objects may be accessed from dynamically-loaded C functions or database client programs that link the library. ラージオブジェクトは、動的にロードされた C 関 数、Libpq ライブラリとリンクされたデータベース・クライアントプロ グラム、のいずれからアクセスされてもかまいません。 Postgres provides a set of routines that support opening, reading, writing, closing, and seeking on large objects. Postgres では、ラージオブジェクトのオ ープン、読み、書き、クローズ、シークの各機能を提供しています。

ラージオブジェクトの生成

The routine 次のルーチンは新しいラージオブジェクトを生成します。

Oid lo_creat(PGconn *conn, int mode)
creates a new large object. The mode is a bitmask describing several different attributes of the new object. mode は新しいオブジェクトの複数の異なった属性を指定するビットマス クです。 The symbolic constants listed here are defined in これ以降で示す定数シンボルは次のファイルで定義されています。 PGROOT/src/backend/libpq/libpq-fs.h The access type (read, write, or both) is controlled by OR ing together the bits INV_READ and INV_WRITE. アクセスタイプ(read、write または両方)は INV_READ と INV_WRITE ビッ トを OR することで指定します。 If the large object should be archived もしラージオブジェクトをアーカイブするのなら -- that is, if historical versions of it should be moved periodically to a special archive relation -- -- すなわち、その複数世代のバージョンを定期的に特別なアーカイブ・リ レーションに移動する場合 -- then the INV_ARCHIVE bit should be set. INV_ARCHIVE ビットをセットしなければなりません。 The low-order sixteen bits of mask are the storage manager number on which the large object should reside. mask の下位 16 ビットは、ラージオブジェクトが存在する記憶 領域の管理番号です。 For sites other than Berkeley, these bits should always be zero. Berkeley 以外のサイトにおいてはこれらは常に0 です。 The commands below create an (Inversion) large object: 以下のコマンドは(転置)ラージオブジェクトを生成します。
inv_oid = lo_creat(INV_READ|INV_WRITE|INV_ARCHIVE);

ラージオブジェクトのインポート

To import a UNIX file as a large object, call UNIX ファイルをラージオブジェクトとしてインポ ートするには、次の関数をコールします。

Oid lo_import(PGconn *conn, text *filename)
The filename argument specifies the UNIX pathname of the file to be imported as a large object. filename 引数はラージオブジェクトとしてインポートするファイル の UNIX パス名を指定します。

ラージオブジェクトのエクスポート

To export a large object into UNIX file, call ラージオブジェクトを UNIX ファイルにエクスポ ートするには、次の関数をコールします。

int lo_export(PGconn *conn, Oid lobjId, text *filename)
The lobjId argument specifies the Oid of the large object to export and the filename argument specifies the UNIX pathname of the file. lobjId 引数はエクスポートするラージオブジェクトの Oid を指定し、 filename にはファイルの UNIX パス名を指定しま す。

既存のラージオブジェクトのオープン

To open an existing large object, call 既存のラージオブジェクトをオープンするには、次の関数をコールしま す。

int lo_open(PGconn *conn, Oid lobjId, int mode, ...)
The lobjId argument specifies the Oid of the large object to open. lobjId 引数にはオープンするラージオブジェクトの Oid を指定し ます。 The mode bits control whether the object is opened for reading INV_READ), writing or both. mode ビットは、オブジェクトを読み込みのみ (INV_READ)、書き込みの み (INV_WRITE )、その両方のどのモードでオープンするかを制御します。 (校正者への註: INV_WRITEなどを補いました) A large object cannot be opened before it is created. ラージオブジェクトを生成する前にオープンすることはできません。 lo_open returns a large object descriptor for later use in lo_read, lo_write, lo_lseek, lo_tell, and lo_close. lo_open は、後に lo_read、lo_write、lo_lseek、lo_tell、lo_close で利用するためのラージオブジェクト記述子を返します。

ラージオブジェクトへのデータの書き込み

The routine 次のルーチンは、buf から len バイトをラージオブジェクト fd に書き 込みます。

int lo_write(PGconn *conn, int fd, char *buf, int len)
writes len bytes from buf to large object fd. The fd argument must have been returned by a previous lo_open. fd 引数は、前の lo_open からの返り値を指定しなくてはなりません。 The number of bytes actually written is returned. 実際に書き込まれたバイト数が返ります。 In the event of an error, the return value is negative. エラーが起こった場合は負数が返ります。

ラージオブジェクトのシーク

To change the current read or write location on a large object, call ラージオブジェクトの現在の読み書きの開始位置を変更するには 次の関数をコールします。

int lo_lseek(PGconn *conn, int fd, int offset, int whence)
This routine moves the current location pointer for the large object described by fd to the new location specified by offset. このルーチンは、fd で指定されたラージオブジェクトの現在の位置ポイ ンタを offset で指定された新しい位置に移動します。 The valid values for .i whence are SEEK_SET SEEK_CUR and SEEK_END. whence の有効な値は SEEK_SET、SEEK_CUR、SEEK_END のいずれかです。 (校正者への註: .i は nroff のイタリック指定か? 疲れてますね ^_^)

ラージオブジェクト記述子のクローズ

A large object may be closed by calling ラージオブジェクトは次の関数をコールしてクローズして下さい。

int lo_close(PGconn *conn, int fd)
where fd is a large object descriptor returned by lo_open. ここで、fd は lo_open で返されたラージオブジェクト記述子です。 On success, lo_close returns zero. On error, the return value is negative. 成功するとlo_closeは 0 を返し、エラーの場合は 負数を返します。


PrevHomeNext
転置ラージオブジェクトUp組み込み登録された関数