Source file binding_wrappers.ml

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
open Ctypes
open Util

module B = Ffi_generated.Functions
module T = Ffi_generated.Types

include B

let handle (typ, z) f =
  let r = allocate typ z in
  let s = f r in
  (s, !@r)

let handle_opt typ = handle (typ, None)
let handle_int f = handle (int, 0) f
let handle_char f = handle (char, '\000') f
let handle_ret = handle_opt B.mysql_opt

let mysql_init () =
  B.mysql_init None

let mysql_options mysql opt value =
  B.mysql_options mysql opt value |> ignore

let mysql_options4 mysql opt value1 value2 =
  B.mysql_options4 mysql opt value1 value2 |> ignore

let mysql_stmt_attr_set_bool stmt attr value =
  let c = if value then '\001' else '\000' in
  let v = allocate B.my_bool c in
  B.mysql_stmt_attr_set stmt attr (to_voidp v) |> ignore

let mysql_stmt_param_count stmt =
  Unsigned.ULong.to_int @@ B.mysql_stmt_param_count stmt

let mysql_stmt_bind_param stmt bind =
  B.mysql_stmt_bind_param stmt (to_voidp bind) = '\000'

let mysql_fetch_field_direct res i =
  B.mysql_fetch_field_direct res (Unsigned.UInt.of_int i)

let mysql_stmt_bind_result stmt bind =
  B.mysql_stmt_bind_result stmt (to_voidp bind) = '\000'

let mysql_stmt_num_rows stmt =
  Unsigned.ULLong.to_int @@ B.mysql_stmt_num_rows stmt

let mysql_stmt_affected_rows stmt =
  Unsigned.ULLong.to_int @@ B.mysql_stmt_affected_rows stmt

let mysql_stmt_insert_id stmt =
  Unsigned.ULLong.to_int @@ B.mysql_stmt_insert_id stmt

(* Blocking API *)

let mysql_real_connect mysql host user pass db port socket flags =
  let host = char_ptr_opt_buffer_of_string host in
  let user = char_ptr_opt_buffer_of_string user in
  let pass = char_ptr_opt_buffer_of_string pass in
  let db = char_ptr_opt_buffer_of_string db in
  let port = Unsigned.UInt.of_int port in
  let socket = char_ptr_opt_buffer_of_string socket in
  let flags = Unsigned.ULong.of_int64 (Int64.of_int32 flags) in
  B.mysql_real_connect mysql host user pass db port socket flags

let mysql_commit mysql =
  B.mysql_commit mysql = '\000'

let mysql_rollback mysql =
  B.mysql_rollback mysql = '\000'

let mysql_autocommit mysql auto =
  let auto = if auto then '\001' else '\000' in
  B.mysql_autocommit mysql auto = '\000'

let mysql_set_character_set mysql charset =
  B.mysql_set_character_set mysql charset = 0

let mysql_select_db mysql db =
  B.mysql_select_db mysql db = 0

let mysql_change_user mysql user pass db =
  B.mysql_change_user mysql user pass db = '\000'

let mysql_set_server_option mysql opt =
  B.mysql_set_server_option mysql opt = 0

let mysql_ping mysql =
  B.mysql_ping mysql = 0

let mysql_stmt_prepare stmt query =
  let len = Unsigned.ULong.of_int (String.length query) in
  let query = char_ptr_buffer_of_string query in
  B.mysql_stmt_prepare stmt query len = 0

let mysql_stmt_reset stmt =
  B.mysql_stmt_reset stmt = '\000'

let mysql_stmt_execute stmt =
  B.mysql_stmt_execute stmt = 0

let mysql_stmt_close stmt =
  B.mysql_stmt_close stmt = '\000'

let mysql_stmt_store_result stmt =
  B.mysql_stmt_store_result stmt = 0

let mysql_stmt_free_result stmt =
  B.mysql_stmt_free_result stmt = '\000'

let mysql_real_query mysql query =
  let len = Unsigned.ULong.of_int (String.length query) in
  let query = char_ptr_buffer_of_string query in
  B.mysql_real_query mysql query len = 0

(* Nonblocking API *)

let mysql_real_connect_start mysql host user pass db port socket flags =
  let port = Unsigned.UInt.of_int port in
  let flags = Unsigned.ULong.of_int64 (Int64.of_int32 flags) in
  handle_ret
    (fun ret ->
      B.mysql_real_connect_start ret mysql host user pass db port socket flags)

let mysql_real_connect_cont mysql status =
  handle_ret (fun ret -> B.mysql_real_connect_cont ret mysql status)

let mysql_get_timeout_value mysql =
  Unsigned.UInt.to_int @@ B.mysql_get_timeout_value mysql

let mysql_get_timeout_value_ms mysql =
  Unsigned.UInt.to_int @@ B.mysql_get_timeout_value_ms mysql

let mysql_set_character_set_start mysql charset =
  handle_int (fun ret -> B.mysql_set_character_set_start ret mysql charset)

let mysql_set_character_set_cont mysql status =
  handle_int (fun ret -> B.mysql_set_character_set_cont ret mysql status)

let mysql_select_db_start mysql db =
  handle_int (fun ret -> B.mysql_select_db_start ret mysql db)

let mysql_select_db_cont mysql status =
  handle_int (fun ret -> B.mysql_select_db_cont ret mysql status)

let mysql_change_user_start mysql user pass db =
  handle_char (fun ret -> B.mysql_change_user_start ret mysql user pass db)

let mysql_change_user_cont mysql status =
  handle_char (fun ret -> B.mysql_change_user_cont ret mysql status)

let mysql_set_server_option_start mysql opt =
  handle_int (fun ret -> B.mysql_set_server_option_start ret mysql opt)

let mysql_set_server_option_cont mysql status =
  handle_int (fun ret -> B.mysql_set_server_option_cont ret mysql status)

let mysql_ping_start mysql =
  handle_int (fun ret -> B.mysql_ping_start ret mysql)

let mysql_ping_cont mysql status =
  handle_int (fun ret -> B.mysql_ping_cont ret mysql status)

let mysql_stmt_prepare_start stmt query len =
  let len = Unsigned.ULong.of_int len in
  handle_int (fun err -> B.mysql_stmt_prepare_start err stmt query len)

let mysql_stmt_prepare_cont stmt status =
  handle_int (fun err -> B.mysql_stmt_prepare_cont err stmt status)

let mysql_stmt_reset_start stmt =
  handle_char (fun err -> B.mysql_stmt_reset_start err stmt)

let mysql_stmt_reset_cont stmt status =
  handle_char (fun err -> B.mysql_stmt_reset_cont err stmt status)

let mysql_stmt_execute_start stmt =
  handle_int (fun err -> B.mysql_stmt_execute_start err stmt)

let mysql_stmt_execute_cont stmt status =
  handle_int (fun err -> B.mysql_stmt_execute_cont err stmt status)

let mysql_stmt_fetch_start stmt =
  handle_int (fun err -> B.mysql_stmt_fetch_start err stmt)

let mysql_stmt_fetch_cont stmt status =
  handle_int (fun err -> B.mysql_stmt_fetch_cont err stmt status)

let mysql_stmt_store_result_start stmt =
  handle_int (fun err -> B.mysql_stmt_store_result_start err stmt)

let mysql_stmt_store_result_cont stmt status =
  handle_int (fun err -> B.mysql_stmt_store_result_cont err stmt status)

let mysql_stmt_close_start stmt =
  handle_char (fun err -> B.mysql_stmt_close_start err stmt)

let mysql_stmt_close_cont stmt status =
  handle_char (fun err -> B.mysql_stmt_close_cont err stmt status)

let mysql_stmt_free_result_start stmt =
  handle_char (fun err -> B.mysql_stmt_free_result_start err stmt)

let mysql_stmt_free_result_cont stmt status =
  handle_char (fun err -> B.mysql_stmt_free_result_cont err stmt status)

let mysql_commit_start mysql =
  handle_char (fun err -> B.mysql_commit_start err mysql)

let mysql_commit_cont mysql status =
  handle_char (fun err -> B.mysql_commit_cont err mysql status)

let mysql_rollback_start mysql =
  handle_char (fun err -> B.mysql_rollback_start err mysql)

let mysql_rollback_cont mysql status =
  handle_char (fun err -> B.mysql_rollback_cont err mysql status)

let mysql_autocommit_start mysql auto =
  let auto = if auto then '\001' else '\000' in
  handle_char (fun err -> B.mysql_autocommit_start err mysql auto)

let mysql_autocommit_cont mysql status =
  handle_char (fun err -> B.mysql_autocommit_cont err mysql status)

let mysql_stmt_next_result_start stmt =
  handle_int (fun err -> B.mysql_stmt_next_result_start err stmt)

let mysql_stmt_next_result_cont stmt status =
  handle_int (fun err -> B.mysql_stmt_next_result_cont err stmt status)

let mysql_real_query_start mysql query =
  let len = Unsigned.ULong.of_int (String.length query) in
  let query = char_ptr_buffer_of_string query in
  handle_int (fun err -> B.mysql_real_query_start err mysql query len)

let mysql_real_query_cont mysql status =
  handle_int (fun err -> B.mysql_real_query_cont err mysql status)