class virtual connection : ?host:string -> ?port:string -> ?user:string -> ?password:string -> string ->
object
.. end
Connection managment & information
method id : int
Returns a unique integer which can be used to identify this
connection.
method close : unit -> unit
Closes the database handle. All statement handles are also invalidated.
Database handles which are collected by the GC are automatically
closed, but you should explicitly close handles to save resources,
where possible.
method closed : bool
Returns true
if this database handle has been closed. Subsequent
operations on the handle will fail.
method ping : unit -> bool
This uses some active method to verify that the database handle is
still working. By this I mean that it tries to execute some sort of
'null' statement against the database to see if it gets a response.
If the database is up, it returns true
. If the database is down or
unresponsive, it returns false
. This method should never throw
an exception (unless, perhaps, there is some sort of catastrophic
internal error in the Dbi
library or the driver).
method host : string option
Return the host
parameter.
method port : string option
Return the port
parameter.
method user : string option
Return the user
parameter.
method password : string option
Return the password
parameter.
method database : string
Return the database name.
method virtual database_type : string
Database type (e.g. "postgres").
method set_debug : bool -> unit
Use this to enable debugging on the handle. In this mode significant
events (such as executing queries) are printed out on stderr.
method debug : bool
Returns true if this handle has debugging enabled.
Database creation, destruction & connection
Statement preparation
method virtual prepare : string -> statement
Prepare a database query, and return the prepared statement.
The statement may contain ?
placeholders which can be substituted
for values when the statement is executed.
method prepare_cached : string -> statement
This method is identical to prepare
except that, if possible, it
caches the statement handle with the database object. Future calls
with the same query string return the previously prepared statement.
For databases which support prepared statement handles, this avoids
a round-trip to the database, and an expensive recompilation of the
statement.
method ex : string -> sql_t list -> statement
dbh#ex stm args
is a shorthand for
let sth = dbh#prepare_cached stmt in
sth#execute args;
sth
Commit and rollback
method commit : unit -> unit
Perform a COMMIT operation on the database.
method rollback : unit -> unit
Perform a ROLLBACK operation on the database.
method register_precommit : (unit -> unit) -> precommit_handle
Register a function which will be called just BEFORE a commit
happens on this handle. This method returns a handle which can
be used to deregister the callback later. This is useful for
implementing various types of persistence.
method unregister_precommit : precommit_handle -> unit
Unregister a precommit callback.
method register_postrollback : (unit -> unit) -> postrollback_handle
Register a function which will be called just AFTER a rollback
happens on this handle. This method returns a handle which can
be used to deregister the callback later. This is useful for
implementing various types of persistence.
method unregister_postrollback : postrollback_handle -> unit
Unregister a postrollback callback.