Class Postgresql.connection


class connection : ?host:string -> ?hostaddr:string -> ?port:string -> ?dbname:string -> ?user:string -> ?password:string -> ?options:string -> ?tty:string -> ?requiressl:string -> ?conninfo:string -> unit -> object .. end
Class of connections.

When conninfo is given, it will be used instead of all other optional arguments.


Main routines

method finish : unit
#finish closes the connection.
Raises Error if there is a connection error.
method try_reset : unit
#try_reset tries to reset the connection if it is bad. If resetting fails, the error exception will be raised with Connection_failure.
Raises Error if there is a connection error.
method reset : unit
#reset resets the connection.
Raises Error if there is a connection error.

Asynchronous Notification

method notifies : (string * int) option
#notifies
Raises Error if there is a connection error.
Returns Some (name, pid) if available (None otherwise), where name is the name the of relation containing data, pid the process id of the backend.

Control Functions

method set_notice_processor : (string -> unit) -> unit
#set_notice_processor controls reporting of notice and warning messages generated by a connection.
Raises Error if there is a connection error.

Accessors

method db : string
#db
Raises Error if there is a connection error.
Returns database name of the connection.
method user : string
#user
Raises Error if there is a connection error.
Returns user name of the connection.
method pass : string
#pass
Raises Error if there is a connection error.
Returns password of the connection.
method host : string
#host
Raises Error if there is a connection error.
Returns server host name of the connection.
method port : string
#port
Raises Error if there is a connection error.
Returns port of the connection.
method tty : string
#tty
Raises Error if there is a connection error.
Returns debug tty of the connection.
method options : string
#options
Raises Error if there is a connection error.
Returns backend options of the connection.
method status : connection_status
#status
Raises Error if there is a connection error.
Returns current connection status.
method error_message : string
#error_message
Raises Error if there is a connection error.
Returns most recent error message of the connection.
method backend_pid : int
#backend
Raises Error if there is a connection error.
Returns process id of the backend server of the connection.

Commands and Queries

method empty_result : result_status -> result
empty_result stat
Raises Error if there is a connection error.
Returns dummy result with a given status stat.
method exec : ?expect:result_status list -> string -> result
exec ?expect query synchronous execution of query or command query. The result status will be checked against all elements in expect. If expect is not empty and if there is no match, the exception Unexpected_status will be raised.
Raises Returns result of query.
expect : default = []
method send_query : string -> unit
send_query query asynchronous execution of query or command query.
Raises Error if there is a connection error.
method get_result : result option
get_result
Raises Error if there is a connection error.
Returns Some result of an asynchronous query if available or None.

Copy operations

Low level

method getline : ?pos:int -> ?len:int -> string -> getline_result
getline ?pos ?len buf reads a newline-terminated line of at most len characters into buf starting at position pos.
Raises Returns getline_result
pos : default = 0
len : default = String.length buf - pos
method getline_async : ?pos:int -> ?len:int -> string -> getline_async_result
getline_async ?pos ?len buf reads a newline-terminated line of at most len characters into buf starting at position pos (asynchronously). No need to call endcopy after receiving EndOfData.
Raises Returns getline_async_result
pos : default = 0
len : default = String.length buf - pos
method putline : string -> unit
putline str sends str to backend server. Don't use this method for binary data, use putnbytes instead!
Raises Error if there is a connection error.
method putnbytes : ?pos:int -> ?len:int -> string -> unit
putnbytes ?pos ?len buf sends the substring of buf of length len starting at pos to backend server (use this method for binary data).
Raises
pos : default = 0
len : default = String.length buf - pos
method endcopy : unit
endcopy synchronizes with the backend.
Raises Error if there is a connection error.

High level

method copy_out : (string -> unit) -> unit
copy_out f applies f to each line returned by backend server.
Raises Error if there is a connection error.
method copy_out_channel : Pervasives.out_channel -> unit
copy_out_channel ch sends each line returned by backend server to output channel ch.
Raises Error if there is a connection error.
method copy_in_channel : Pervasives.in_channel -> unit
copy_in_channel ch sends each line in input channel ch to backend server.
Raises Error if there is a connection error.

Asynchronous operations and non blocking mode

method set_nonblocking : bool -> unit
set_nonblocking b sets state of the connection to nonblocking if b is true and to blocking otherwise.
Raises Error if there is a connection error.
method is_nonblocking : bool
is_nonblocking
Raises Error if there is a connection error.
Returns the blocking status of the connection.
method consume_input : unit
consume_input consume any available input from backend.
Raises Error if there is a connection error.
method is_busy : bool
is_busy
Raises Error if there is a connection error.
Returns busy status of a query.
method flush : unit
flush attempts to flush any data queued to the backend.
Raises Error if there is a connection error.
method socket : Unix.file_descr
socket obtains the file descriptor for the backend connection socket.
Raises Error if there is a connection error.
method request_cancel : unit
request_cancel requests that PostgreSQL abandon processing of the current command.
Raises Error if there is a connection error.

Large objects

method lo_creat : oid
lo_creat creates a new large object and returns its oid.
Raises Error if there is a connection error.
method lo_import : string -> oid
lo_import filename imports an operating system file given by filename as a large object.
Raises Error if there is a connection error.
method lo_export : oid -> string -> unit
lo_export oid filename exports the large object given by oid to an operating system file given by filename.
Raises Error if there is a connection error.
method lo_open : oid -> large_object
lo_open oid opens the large object given by oid for reading and writing.
Raises Error if there is a connection error.
method lo_write : ?pos:int -> ?len:int -> string -> large_object -> unit
lo_write ?pos ?len buf lo writes len bytes of buffer buf starting at position pos to large object lo.
Raises
pos : default = 0
len : default = String.length buf - pos
method lo_read : large_object -> ?pos:int -> ?len:int -> string -> int
lo_read lo ?pos ?len buf reads len bytes from large object lo to buffer buf starting at position pos.
Raises
pos : default = 0
len : default = String.length buf - pos
method lo_seek : ?pos:int -> ?whence:seek_cmd -> large_object -> unit
lo_seek ?pos ?whence lo seeks read/write position pos in large object lo relative to the start, current read/write position, or end of the object (whence is SEEK_SET, SEEK_CUR, SEEK_END respectively).
Raises Error if there is a connection error.
pos : default = 0
whence : default = SEEK_SET
method lo_tell : large_object -> int
lo_tell lo
Raises Error if there is a connection error.
Returns current read/write position of large object lo.
method lo_close : large_object -> unit
lo_close lo closes large object lo.
Raises Error if there is a connection error.
method lo_unlink : oid -> unit
lo_unlink oid removes the large object specified by oid from the database.
Raises Error if there is a connection error.
method escape_bytea : ?pos:int -> ?len:int -> string -> string
escape_bytea ?pos ?len str escapes binary substring str of length len starting at position pos for use within SQL.
pos : default = 0
len : default = String.length str - pos