ソフト開発塾
Pg.pm における接続
    # データベースへの接続
    $conn = Pg::connectdb("user=postgres password=postpass dbname=testdb");
Pg.pmから抜粋・使用例・他
$dbname = $conn->db

Returns the database name of the connection.


$pguser = $conn->user

Returns the Postgres user name of the connection.


$pguser = $conn->pass

Returns the Postgres password of the connection.


$pghost = $conn->host

Returns the host name of the connection.


$pgport = $conn->port

Returns the port of the connection.


$pgtty = $conn->tty

Returns the tty of the connection.


$pgoptions = $conn->options

Returns the options used in the connection.


$status = $conn->status

Returns the status of the connection. For comparing the status
you may use the following constants:

 - PGRES_CONNECTION_OK
 - PGRES_CONNECTION_BAD


$errorMessage = $conn->errorMessage

Returns the last error message associated with this connection.


$fd = $conn->socket

 Obtain the file descriptor number for the backend connection socket.
A result of -1 indicates that no backend connection is currently open.


$pid = $conn->backendPID

Returns the process-id of the corresponding backend proceess.


$conn->trace(debug_port)

Messages passed between frontend and backend are echoed to the
debug_port file stream.


$conn->untrace

Disables tracing.


$result = $conn->exec($query)

Submits a query to the backend. The return value is a pointer to
the PGresult structure, which contains the complete query-result
returned by the backend. In case of failure, the pointer points
to an empty structure. In this, the perl implementation differs
from the C-implementation. Using the old style, even the empty
structure has to be freed using PQfree. Before using $result you
should call resultStatus to ensure, that the query was
properly executed.


($table, $pid) = $conn->notifies

Checks for asynchronous notifications. This functions differs from
the C-counterpart which returns a pointer to a new allocated structure,
whereas the perl implementation returns a list. $table is the table
which has been listened to and $pid is the process id of the backend.


$ret = $conn->sendQuery($string, $query)

Submit a query to Postgres without waiting for the result(s). After
successfully calling PQsendQuery, call PQgetResult one or more times
to obtain the query results. PQsendQuery may not be called again until
getResult has returned NULL, indicating that the query is done.


$result = $conn->getResult

Wait for the next result from a prior PQsendQuery, and return it. NULL
is returned when the query is complete and there will be no more results.
getResult will block only if a query is active and the necessary response
data has not yet been read by PQconsumeInput.


$ret = $conn->isBusy

Returns TRUE if a query is busy, that is, PQgetResult would block waiting
for input. A FALSE return indicates that PQgetResult can be called with
assurance of not blocking.


$result = $conn->consumeInput

If input is available from the backend, consume it. After calling consumeInput,
the application may check isBusy and/or notifies to see if their state has changed.


$ret = $conn->getline($string, $length)

Reads a string up to $length - 1 characters from the backend.
getline returns EOF at EOF, 0 if the entire line has been read,
and 1 if the buffer is full. If a line consists of the two
characters "\." the backend has finished sending the results of
the copy command.


$ret = $conn->putline($string)

Sends a string to the backend. The application must explicitly
send the two characters "\." to indicate to the backend that
it has finished sending its data.


$ret = $conn->getlineAsync($buffer, $bufsize)

Non-blocking version of getline. It reads up to $bufsize
characters from the backend. getlineAsync returns -1 if
the end-of-copy-marker has been recognized, 0 if no data
is avilable, and >0 the number of bytes returned.


$ret = $conn->putnbytes($buffer, $nbytes)

Sends n bytes to the backend. Returns 0 if OK, EOF if not.


$ret = $conn->endcopy

This function waits until the backend has finished the copy.
It should either be issued when the last string has been sent
to the backend using putline or when the last string has
been received from the backend using getline. endcopy returns
0 on success, 1 on failure.


$result = $conn->makeEmptyPGresult($status);

Returns a newly allocated, initialized result with given status.
ソフト開発塾 前のページへ戻る

--- KONDO-NET.GR.JP ---
今日のアクセス人目