~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
2464.1.2 by Brian Aker
Fix compiling issues for 1.0, and cleanup header files.
42
#pragma once
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
43
44
#ifdef __cplusplus
45
extern "C" {
46
#endif
47
48
/**
49
 * @addtogroup drizzle_query Query Declarations
50
 *
51
 * @ingroup drizzle_client_interface
52
 * These functions are used to issue queries on a connection. Single queries are
53
 * made using the drizzle_query function, or you can queue multiple queries and
54
 * run them concurrently using the other query functions.
55
 * @{
56
 */
57
58
/**
59
 * Send query to server. A \ref drizzle_result_st will be created for the
60
 * results.
61
 *
62
 * @param[in] con connection to use to send the query.
63
 * @param[in,out] result pointer to an unused structure that will be used for
64
 *                       the results, or NULL to allocate a new structure.
65
 * @param[in] query query string to send.
66
 * @param[in] size length of the query string in bytes.
67
 * @param[out] ret_ptr pointer to the result code.
68
 * @return result, a pointer to the newly allocated result structure, or NULL
69
 *         if the allocation failed.
70
 */
71
DRIZZLE_API
72
drizzle_result_st *drizzle_query(drizzle_con_st *con, drizzle_result_st *result,
73
                                 const char *query, size_t size,
74
                                 drizzle_return_t *ret_ptr);
75
76
/**
77
 * Send query to server, using strlen to get the size of query buffer..
78
 */
79
DRIZZLE_API
80
drizzle_result_st *drizzle_query_str(drizzle_con_st *con,
81
                                     drizzle_result_st *result,
82
                                     const char *query,
83
                                     drizzle_return_t *ret_ptr);
84
85
/**
86
 * Send query incrementally.
87
 */
88
DRIZZLE_API
89
drizzle_result_st *drizzle_query_inc(drizzle_con_st *con,
90
                                     drizzle_result_st *result,
91
                                     const char *query, size_t size,
92
                                     size_t total, drizzle_return_t *ret_ptr);
93
94
/**
95
 * Add a query to be run concurrently.
96
 */
97
DRIZZLE_API
98
drizzle_query_st *drizzle_query_add(drizzle_st *drizzle,
99
                                    drizzle_query_st *query,
100
                                    drizzle_con_st *con,
101
                                    drizzle_result_st *result,
102
                                    const char *query_string, size_t size,
103
                                    drizzle_query_options_t options,
104
                                    void *context);
105
106
/**
107
 * Initialize a query structure.
108
 */
109
DRIZZLE_API
110
drizzle_query_st *drizzle_query_create(drizzle_st *drizzle,
111
                                       drizzle_query_st *query);
112
113
/**
114
 * Free a query structure.
115
 */
116
DRIZZLE_API
117
void drizzle_query_free(drizzle_query_st *query);
118
119
/**
120
 * Free a query structure.
121
 */
122
DRIZZLE_API
123
void drizzle_query_free_all(drizzle_st *drizzle);
124
125
/**
126
 * Get connection struct for a query.
127
 */
128
DRIZZLE_API
129
drizzle_con_st *drizzle_query_con(drizzle_query_st *query);
130
131
/**
132
 * Set connection struct for a query.
133
 */
134
DRIZZLE_API
135
void drizzle_query_set_con(drizzle_query_st *query, drizzle_con_st *con);
136
137
/**
138
 * Get result struct for a query.
139
 */
140
DRIZZLE_API
141
drizzle_result_st *drizzle_query_result(drizzle_query_st *query);
142
143
/**
144
 * Set result struct for a query.
145
 */
146
DRIZZLE_API
147
void drizzle_query_set_result(drizzle_query_st *query,
148
                              drizzle_result_st *result);
149
150
/**
151
 * Get query string for a query.
152
 */
153
DRIZZLE_API
154
char *drizzle_query_string(drizzle_query_st *query, size_t *size);
155
156
/**
157
 * Set query string for a query.
158
 */
159
DRIZZLE_API
160
void drizzle_query_set_string(drizzle_query_st *query, const char *string,
161
                              size_t size);
162
163
/**
164
 * Get options for a query. 
165
 */
166
DRIZZLE_API
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
167
drizzle_query_options_t drizzle_query_options(drizzle_query_st *query);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
168
169
/**
170
 * Set options for a query.
171
 */
172
DRIZZLE_API
173
void drizzle_query_set_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
174
                               drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
175
176
/**
177
 * Add options for a query.
178
 */
179
DRIZZLE_API
180
void drizzle_query_add_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
181
                               drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
182
183
/**
184
 * Remove options for a query.
185
 */
186
DRIZZLE_API
187
void drizzle_query_remove_options(drizzle_query_st *query,
1992.6.7 by Monty Taylor
Revert -Wc++-compat change.
188
                                  drizzle_query_options_t options);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
189
190
/**
191
 * Get application context for a query.
192
 */
193
DRIZZLE_API
194
void *drizzle_query_context(drizzle_query_st *query);
195
196
/**
197
 * Set application context for a query.
198
 */
199
DRIZZLE_API
200
void drizzle_query_set_context(drizzle_query_st *query, void *context);
201
202
/**
203
 * Set callback function when the context pointer should be freed.
204
 */
205
DRIZZLE_API
206
void drizzle_query_set_context_free_fn(drizzle_query_st *query,
207
                                       drizzle_query_context_free_fn *function);
208
209
/**
210
 * Run queries concurrently, returning when one is complete.
211
 */
212
DRIZZLE_API
213
drizzle_query_st *drizzle_query_run(drizzle_st *drizzle,
214
                                    drizzle_return_t *ret_ptr);
215
216
/**
217
 * Run queries until they are all complete. Returns \ref DRIZZLE_RETURN_OK if
218
 * all queries complete, even if some return errors. This returns immediately
219
 * if some other error occurs, leaving some queries unprocessed. You must call
220
 * drizzle_result_error_code() to check if each query succeeded.
221
 */
222
DRIZZLE_API
223
drizzle_return_t drizzle_query_run_all(drizzle_st *drizzle);
224
225
/*
226
 * Escape a string or encode a string in hexadecimal. The return value is the
227
 * size of the output string in to.
228
 */
229
DRIZZLE_API
2472.1.6 by Brian Aker
Break up unit tests
230
size_t drizzle_escape_string(char *to, const char *from, const size_t from_size);
231
232
DRIZZLE_API
233
ssize_t drizzle_safe_escape_string(char *to, const size_t max_to_size, const char *from, const size_t from_size);
234
235
DRIZZLE_API
236
size_t drizzle_hex_string(char *to, const char *from, const size_t from_size);
237
238
DRIZZLE_API
239
void drizzle_mysql_password_hash(char *to, const char *from, const size_t from_size);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
240
241
/** @} */
242
243
#ifdef __cplusplus
244
}
245
#endif