Common Lisp Package: POSTGRESQL

README:

FUNCTION

Public

PG-BACKEND-VERSION (CONN)

Return a string identifying the version and operating environment of the backend.

PG-CLIENT-ENCODING (CONN)

Return a string identifying the client encoding.

PG-COLUMNS (CONN TABLE)

Return a list of the columns present in TABLE.

PG-CONNECT (DBNAME USER &KEY (HOST localhost) (PORT 5432) (PASSWORD ) (ENCODING *PG-CLIENT-ENCODING*))

Initiate a connection with the PostgreSQL backend. Connect to the database DBNAME with the username USER, on PORT of HOST, providing PASSWORD if necessary. Return a connection to the database (as an opaque type). If HOST is a pathname or a string starting with #/, it designates the directory containing the Unix socket on which PostgreSQL's backend is waiting for local connections. We first attempt to speak the PostgreSQL 7.4 protocol, and fall back to the older network protocol if necessary.

PG-DATABASES (CONN)

Return a list of the databases available at this site.

PG-FOR-EACH (CONN SELECT-FORM CALLBACK)

Create a cursor for SELECT-FORM, and call CALLBACK for each result. Uses the PostgreSQL database connection CONN. SELECT-FORM must be an SQL SELECT statement. The cursor is created using an SQL DECLARE CURSOR command, then results are fetched successively until no results are left. The cursor is then closed. The work is performed within a transaction. The work can be interrupted before all tuples have been handled by THROWing to a tag called 'pg-finished.

PG-RESULT (RESULT WHAT &REST ARGS)

Extract WHAT component of RESULT. RESULT should be a structure obtained from a call to `pg-exec', and WHAT should be one of :connection -> return the connection object :status -> return the status string provided by the database :attributes -> return the metadata, as a list of lists :tuples -> return the data, as a list of lists :tuple n -> return the nth component of the data :oid -> return the OID (a unique identifier generated by PostgreSQL for each row resulting from an insertion

PG-TABLES (CONN)

Return a list of the tables present in this database.

Undocumented

PG-DATE-STYLE (CONN)

PGLO-CLOSE (CONNECTION FD)

PGLO-CREATE (CONNECTION &OPTIONAL (MODESTR r))

PGLO-EXPORT (CONNECTION OID FILENAME)

PGLO-IMPORT (CONNECTION FILENAME)

PGLO-LSEEK (CONNECTION FD OFFSET WHENCE)

PGLO-OPEN (CONNECTION OID &OPTIONAL (MODESTR r))

PGLO-TELL (CONNECTION FD)

PGLO-WRITE (CONNECTION FD BUF)

Private

%READ-BYTES (STREAM HOWMANY)

Reads HOWMANY bytes from the STREAM. Returns the array of

%READ-CSTRING (STREAM MAXBYTES)

Read a null-terminated string from CONNECTION.

%READ-NET-INT16 (STREAM)

Reads an integer BYTES bytes long from the STREAM. The signed integer is presumed to be in network order. Returns the integer.

%READ-NET-INT32 (STREAM)

Reads an integer BYTES bytes long from the STREAM. The signed integer is presumed to be in network order. Returns the integer.

%READ-NET-INT8 (STREAM)

Reads an integer BYTES bytes long from the STREAM. The signed integer is presumed to be in network order. Returns the integer.

%SEND-CSTRING (STREAM STR)

Sends a null-terminated string to CONNECTION

DO-FOLLOWUP-QUERY (CONNECTION)

Does the followup of a query

LOOKUP-TYPE (TYPE)

Given the name of a type, returns the oid of the type or NIL if not found

PG-CONNECT/V2 (DBNAME USER &KEY (HOST localhost) (PORT 5432) (PASSWORD ) (ENCODING *PG-CLIENT-ENCODING*))

Initiate a connection with the PostgreSQL backend, using protocol v2. Connect to the database DBNAME with the username USER, on PORT of HOST, providing PASSWORD if necessary. Return a connection to the database (as an opaque type). If HOST is a pathname or a string whose first character is #/, it designates the directory containing the Unix socket on which the PostgreSQL backend is listening.

PG-CONNECT/V3 (DBNAME USER &KEY (HOST localhost) (PORT 5432) (PASSWORD ) (ENCODING *PG-CLIENT-ENCODING*))

Initiate a connection with the PostgreSQL backend. Connect to the database DBNAME with the username USER, on PORT of HOST, providing PASSWORD if necessary. Return a connection to the database (as an opaque type). If HOST is a pathname or a string whose first character is #/, it designates the directory containing the Unix socket on which the PostgreSQL backend is listening.

PGRESULT-ATTRIBUTES (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PGRESULT-CONNECTION (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PGRESULT-STATUS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PGRESULT-TUPLES (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

READ-PACKET (CONNECTION)

Reads a packet from the connection. Returns the packet, handles errors and notices automagically, but will still return them

SEND-PACKET (CONNECTION CODE DESCRIPTION)

Sends a packet to the connection. CODE is the character code of the packet, description is a list of items with as first element one of :byte, :char :int16 :int32 or :cstring and as second element the value of the parameter

SET-PG-CLIENT-ENCODING (CONN NEW-ENCODING)

Set the client_encoding.

Undocumented

%FLUSH (CONNECTION)

%READ-CHARS (STREAM HOWMANY)

%SEND-NET-INT (STREAM INT BYTES)

BITMAP-REF/V2 (BITMAP REF)

BOOL-PARSER (STR)

BYTEA->STRING (DATA)

CONVERT-STRING-FROM-BYTES (BYTES ENCODING)

CONVERT-STRING-TO-BYTES (STRING ENCODING)

COPY-PGRESULT (INSTANCE)

CRYPT (KEY SALT)

DATE-PARSER (STR)

FLOAT-PARSER (STR)

HANDLE-NOTICE (CONNECTION)

HANDLE-NOTICE/V3 (CONNECTION PACKET)

IMPLEMENTATION-NAME-FOR-ENCODING (ENCODING)

INITIALIZE-PARSERS (CONNECTION)

INTEGER-PARSER (STR)

INTERVAL-PARSER (STR)

ISODATE-PARSER (STR)

LO-INIT (CONNECTION)

MAKE-PGRESULT (&KEY ((CONNECTION DUM138) NIL) ((STATUS DUM139) NIL) ((ATTRIBUTES DUM140) NIL) ((TUPLES DUM141) NIL))

MD5-DIGEST (STRING &REST STRINGS)

MD5-ENCODE-PASSWORD (USER PASSWORD SALT)

NUMERIC-PARSER (STR)

PARSE (STR OID)

PARSE-TIMESTAMP (STR)

PG-CLOSE (CONNECTION NAME TYPE)

PG-DESCRIBE-TABLE (CONN TABLE)

SETFPGRESULT-ATTRIBUTES (NEW-VALUE INSTANCE)

SETFPGRESULT-CONNECTION (NEW-VALUE INSTANCE)

PGRESULT-P (OBJECT)

SETFPGRESULT-STATUS (NEW-VALUE INSTANCE)

SETFPGRESULT-TUPLES (NEW-VALUE INSTANCE)

PRECISE-TIMESTAMP-PARSER (STR)

READ-AND-GENERATE-ERROR-RESPONSE (CONNECTION PACKET)

READ-AND-HANDLE-NOTIFICATION-RESPONSE (CONNECTION PACKET)

READ-ATTRIBUTES/V2 (CONNECTION)

READ-ATTRIBUTES/V3 (PACKET)

READ-NET-INT (CONNECTION BYTES)

READ-TUPLE/V2 (CONNECTION ATTRIBUTES)

READ-TUPLE/V3 (PACKET ATTRIBUTES)

ROW-PARSER (STR)

SEND-INT (CONNECTION INT BYTES)

SEND-OCTETS (CONNECTION BUFFER)

SEND-STRING (CONNECTION STR &OPTIONAL PAD-TO)

SET-PG-DATE-STYLE (CONN NEW-DATE-STYLE)

SOCKET-CONNECT (PORT HOST-NAME)

TEXT-PARSER (STR)

TIMESTAMP-PARSER (STR)

MACRO

Public

WITH-PG-CONNECTION ((CON &REST OPEN-ARGS) &BODY BODY)

Bindspec is of the form (connection open-args), where OPEN-ARGS are as for PG-CONNECT. The database connection is bound to the variable CONNECTION. If the connection is unsuccessful, the forms are not evaluated. Otherwise, the BODY forms are executed, and upon termination, normal or otherwise, the database connection is closed.

WITH-PG-TRANSACTION (CON &BODY BODY)

Execute BODY forms in a BEGIN..END block. If a PostgreSQL error occurs during execution of the forms, execute a ROLLBACK command. Large-object manipulations _must_ occur within a transaction, since the large object descriptors are only valid within the context of a transaction.

Private

Undocumented

%SYSDEP (DESC &REST FORMS)

GENERIC-FUNCTION

Public

PG-BIND (CONNECTION PORTAL STATEMENT-NAME LIST-OF-TYPES-AND-VALUES)

Gives the values for the parameters defined in the statement-name. The types can be one of :char :byte :int16 :int32 or :cstring

PG-CLOSE-PORTAL (CONNECTION PORTAL)

Closes a prepared statement portal

PG-CLOSE-STATEMENT (CONNECTION STATEMENT-NAME)

Closes prepared statement specified by STATEMENT-NAME and closes all portals associated with that statement (see PG-PREPARE and PG-BIND).

PG-DISCONNECT (CONNECTION &KEY ABORT)

Disconnects from the DB

PG-EXEC (CONNECTION &REST ARGS)

Execute the SQL command given by the concatenation of ARGS on the database to which we are connected via CONNECTION. Return a result structure which can be decoded using `pg-result'.

PG-EXECUTE (CONNECTION PORTAL &OPTIONAL MAXIMUM-NUMBER-OF-ROWS)

Executes the portal defined previously and return (optionally) up to MAXIMUM-NUMBER-OF-ROWS. For an unlimited number of rows use 0.

PG-PREPARE (CONNECTION STATEMENT-NAME SQL-STATEMENT &OPTIONAL TYPE-OF-PARAMETERS)

Prepares a sql-statement give a given statement-name (can be empty) and optionally declares the types of the parameters as a list of strings. You can define parameters to be filled in later by using $1 and so on.

PG-SUPPORTS-PBE (CONNECTION)

Returns true if the connection supports pg-prepare/-bind and -execute

PGLO-READ (CONNECTION FD BYTES)

Read from a large object on file descriptor FD.

Private

FN (CONNECTION FN INTEGER-RESULT &REST ARGS)

Execute one of the large-object functions (lo_open, lo_close etc). Argument FN is either an integer, in which case it is the OID of an element in the pg_proc table, and otherwise it is a string which we look up in the alist *lo-functions* to find the corresponding OID.

READ-FROM-PACKET (PACKET TYPE)

Reads an integer from the given PACKET with type TYPE

READ-STRING-FROM-PACKET (PACKET LENGTH)

Reads a string of LENGTH characters from the packet

Undocumented

AUTHENTICATION-FAILURE-REASON (CONDITION)

BACKEND-ERROR-REASON (CONDITION)

CONNECTION-FAILURE-HOST (CONDITION)

CONNECTION-FAILURE-PORT (CONDITION)

CONNECTION-FAILURE-TRANSPORT-ERROR (CONDITION)

ERROR-RESPONSE-CODE (CONDITION)

ERROR-RESPONSE-DETAIL (CONDITION)

ERROR-RESPONSE-FILE (CONDITION)

ERROR-RESPONSE-HINT (CONDITION)

ERROR-RESPONSE-LINE (CONDITION)

ERROR-RESPONSE-MESSAGE (CONDITION)

ERROR-RESPONSE-POSITION (CONDITION)

ERROR-RESPONSE-ROUTINE (CONDITION)

ERROR-RESPONSE-SEVERITY (CONDITION)

ERROR-RESPONSE-WHERE (CONDITION)

PROTOCOL-ERROR-REASON (CONDITION)

READ-OCTETS-FROM-PACKET (PACKET LENGTH)

SLOT-ACCESSOR

Public

Undocumented

PGCON-SQL-STREAM (OBJECT)

SETFPGCON-SQL-STREAM (NEW-VALUE OBJECT)

Private

Undocumented

PG-PACKET-LENGTH (OBJECT)

PG-PACKET-TYPE (OBJECT)

PGCON-BINARY-P (OBJECT)

SETFPGCON-BINARY-P (NEW-VALUE OBJECT)

PGCON-ENCODING (OBJECT)

SETFPGCON-ENCODING (NEW-VALUE OBJECT)

PGCON-HOST (OBJECT)

SETFPGCON-HOST (NEW-VALUE OBJECT)

PGCON-NOTICES (OBJECT)

SETFPGCON-NOTICES (NEW-VALUE OBJECT)

PGCON-PARAMETERS (OBJECT)

SETFPGCON-PARAMETERS (NEW-VALUE OBJECT)

PGCON-PID (OBJECT)

SETFPGCON-PID (NEW-VALUE OBJECT)

PGCON-PORT (OBJECT)

SETFPGCON-PORT (NEW-VALUE OBJECT)

PGCON-SECRET (OBJECT)

SETFPGCON-SECRET (NEW-VALUE OBJECT)

PGCON-STREAM (OBJECT)

SETFPGCON-STREAM (NEW-VALUE OBJECT)

VARIABLE

Public

*PG-CLIENT-ENCODING*

The encoding that will be used for communication with the PostgreSQL backend, for example "LATIN1", "UTF8", "EUC_JP". See <http://www.postgresql.org/docs/7.3/static/multibyte.html>.

*PG-DISABLE-TYPE-COERCION*

Non-nil disables the type coercion mechanism. The default is nil, which means that data recovered from the database is coerced to the corresponding Common Lisp type before being returned; for example numeric data is transformed to CL numbers, and booleans to booleans. The coercion mechanism requires an initialization query to the database, in order to build a table mapping type names to OIDs. This option is provided mainly in case you wish to avoid the overhead of this initial query. The overhead is only incurred once per session (not per connection to the backend).

Private

*TYPE-TO-OID*

Is a hashtable for turning a typename into a OID. Needed to define the type of objects in pg-prepare

Undocumented

*LO-FUNCTIONS*

*LO-INITIALIZED*

*PARSERS*

*PG-DATE-STYLE*

*TYPE-PARSERS*

CLASS

Private

Undocumented

BACKEND-NOTIFICATION

PG-PACKET

PGCON

PGCON-V2

PGCON-V3

PGRESULT

CONDITION

Public

Undocumented

AUTHENTICATION-FAILURE

BACKEND-ERROR

CONNECTION-FAILURE

POSTGRESQL-ERROR

PROTOCOL-ERROR

Private

Undocumented

ERROR-RESPONSE

CONSTANT

Private

Undocumented

+INV_ARCHIVE+

+INV_READ+

+INV_WRITE+

+LO_BUFSIZ+

+MAX_MESSAGE_LEN+

+NAMEDATALEN+

+SM_DATABASE+

+SM_OPTIONS+

+SM_TTY+

+SM_UNUSED+

+SM_USER+

+STARTUP_KRB4_MSG+

+STARTUP_KRB5_MSG+

+STARTUP_MSG+

+STARTUP_PACKET_SIZE+

+STARTUP_PASSWORD_MSG+