exec ?expect ?params ?binary_params ?binary_result 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.
Additional query parameters can be passed in the params array. They must not be escaped and they can be referred to in query as $1, $2, ... The value null can be used in the params array to denote an SQL NULL. It is possible to specify that some of the query parameters are passed as binary strings using the binary_params array. By default, results are returned in text format, but will be returned in binary format if binary_result is true.
If no (or an empty) query parameter is passed, it is possible to emit several commands with a single call.
#describe_prepared stm_name submits a request to obtain information about the specified prepared statement, and waits for completion. describe_prepared allows an application to obtain information about a previously prepared statement. The stm_name parameter can be the empty string ("") to reference the unnamed statement, otherwise it must be the name of an existing prepared statement. On success, a result with status Command_ok is returned. The methods result.nparams and result.paramtype of the class result can be used to obtain information about the parameters of the prepared statement, and the methods result.nfields, result.fname and result.ftype provide information about the result columns (if any) of the statement.
To prepare a statement use the SQL command PREPARE.
method send_query : ?params:string array->?binary_params:bool array->string ->
unit
send_query ?params ?binary_params query asynchronous execution of query or command query.
Additional query parameters can be passed in the params array. They must not be escaped and they can be referred to in query as $1, $2, ... The value null can be used in the params array to denote an SQL NULL. It is possible to specify that some of the query parameters are passed as binary strings using the binary_params array.
If no (or an empty) query parameter is passed, it is possible to emit several commands with a single call.
parameterparams
default = ||
parameterbinary_params
default = ||
raisesError
if there is a connection error.
method send_prepare : string ->string -> unit
#send_prepare stm_name query sends a query preparation without waiting for the result. This does the same as prepare except that the status is reported by get_result when available.
raisesError
if there is a connection error.
method send_query_prepared : ?params:string array->?binary_params:bool array->string ->
unit
#send_query_prepared ?params ?binary_params stm_name is an asynchronous version of query_prepared. The semantics is otherwise the same, and the result is reported by get_result when available.
parameterparams
default = ||
parameterbinary_params
default = ||
raisesError
if there is a connection error.
method send_describe_prepared : string -> unit
#send_describe_prepared stm_name sends a request for a description of a prepared query without waiting for the result. The result must be fetched with get_result when it becomes available. Otherwise it does the same as describe_prepared.
raisesError
if there is a connection error.
method send_describe_portal : string -> unit
#send_describe_portal portal_name sends a request for a description of the named portal. The result must be fetched with get_result.
raisesError
if there is a connection error.
method set_single_row_mode : unit
#set_single_row_mode called right after send_query or a sibling function causes the returned rows to be split into individual results.
put_copy_data ?pos ?len buf sends buf of length len starting at pos to the backend server, which must be in copy-in mode. In non-blocking mode, returns Put_copy_not_queued if the data was not queued due to full buffers.
put_copy_end ?error_msg () terminates the copy-in mode, leaving the connection in Command_ok or failed state. In non-blocking mode, returns Put_copy_not_queued if the termination message was not queued due to full buffers. Also, to ensure delivery of data in non-blocking mode, repeatedly wait for write-ready an call #flush.
parametererror_msg
if set, force the copy operation to fail with the given message.
get_copy_data ?async () retrieves the next row of data if available. Only single complete rows are returned. In synchronous mode, the call will wait for completion of the next row. In asynchronous mode it will return immediately with Get_copy_wait if the row transfer is incomplete. In that case, wait for read-ready and call #consume_input before retrying.
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.
returns
getline_async_result
parameterpos
default = 0
parameterlen
default = Bytes.length buf - pos
raisesInvalid_argument
if the buffer parameters are invalid.
raisesError
if there is a connection error.
method putline : string -> unit
putline str sends str to backend server. Don't use this method for binary data, use putnbytes instead!
raisesError
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).
parameterpos
default = 0
parameterlen
default = String.length buf - pos
raisesInvalid_argument
if the buffer parameters are invalid.
raisesError
if there is a connection error.
method endcopy : unit
endcopy synchronizes with the backend.
raisesError
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.
After creating a connection with ~startonly:true, connect_poll must be called a number of times before the connection can be used. The precise procedure is described in the libpq manual, but the following code should capture the idea, assuming monadic concurrency primitives return and >>= along with polling functions wait_for_read and wait_for_write:
let my_async_connect () =
let c = new connection () in
let rec establish_connection = function
| Polling_failed | Polling_ok -> return c
| Polling_reading -> wait_for_read c#socket >>= fun () ->
establish_connection c#connect_poll
| Polling_writing -> wait_for_write c#socket >>= fun () ->
establish_connection c#connect_poll in
establish_connection Polling_writing
See also examples/async.ml.
method reset_start : bool
An asynchronous variant of reset. Use reset_poll to finish re-establishing the connection.
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).