Module Dbi


module Dbi: sig  end
Generic database interface.

Making a connection to a specific type of database:

 module DB = Dbi_postgres
 let dbh = new DB.connection "database_name"

Equivalent to above, except that we make a connection to a named type of database:

 let dbh =
   try
     Dbi.Factory.connect "postgres" "database_name"
   with
     Not_found -> failwith "Postgres driver not available."

From Apache, using persistent connections (see Apache.DbiPool):

 let dbh = Apache.DbiPool.get r "postgres" "database_name"

Simple usage, returning one row:

 let sth = dbh#prepare "select name from employees where empid = ?" in
 sth#execute [ `Int 100 ];
 let row = sth#fetch1 in
 let name = row.(0) in

Simple usage, returning multiple rows:

 let sth = dbh#prepare "select name from employees where salary > ?" in
 sth#execute [ `Int 10000 ];
 sth#iter (fun row -> Printf.printf "name = %s\n" row.(0))

Advanced usage, binding columns for maximum efficiency:

 let sth = dbh#prepare "select name from employees where salary > ?" in
 sth#execute [ `Int 10000 ];
 let name = ref "" in
 sth#bind_columns [ `StringRef name ];
 while sth#next do
   Printf.printf "name = %s\n" !name
 done

Advanced usage, reusing prepared statements:

 let sth =
   dbh#prepare "insert into employees (name, salary) values (?, ?)" in
 List.iter (
   fun (name, salary) ->
     sth#execute [ `String name; `Int salary ];
     let id = sth#serial "" in
     Printf.printf "Employee %s has been assigned ID %d\n" name id
 ) employee_list;


type arg_t = [ `Bool of bool
| `BoolOption of bool option
| `Int of int
| `IntOption of int option
| `Interval of interval_t
| `IntervalOption of interval_t option
| `Null
| `Numeric of float
| `NumericOption of float option
| `String of string
| `StringOption of string option
| `Timestamp of timestamp_t
| `TimestampOption of timestamp_t option ]
Type of arguments to the statement#execute method. The *Option arguments can be Some thing or None meaning SQL NULL.

type timestamp_t = {
   ts_is_null : bool; (*Null? Other fields will be 0.*)
   ts_year : int;
   ts_month : int;
   ts_day : int;
   ts_hour : int;
   ts_min : int;
   ts_sec : int;
   ts_microsecs : int;
   ts_utc_offset : int;
}
Timestamp type.

type interval_t = {
   iv_is_null : bool; (*Null? Other fields will be 0.*)
   iv_years : int;
   iv_months : int;
   iv_days : int;
   iv_hours : int;
   iv_mins : int;
   iv_secs : int;
   iv_microsecs : int;
}
Interval type.
val null_timestamp : timestamp_t
A timestamp with the ts_is_null field set to true.
val null_interval : interval_t
An interval with the iv_is_null field set to true.
type ref_t = [ `IntOptionRef of int option Pervasives.ref
| `IntRef of int Pervasives.ref
| `NumericOptionRef of float option Pervasives.ref
| `NumericRef of float Pervasives.ref
| `StringOptionRef of string option Pervasives.ref
| `StringRef of string Pervasives.ref ]
Type of arguments to the statement#bind_columns method.
type precommit_handle 
See Dbi.connection.register_precommit.
type postrollback_handle 
See Dbi.connection.register_postrollback.
exception SQL_error of string
Exceptions thrown by subclasses on SQL errors.
class virtual statement : connection -> object  end
class virtual connection : ?host:string ->
?port:string -> ?user:string -> ?password:string -> string -> object end
module Factory: sig  end