2
* Drizzle Client & Protocol Library
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
14
* * Redistributions in binary form must reproduce the above
15
* copyright notice, this list of conditions and the following disclaimer
16
* in the documentation and/or other materials provided with the
19
* * The names of its contributors may not be used to endorse or
20
* promote products derived from this software without specific prior
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
* @brief Drizzle Declarations
45
#if !defined(__cplusplus)
50
#include <sys/types.h>
53
# include <winsock2.h>
54
# include <ws2tcpip.h>
57
# define EINPROGRESS WSAEINPROGRESS
58
# define EALREADY WSAEALREADY
59
# define EISCONN WSAEISCONN
60
# define ENOBUFS WSAENOBUFS
61
# define ECONNREFUSED WSAECONNREFUSED
62
# define ENETUNREACH WSAENETUNREACH
63
# define ETIMEDOUT WSAETIMEDOUT
64
# define ECONNRESET WSAECONNRESET
65
# define EADDRINUSE WSAEADDRINUSE
66
# define EOPNOTSUPP WSAEOPNOTSUPP
67
# define ENOPROTOOPT WSAENOPROTOOPT
69
typedef unsigned int in_port_t;
79
# include <sys/socket.h>
80
# include <netinet/in.h>
81
# include <arpa/inet.h>
88
#include <libdrizzle/visibility.h>
89
#include <libdrizzle/constants.h>
90
#include <libdrizzle/structs.h>
91
#include <libdrizzle/conn.h>
92
#include <libdrizzle/result.h>
93
#include <libdrizzle/column.h>
100
* @addtogroup drizzle Drizzle Declarations
101
* @ingroup drizzle_client_interface
102
* @ingroup drizzle_server_interface
104
* This is the core library structure that other structures (such as
105
* connections) are created from.
107
* There is no locking within a single drizzle_st structure, so for threaded
108
* applications you must either ensure isolation in the application or use
109
* multiple drizzle_st structures (for example, one for each thread).
114
* Get library version string.
116
* @return Pointer to static buffer in library that holds the version string.
119
const char *drizzle_version(void);
122
* Get bug report URL.
124
* @return Bug report URL string.
127
const char *drizzle_bugreport(void);
130
* Get string with the name of the given verbose level.
132
* @param[in] verbose Verbose logging level.
133
* @return String form of verbose level.
136
const char *drizzle_verbose_name(drizzle_verbose_t verbose);
139
* Initialize a drizzle structure. Always check the return value even if passing
140
* in a pre-allocated structure. Some other initialization may have failed.
142
* @param[in] drizzle Caller allocated structure, or NULL to allocate one.
143
* @return On success, a pointer to the (possibly allocated) structure. On
144
* failure this will be NULL.
147
drizzle_st *drizzle_create(drizzle_st *drizzle);
150
* Clone a drizzle structure.
152
* @param[in] drizzle Caller allocated structure, or NULL to allocate one.
153
* @param[in] from Drizzle structure to use as a source to clone from.
154
* @return Same return as drizzle_create().
157
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from);
160
* Free a drizzle structure.
162
* @param[in] drizzle Drizzle structure previously initialized with
163
* drizzle_create() or drizzle_clone().
166
void drizzle_free(drizzle_st *drizzle);
169
* Return an error string for last error encountered.
171
* @param[in] drizzle Drizzle structure previously initialized with
172
* drizzle_create() or drizzle_clone().
173
* @return Pointer to static buffer in library that holds an error string.
176
const char *drizzle_error(const drizzle_st *drizzle);
179
* Value of errno in the case of a DRIZZLE_RETURN_ERRNO return value.
181
* @param[in] drizzle Drizzle structure previously initialized with
182
* drizzle_create() or drizzle_clone().
183
* @return An errno value as defined in your system errno.h file.
186
int drizzle_errno(const drizzle_st *drizzle);
189
* Get server defined error code for the last result read.
191
* @param[in] drizzle Drizzle structure previously initialized with
192
* drizzle_create() or drizzle_clone().
193
* @return An error code given back in the server response.
196
uint16_t drizzle_error_code(const drizzle_st *drizzle);
199
* Get SQL state code for the last result read.
201
* @param[in] drizzle Drizzle structure previously initialized with
202
* drizzle_create() or drizzle_clone().
203
* @return A SQLSTATE code given back in the server response.
206
const char *drizzle_sqlstate(const drizzle_st *drizzle);
209
* Get options for a drizzle structure.
211
* @param[in] drizzle Drizzle structure previously initialized with
212
* drizzle_create() or drizzle_clone().
213
* @return Options set for the drizzle structure.
216
drizzle_options_t drizzle_options(const drizzle_st *drizzle);
219
* Set options for a drizzle structure.
221
* @param[in] drizzle Drizzle structure previously initialized with
222
* drizzle_create() or drizzle_clone().
223
* @param[in] options Available options for drizzle structure to set.
226
void drizzle_set_options(drizzle_st *drizzle, drizzle_options_t options);
229
* Add options for a drizzle structure.
231
* @param[in] drizzle Drizzle structure previously initialized with
232
* drizzle_create() or drizzle_clone().
233
* @param[in] options Available options for drizzle structure to add.
236
void drizzle_add_options(drizzle_st *drizzle, drizzle_options_t options);
239
* Remove options for a drizzle structure.
241
* @param[in] drizzle Drizzle structure previously initialized with
242
* drizzle_create() or drizzle_clone().
243
* @param[in] options Available options for drizzle structure to remove.
246
void drizzle_remove_options(drizzle_st *drizzle, drizzle_options_t options);
249
* Get application context pointer.
251
* @param[in] drizzle Drizzle structure previously initialized with
252
* drizzle_create() or drizzle_clone().
253
* @return Application context that was previously set, or NULL.
256
void *drizzle_context(const drizzle_st *drizzle);
259
* Set application context pointer.
261
* @param[in] drizzle Drizzle structure previously initialized with
262
* drizzle_create() or drizzle_clone().
263
* @param[in] context Application context to set.
266
void drizzle_set_context(drizzle_st *drizzle, void *context);
269
* Set function to call when the drizzle structure is being cleaned up so
270
* the application can clean up the context pointer.
272
* @param[in] drizzle Drizzle structure previously initialized with
273
* drizzle_create() or drizzle_clone().
274
* @param[in] function Function to call to clean up drizzle context.
277
void drizzle_set_context_free_fn(drizzle_st *drizzle,
278
drizzle_context_free_fn *function);
281
* Get current socket I/O activity timeout value.
283
* @param[in] drizzle Drizzle structure previously initialized with
284
* drizzle_create() or drizzle_clone().
285
* @return Timeout in milliseconds to wait for I/O activity. A negative value
286
* means an infinite timeout.
289
int drizzle_timeout(const drizzle_st *drizzle);
292
* Set socket I/O activity timeout for connections in a Drizzle structure.
294
* @param[in] drizzle Drizzle structure previously initialized with
295
* drizzle_create() or drizzle_clone().
296
* @param[in] timeout Milliseconds to wait for I/O activity. A negative value
297
* means an infinite timeout.
300
void drizzle_set_timeout(drizzle_st *drizzle, int timeout);
303
* Get current verbosity threshold for logging messages.
305
* @param[in] drizzle Drizzle structure previously initialized with
306
* drizzle_create() or drizzle_clone().
307
* @return Current verbosity threshold.
310
drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle);
313
* Set verbosity threshold for logging messages. If this is set above
314
* DRIZZLE_VERBOSE_NEVER and the drizzle_set_log_fn() callback is set to NULL,
315
* messages are printed to STDOUT.
317
* @param[in] drizzle Drizzle structure previously initialized with
318
* drizzle_create() or drizzle_clone().
319
* @param[in] verbose Verbosity threshold of what to log.
322
void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose);
325
* Set logging function for a drizzle structure. This function is only called
326
* for log messages that are above the verbosity threshold set with
327
* drizzle_set_verbose().
329
* @param[in] drizzle Drizzle structure previously initialized with
330
* drizzle_create() or drizzle_clone().
331
* @param[in] function Function to call when there is a logging message.
332
* @param[in] context Argument to pass into the callback function.
335
void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function,
339
* Set a custom I/O event watcher function for a drizzle structure. Used to
340
* integrate libdrizzle with a custom event loop. The callback will be invoked
341
* to register or deregister interest in events for a connection. When the
342
* events are triggered, drizzle_con_set_revents() should be called to
343
* indicate which events are ready. The event loop should stop waiting for
344
* these events, as libdrizzle will call the callback again if it is still
345
* interested. To resume processing, the libdrizzle function that returned
346
* DRIZZLE_RETURN_IO_WAIT should be called again. See drizzle_event_watch_fn().
348
* @param[in] drizzle Drizzle structure previously initialized with
349
* drizzle_create() or drizzle_clone().
350
* @param[in] function Function to call when there is an I/O event.
351
* @param[in] context Argument to pass into the callback function.
354
void drizzle_set_event_watch_fn(drizzle_st *drizzle,
355
drizzle_event_watch_fn *function,
359
* Initialize a connection structure. Always check the return value even if
360
* passing in a pre-allocated structure. Some other initialization may have
363
* @param[in] drizzle Drizzle structure previously initialized with
364
* drizzle_create() or drizzle_clone().
365
* @param[in] con Caller allocated structure, or NULL to allocate one.
366
* @return On success, a pointer to the (possibly allocated) structure. On
367
* failure this will be NULL.
370
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle, drizzle_con_st *con);
373
* Clone a connection structure.
375
* @param[in] drizzle Drizzle structure previously initialized with
376
* drizzle_create() or drizzle_clone().
377
* @param[in] con Caller allocated structure, or NULL to allocate one.
378
* @param[in] from Connection structure to use as a source to clone from.
379
* @return Same return as drizzle_con_create().
382
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con,
383
const drizzle_con_st *from);
386
* Free a connection structure.
388
* @param[in] con Connection structure previously initialized with
389
* drizzle_con_create(), drizzle_con_clone(), or related functions.
392
void drizzle_con_free(drizzle_con_st *con);
395
* Free all connections in a drizzle structure.
397
* @param[in] drizzle Drizzle structure previously initialized with
398
* drizzle_create() or drizzle_clone().
401
void drizzle_con_free_all(drizzle_st *drizzle);
404
* Wait for I/O on connections.
406
* @param[in] drizzle Drizzle structure previously initialized with
407
* drizzle_create() or drizzle_clone().
408
* @return Standard drizzle return value.
411
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle);
414
* Get next connection that is ready for I/O.
416
* @param[in] drizzle Drizzle structure previously initialized with
417
* drizzle_create() or drizzle_clone().
418
* @return Connection that is ready for I/O, or NULL if there are none.
421
drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle);
429
#endif /* __DRIZZLE_H */