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�Ȥ߹�����Ͽ���줿�ؿ�