1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
/* Overview of what this is and does:
18
* http://www.apache.org/~niq/dbd.html
21
#ifndef APR_DBD_INTERNAL_H
22
#define APR_DBD_INTERNAL_H
32
struct apr_dbd_driver_t {
36
/** init: allow driver to perform once-only initialisation.
37
* Called once only. May be NULL
39
void (*init)(apr_pool_t *pool);
41
/** native_handle: return the native database handle of the underlying db
43
* @param handle - apr_dbd handle
44
* @return - native handle
46
void *(*native_handle)(apr_dbd_t *handle);
48
/** open: obtain a database connection from the server rec.
49
* Must be explicitly closed when you're finished with it.
50
* WARNING: only use this when you need a connection with
51
* a lifetime other than a request
53
* @param pool - a pool to use for error messages (if any).
54
* @param s - server rec managing the underlying connection/pool.
55
* @return database handle, or NULL on error.
57
apr_dbd_t *(*open)(apr_pool_t *pool, const char *params);
59
/** check_conn: check status of a database connection
61
* @param pool - a pool to use for error messages (if any).
62
* @param handle - the connection to check
63
* @return APR_SUCCESS or error
65
apr_status_t (*check_conn)(apr_pool_t *pool, apr_dbd_t *handle);
67
/** close: close/release a connection obtained from open()
69
* @param handle - the connection to release
70
* @return APR_SUCCESS or error
72
apr_status_t (*close)(apr_dbd_t *handle);
74
/** set_dbname: select database name. May be a no-op if not supported.
76
* @param pool - working pool
77
* @param handle - the connection
78
* @param name - the database to select
79
* @return 0 for success or error code
81
int (*set_dbname)(apr_pool_t* pool, apr_dbd_t *handle, const char *name);
83
/** transaction: start a transaction. May be a no-op.
85
* @param pool - a pool to use for error messages (if any).
86
* @param handle - the connection
87
* @param transaction - ptr to a transaction. May be null on entry
88
* @return 0 for success or error code
90
int (*start_transaction)(apr_pool_t *pool, apr_dbd_t *handle,
91
apr_dbd_transaction_t **trans);
93
/** end_transaction: end a transaction
94
* (commit on success, rollback on error).
97
* @param transaction - the transaction.
98
* @return 0 for success or error code
100
int (*end_transaction)(apr_dbd_transaction_t *trans);
102
/** query: execute an SQL query that doesn't return a result set
104
* @param handle - the connection
105
* @param nrows - number of rows affected.
106
* @param statement - the SQL statement to execute
107
* @return 0 for success or error code
109
int (*query)(apr_dbd_t *handle, int *nrows, const char *statement);
111
/** select: execute an SQL query that returns a result set
113
* @param pool - pool to allocate the result set
114
* @param handle - the connection
115
* @param res - pointer to result set pointer. May point to NULL on entry
116
* @param statement - the SQL statement to execute
117
* @param random - 1 to support random access to results (seek any row);
118
* 0 to support only looping through results in order
119
* (async access - faster)
120
* @return 0 for success or error code
122
int (*select)(apr_pool_t *pool, apr_dbd_t *handle, apr_dbd_results_t **res,
123
const char *statement, int random);
125
/** num_cols: get the number of columns in a results set
127
* @param res - result set.
128
* @return number of columns
130
int (*num_cols)(apr_dbd_results_t *res);
132
/** num_tuples: get the number of rows in a results set
133
* of a synchronous select
135
* @param res - result set.
136
* @return number of rows, or -1 if the results are asynchronous
138
int (*num_tuples)(apr_dbd_results_t *res);
140
/** get_row: get a row from a result set
142
* @param pool - pool to allocate the row
143
* @param res - result set pointer
144
* @param row - pointer to row pointer. May point to NULL on entry
145
* @param rownum - row number, or -1 for "next row". Ignored if random
146
* access is not supported.
147
* @return 0 for success, -1 for rownum out of range or data finished
149
int (*get_row)(apr_pool_t *pool, apr_dbd_results_t *res,
150
apr_dbd_row_t **row, int rownum);
152
/** get_entry: get an entry from a row
154
* @param row - row pointer
155
* @param col - entry number
156
* @param val - entry to fill
157
* @return 0 for success, -1 for no data, +1 for general error
159
const char* (*get_entry)(const apr_dbd_row_t *row, int col);
161
/** error: get current error message (if any)
163
* @param handle - the connection
164
* @param errnum - error code from operation that returned an error
165
* @return the database current error message, or message for errnum
166
* (implementation-dependent whether errnum is ignored)
168
const char *(*error)(apr_dbd_t *handle, int errnum);
170
/** escape: escape a string so it is safe for use in query/select
172
* @param pool - pool to alloc the result from
173
* @param string - the string to escape
174
* @param handle - the connection
175
* @return the escaped, safe string
177
const char *(*escape)(apr_pool_t *pool, const char *string,
180
/** prepare: prepare a statement
182
* @param pool - pool to alloc the result from
183
* @param handle - the connection
184
* @param query - the SQL query
185
* @param label - A label for the prepared statement.
186
* use NULL for temporary prepared statements
187
* (eg within a Request in httpd)
188
* @param statement - statement to prepare. May point to null on entry.
189
* @return 0 for success or error code
191
int (*prepare)(apr_pool_t *pool, apr_dbd_t *handle, const char *query,
192
const char *label, apr_dbd_prepared_t **statement);
194
/** pvquery: query using a prepared statement + args
196
* @param pool - working pool
197
* @param handle - the connection
198
* @param nrows - number of rows affected.
199
* @param statement - the prepared statement to execute
200
* @param args - args to prepared statement
201
* @return 0 for success or error code
203
int (*pvquery)(apr_pool_t *pool, apr_dbd_t *handle, int *nrows,
204
apr_dbd_prepared_t *statement, va_list args);
206
/** pvselect: select using a prepared statement + args
208
* @param pool - working pool
209
* @param handle - the connection
210
* @param res - pointer to query results. May point to NULL on entry
211
* @param statement - the prepared statement to execute
212
* @param random - Whether to support random-access to results
213
* @param args - args to prepared statement
214
* @return 0 for success or error code
216
int (*pvselect)(apr_pool_t *pool, apr_dbd_t *handle,
217
apr_dbd_results_t **res,
218
apr_dbd_prepared_t *statement, int random, va_list args);
220
/** pquery: query using a prepared statement + args
222
* @param pool - working pool
223
* @param handle - the connection
224
* @param nrows - number of rows affected.
225
* @param statement - the prepared statement to execute
226
* @param nargs - number of args to prepared statement
227
* @param args - args to prepared statement
228
* @return 0 for success or error code
230
int (*pquery)(apr_pool_t *pool, apr_dbd_t *handle, int *nrows,
231
apr_dbd_prepared_t *statement, int nargs,
234
/** pselect: select using a prepared statement + args
236
* @param pool - working pool
237
* @param handle - the connection
238
* @param res - pointer to query results. May point to NULL on entry
239
* @param statement - the prepared statement to execute
240
* @param random - Whether to support random-access to results
241
* @param nargs - number of args to prepared statement
242
* @param args - args to prepared statement
243
* @return 0 for success or error code
245
int (*pselect)(apr_pool_t *pool, apr_dbd_t *handle,
246
apr_dbd_results_t **res, apr_dbd_prepared_t *statement,
247
int random, int nargs, const char **args);