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
47
#include <sys/types.h>
50
# define WIN32_LEAN_AND_MEAN
53
# include <winsock2.h>
54
# include <ws2tcpip.h>
59
typedef unsigned int in_port_t;
62
# define snprintf _snprintf
63
# define inline __inline
72
//# define pollfd WSAPOLLFD
77
# if !defined(__cplusplus)
78
typedef enum { false = 0, true = 1 } _Bool;
84
# if !defined(__cplusplus)
87
# include <sys/socket.h>
88
# include <netinet/in.h>
89
# include <arpa/inet.h>
98
#include <libdrizzle/visibility.h>
99
#include <libdrizzle/constants.h>
100
#include <libdrizzle/structs.h>
101
#include <libdrizzle/conn.h>
102
#include <libdrizzle/result.h>
103
#include <libdrizzle/column.h>
110
* @addtogroup drizzle Drizzle Declarations
111
* @ingroup drizzle_client_interface
112
* @ingroup drizzle_server_interface
114
* This is the core library structure that other structures (such as
115
* connections) are created from.
117
* There is no locking within a single drizzle_st structure, so for threaded
118
* applications you must either ensure isolation in the application or use
119
* multiple drizzle_st structures (for example, one for each thread).
124
* Get library version string.
126
* @return Pointer to static buffer in library that holds the version string.
129
const char *drizzle_version(void);
132
* Get bug report URL.
134
* @return Bug report URL string.
137
const char *drizzle_bugreport(void);
140
* Get string with the name of the given verbose level.
142
* @param[in] verbose Verbose logging level.
143
* @return String form of verbose level.
146
const char *drizzle_verbose_name(drizzle_verbose_t verbose);
149
* Initialize a drizzle structure. Always check the return value even if passing
150
* in a pre-allocated structure. Some other initialization may have failed.
152
* @param[in] drizzle Caller allocated structure, or NULL to allocate one.
153
* @return On success, a pointer to the (possibly allocated) structure. On
154
* failure this will be NULL.
157
drizzle_st *drizzle_create(drizzle_st *drizzle);
160
* Clone a drizzle structure.
162
* @param[in] drizzle Caller allocated structure, or NULL to allocate one.
163
* @param[in] from Drizzle structure to use as a source to clone from.
164
* @return Same return as drizzle_create().
167
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from);
170
* Free a drizzle structure.
172
* @param[in] drizzle Drizzle structure previously initialized with
173
* drizzle_create() or drizzle_clone().
176
void drizzle_free(drizzle_st *drizzle);
179
* Return an error string for last error encountered.
181
* @param[in] drizzle Drizzle structure previously initialized with
182
* drizzle_create() or drizzle_clone().
183
* @return Pointer to static buffer in library that holds an error string.
186
const char *drizzle_error(const drizzle_st *drizzle);
189
* Value of errno in the case of a DRIZZLE_RETURN_ERRNO return value.
191
* @param[in] drizzle Drizzle structure previously initialized with
192
* drizzle_create() or drizzle_clone().
193
* @return An errno value as defined in your system errno.h file.
196
int drizzle_errno(const drizzle_st *drizzle);
199
* Get server defined error code for the last result read.
201
* @param[in] drizzle Drizzle structure previously initialized with
202
* drizzle_create() or drizzle_clone().
203
* @return An error code given back in the server response.
206
uint16_t drizzle_error_code(const drizzle_st *drizzle);
209
* Get SQL state code for the last result read.
211
* @param[in] drizzle Drizzle structure previously initialized with
212
* drizzle_create() or drizzle_clone().
213
* @return A SQLSTATE code given back in the server response.
216
const char *drizzle_sqlstate(const drizzle_st *drizzle);
219
* Get options for a drizzle structure.
221
* @param[in] drizzle Drizzle structure previously initialized with
222
* drizzle_create() or drizzle_clone().
223
* @return Options set for the drizzle structure.
226
int drizzle_options(const drizzle_st *drizzle);
229
* Set 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 set.
236
void drizzle_set_options(drizzle_st *drizzle, int options);
239
* Add 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 add.
246
void drizzle_add_options(drizzle_st *drizzle, int options);
249
* Remove options for a drizzle structure.
251
* @param[in] drizzle Drizzle structure previously initialized with
252
* drizzle_create() or drizzle_clone().
253
* @param[in] options Available options for drizzle structure to remove.
256
void drizzle_remove_options(drizzle_st *drizzle, drizzle_options_t options);
259
* Get application context pointer.
261
* @param[in] drizzle Drizzle structure previously initialized with
262
* drizzle_create() or drizzle_clone().
263
* @return Application context that was previously set, or NULL.
266
void *drizzle_context(const drizzle_st *drizzle);
269
* Set application context pointer.
271
* @param[in] drizzle Drizzle structure previously initialized with
272
* drizzle_create() or drizzle_clone().
273
* @param[in] context Application context to set.
276
void drizzle_set_context(drizzle_st *drizzle, void *context);
279
* Set function to call when the drizzle structure is being cleaned up so
280
* the application can clean up the context pointer.
282
* @param[in] drizzle Drizzle structure previously initialized with
283
* drizzle_create() or drizzle_clone().
284
* @param[in] function Function to call to clean up drizzle context.
287
void drizzle_set_context_free_fn(drizzle_st *drizzle,
288
drizzle_context_free_fn *function);
291
* Get current socket I/O activity timeout value.
293
* @param[in] drizzle Drizzle structure previously initialized with
294
* drizzle_create() or drizzle_clone().
295
* @return Timeout in milliseconds to wait for I/O activity. A negative value
296
* means an infinite timeout.
299
int drizzle_timeout(const drizzle_st *drizzle);
302
* Set socket I/O activity timeout for connections in a Drizzle structure.
304
* @param[in] drizzle Drizzle structure previously initialized with
305
* drizzle_create() or drizzle_clone().
306
* @param[in] timeout Milliseconds to wait for I/O activity. A negative value
307
* means an infinite timeout.
310
void drizzle_set_timeout(drizzle_st *drizzle, int timeout);
313
* Get current verbosity threshold for logging messages.
315
* @param[in] drizzle Drizzle structure previously initialized with
316
* drizzle_create() or drizzle_clone().
317
* @return Current verbosity threshold.
320
drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle);
323
* Set verbosity threshold for logging messages. If this is set above
324
* DRIZZLE_VERBOSE_NEVER and the drizzle_set_log_fn() callback is set to NULL,
325
* messages are printed to STDOUT.
327
* @param[in] drizzle Drizzle structure previously initialized with
328
* drizzle_create() or drizzle_clone().
329
* @param[in] verbose Verbosity threshold of what to log.
332
void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose);
335
* Set logging function for a drizzle structure. This function is only called
336
* for log messages that are above the verbosity threshold set with
337
* drizzle_set_verbose().
339
* @param[in] drizzle Drizzle structure previously initialized with
340
* drizzle_create() or drizzle_clone().
341
* @param[in] function Function to call when there is a logging message.
342
* @param[in] context Argument to pass into the callback function.
345
void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function,
349
* Set a custom I/O event watcher function for a drizzle structure. Used to
350
* integrate libdrizzle with a custom event loop. The callback will be invoked
351
* to register or deregister interest in events for a connection. When the
352
* events are triggered, drizzle_con_set_revents() should be called to
353
* indicate which events are ready. The event loop should stop waiting for
354
* these events, as libdrizzle will call the callback again if it is still
355
* interested. To resume processing, the libdrizzle function that returned
356
* DRIZZLE_RETURN_IO_WAIT should be called again. See drizzle_event_watch_fn().
358
* @param[in] drizzle Drizzle structure previously initialized with
359
* drizzle_create() or drizzle_clone().
360
* @param[in] function Function to call when there is an I/O event.
361
* @param[in] context Argument to pass into the callback function.
364
void drizzle_set_event_watch_fn(drizzle_st *drizzle,
365
drizzle_event_watch_fn *function,
369
* Initialize a connection structure. Always check the return value even if
370
* passing in a pre-allocated structure. Some other initialization may have
373
* @param[in] drizzle Drizzle structure previously initialized with
374
* drizzle_create() or drizzle_clone().
375
* @param[in] con Caller allocated structure, or NULL to allocate one.
376
* @return On success, a pointer to the (possibly allocated) structure. On
377
* failure this will be NULL.
380
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle, drizzle_con_st *con);
383
* Clone a connection structure.
385
* @param[in] drizzle Drizzle structure previously initialized with
386
* drizzle_create() or drizzle_clone().
387
* @param[in] con Caller allocated structure, or NULL to allocate one.
388
* @param[in] from Connection structure to use as a source to clone from.
389
* @return Same return as drizzle_con_create().
392
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con,
393
const drizzle_con_st *from);
396
* Free a connection structure.
398
* @param[in] con Connection structure previously initialized with
399
* drizzle_con_create(), drizzle_con_clone(), or related functions.
402
void drizzle_con_free(drizzle_con_st *con);
405
* Free all connections in a drizzle structure.
407
* @param[in] drizzle Drizzle structure previously initialized with
408
* drizzle_create() or drizzle_clone().
411
void drizzle_con_free_all(drizzle_st *drizzle);
414
* Wait for I/O on connections.
416
* @param[in] drizzle Drizzle structure previously initialized with
417
* drizzle_create() or drizzle_clone().
418
* @return Standard drizzle return value.
421
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle);
424
* Get next connection that is ready for I/O.
426
* @param[in] drizzle Drizzle structure previously initialized with
427
* drizzle_create() or drizzle_clone().
428
* @return Connection that is ready for I/O, or NULL if there are none.
431
drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle);
439
#endif /* __DRIZZLE_H */