-
Notifications
You must be signed in to change notification settings - Fork 1
/
ocamlodbc.mli
133 lines (110 loc) · 6.23 KB
/
ocamlodbc.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(*****************************************************************************)
(* OCamlODBC *)
(* *)
(* Copyright (C) 2004-2011 Institut National de Recherche en Informatique *)
(* et en Automatique. All rights reserved. *)
(* *)
(* This program is free software; you can redistribute it and/or modify *)
(* it under the terms of the GNU Lesser General Public License as published *)
(* by the Free Software Foundation; either version 2.1 of the License, or *)
(* any later version. *)
(* *)
(* This program is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU Lesser General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public License *)
(* along with this program; if not, write to the Free Software *)
(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)
(* 02111-1307 USA *)
(* *)
(* Contact: Maxence.Guesdon@inria.fr *)
(*****************************************************************************)
(** Interface to ODBC databases.
See http://home.gna.org/ocamlodbc/configuring.html for
configutation information. *)
(** {2 Classic interface} *)
(** The type of connections to databases. *)
type connection
val connect : string -> string -> string -> connection
(** [connect base user passwd] creates a connection to data source
[base], as user [user], with password [passwd].
@raise SQL_Error if the connection to the database failed. *)
val connect_driver : ?prompt:bool -> string -> connection
(** [connect_driver conn_string] exposes the SQLDriverConnect
function to OCaml (for ODBC v2 or greater under MinGW). This
allows SQLServer "trusted authentication" mode based on NT
domain identities. An example of [conn_string] is ["Driver={SQL
Server};SERVER=FOOSERVER;Trusted_Connection=yes;Database=MYDB"].
@param prompt tells whether the if the driver should raise a
dialog box to request username and password. Default: [false].
@raise SQL_Error if the connection to the database failed. *)
val disconnect : connection -> unit
(** Disconnect from a database. The given connection should not be
used after this function was called.
@raise SQL_Error if an error occured while disconnecting.*)
val execute : connection -> string -> int * string option list list
(** [execute c q] executes query [q] through connection [c] and
returns the result as a pair [(error_code, recordlist)], where a
record is a [string option list]. The [error_code] is 0 if no
error occured. Each field of a record can be [None], which
represents the SQL NULL, or [Some v] where [v] is a string holding
the field value. *)
val execute_with_info :
connection -> string
-> int * (string * Odbc.sql_t) list * string option list list
(** [execute_with_info c q] executes query [q] through connection [c] and
returns the result as a tuple [(error_code, type_list, record list)],
where [type_list] indicates the SQL types of the returned columns,
and a record is a [string list].
The [error_code] is [>= 0] if no error occured.*)
val execute_gen :
connection -> ?get_info:bool -> ?n_rec:int -> string ->
(string option list list -> unit) -> int * (string * Odbc.sql_t) list
(** [execute_gen c get_info n_rec q callback] executes query [q] over
the connection [c], and invokes [callback] on successful blocks of
the results (of [n_rec] records each). Each record is a [string
list] of fields.
The result is a tuple [(error_code, type_list)]. The
[error_code] is [>= 0] if no error occurred, [type_list] is
empty if [get_info] is [false]. *)
(** {2 Object-oriented interface} *)
(** The class which represents a connection to a database. The
connection occurs when the object is created.
@raise SQL_Error if an error occured during the connection to the
database. *)
class database :
string ->
string ->
string ->
object
method connect : unit -> unit
(** @deprecated The connection to the database oocurs when the
object is created.*)
method disconnect : unit -> unit
(** Disconnect from the database. The objet should not be used
after calling this method.
@raise SQL_Error if an error occurs while disconnecting.*)
method execute : string -> int * (string option list list)
(** [#execute q] executes query [q] and returns the result as a pair
[(error_code, recordlist)], where a record is a [string
list]. The [error_code] is 0 if no error occured.*)
method execute_with_info :
string -> int * ((string * Odbc.sql_t) list)
* (string option list list)
(** [#execute_with_info q] executes query [q] and returns the result
as a tuple [(error_code, type_list, record list)], where
[type_list] indicates the SQL types of the returned columns, and
a record is a [string list].
The [error_code] is 0 if no error occured.*)
method execute_gen :
?get_info:bool -> ?n_rec:int -> string ->
(string option list list -> unit) -> int * (string * Odbc.sql_t) list
(** [#execute_gen get_info n_rec q callback] executes query [q] and
invokes [callback] on successful blocks of the results (of
[n_rec] records each). Each record is a [string list] of fields.
The result is a tuple [(error_code, type_list)]. The
[error_code] is 0 if no error occurred, [type_list] is empty if
[get_info] is [false]. *)
end