~drizzle-trunk/drizzle/development

1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
1971.2.1 by kalebral at gmail
update files that did not have license or had incorrect license structure
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are
9
 * met:
10
 *
11
 *     * Redistributions of source code must retain the above copyright
12
 * notice, this list of conditions and the following disclaimer.
13
 *
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
17
 * distribution.
18
 *
19
 *     * The names of its contributors may not be used to endorse or
20
 * promote products derived from this software without specific prior
21
 * written permission.
22
 *
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.
34
 *
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
35
 */
36
37
/**
38
 * @file
39
 * @brief Query Declarations
40
 */
41
42
#ifndef __DRIZZLE_QUERY_H
43
#define __DRIZZLE_QUERY_H
44
45
#ifdef __cplusplus
46
extern "C" {
47
#endif
48
49
/**
50
 * @addtogroup drizzle_query Query Declarations
51
 *
52
 * @ingroup drizzle_client_interface
53
 * These functions are used to issue queries on a connection. Single queries are
54
 * made using the drizzle_query function, or you can queue multiple queries and
55
 * run them concurrently using the other query functions.
56
 * @{
57
 */
58
59
/**
60
 * Send query to server. A \ref drizzle_result_st will be created for the
61
 * results.
62
 *
63
 * @param[in] con connection to use to send the query.
64
 * @param[in,out] result pointer to an unused structure that will be used for
65
 *                       the results, or NULL to allocate a new structure.
66
 * @param[in] query query string to send.
67
 * @param[in] size length of the query string in bytes.
68
 * @param[out] ret_ptr pointer to the result code.
69
 * @return result, a pointer to the newly allocated result structure, or NULL
70
 *         if the allocation failed.
71
 */
72
DRIZZLE_API
73
drizzle_result_st *drizzle_query(drizzle_con_st *con, drizzle_result_st *result,
74
                                 const char *query, size_t size,
75
                                 drizzle_return_t *ret_ptr);
76
77
/**
78
 * Send query to server, using strlen to get the size of query buffer..
79
 */
80
DRIZZLE_API
81
drizzle_result_st *drizzle_query_str(drizzle_con_st *con,
82
                                     drizzle_result_st *result,
83
                                     const char *query,
84
                                     drizzle_return_t *ret_ptr);
85
86
/**
87
 * Send query incrementally.
88
 */
89
DRIZZLE_API
90
drizzle_result_st *drizzle_query_inc(drizzle_con_st *con,
91
                                     drizzle_result_st *result,
92
                                     const char *query, size_t size,
93
                                     size_t total, drizzle_return_t *ret_ptr);
94
95
/**
96
 * Add a query to be run concurrently.
97
 */
98
DRIZZLE_API
99
drizzle_query_st *drizzle_query_add(drizzle_st *drizzle,
100
                                    drizzle_query_st *query,
101
                                    drizzle_con_st *con,
102
                                    drizzle_result_st *result,
103
                                    const char *query_string, size_t size,
104
                                    drizzle_query_options_t options,
105
                                    void *context);
106
107
/**
108
 * Initialize a query structure.
109
 */
110
DRIZZLE_API
111
drizzle_query_st *drizzle_query_create(drizzle_st *drizzle,
112
                                       drizzle_query_st *query);
113
114
/**
115
 * Free a query structure.
116
 */
117
DRIZZLE_API
118
void drizzle_query_free(drizzle_query_st *query);
119
120
/**
121
 * Free a query structure.
122
 */
123
DRIZZLE_API
124
void drizzle_query_free_all(drizzle_st *drizzle);
125
126
/**
127
 * Get connection struct for a query.
128
 */
129
DRIZZLE_API
130
drizzle_con_st *drizzle_query_con(drizzle_query_st *query);
131
132
/**
133
 * Set connection struct for a query.
134
 */
135
DRIZZLE_API
136
void drizzle_query_set_con(drizzle_query_st *query, drizzle_con_st *con);
137
138
/**
139
 * Get result struct for a query.
140
 */
141
DRIZZLE_API
142
drizzle_result_st *drizzle_query_result(drizzle_query_st *query);
143
144
/**
145
 * Set result struct for a query.
146
 */
147
DRIZZLE_API
148
void drizzle_query_set_result(drizzle_query_st *query,
149
                              drizzle_result_st *result);
150
151
/**
152
 * Get query string for a query.
153
 */
154
DRIZZLE_API
155
char *drizzle_query_string(drizzle_query_st *query, size_t *size);
156
157
/**
158
 * Set query string for a query.
159
 */
160
DRIZZLE_API
161
void drizzle_query_set_string(drizzle_query_st *query, const char *string,
162
                              size_t size);
163
164
/**
165
 * Get options for a query. 
166
 */
167
DRIZZLE_API
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
168
drizzle_query_options_t drizzle_query_options(drizzle_query_st *query);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
169
170
/**
171
 * Set options for a query.
172
 */
173
DRIZZLE_API
174
void drizzle_query_set_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
175
                               drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
176
177
/**
178
 * Add options for a query.
179
 */
180
DRIZZLE_API
181
void drizzle_query_add_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
182
                               drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
183
184
/**
185
 * Remove options for a query.
186
 */
187
DRIZZLE_API
188
void drizzle_query_remove_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
189
                                  drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
190
191
/**
192
 * Get application context for a query.
193
 */
194
DRIZZLE_API
195
void *drizzle_query_context(drizzle_query_st *query);
196
197
/**
198
 * Set application context for a query.
199
 */
200
DRIZZLE_API
201
void drizzle_query_set_context(drizzle_query_st *query, void *context);
202
203
/**
204
 * Set callback function when the context pointer should be freed.
205
 */
206
DRIZZLE_API
207
void drizzle_query_set_context_free_fn(drizzle_query_st *query,
208
                                       drizzle_query_context_free_fn *function);
209
210
/**
211
 * Run queries concurrently, returning when one is complete.
212
 */
213
DRIZZLE_API
214
drizzle_query_st *drizzle_query_run(drizzle_st *drizzle,
215
                                    drizzle_return_t *ret_ptr);
216
217
/**
218
 * Run queries until they are all complete. Returns \ref DRIZZLE_RETURN_OK if
219
 * all queries complete, even if some return errors. This returns immediately
220
 * if some other error occurs, leaving some queries unprocessed. You must call
221
 * drizzle_result_error_code() to check if each query succeeded.
222
 */
223
DRIZZLE_API
224
drizzle_return_t drizzle_query_run_all(drizzle_st *drizzle);
225
226
/*
227
 * Escape a string or encode a string in hexadecimal. The return value is the
228
 * size of the output string in to.
229
 */
230
DRIZZLE_API
231
size_t drizzle_escape_string(char *to, const char *from, size_t from_size);
232
DRIZZLE_API
2235.1.2 by Andrew Hutchings
Add drizzle_safe_escape_string() function
233
ssize_t drizzle_safe_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size);
234
DRIZZLE_API
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
235
size_t drizzle_hex_string(char *to, const char *from, size_t from_size);
236
DRIZZLE_API
237
void drizzle_mysql_password_hash(char *to, const char *from, size_t from_size);
238
239
/** @} */
240
241
#ifdef __cplusplus
242
}
243
#endif
244
245
#endif /* __DRIZZLE_QUERY_H */