Retrieve declared column types for a prepared statement
#include <qdb/qdb.h>
int qdb_stmt_decltypes(qdb_hdl_t *db,
int stmtid,
char **buf,
ssize_t bufsize,
ssize_t *required_size);
- db
- A pointer to the database handle.
- stmtid
- The prepared statement ID returned from qdb_stmt_init().
- buf
- Pointer to a string buffer of the size specified by bufsize. The pointer must point to the beginning of the buffer. The buffer is managed by the client application, not by QDB.
- bufsize
- The size of the buffer, in bytes. Set to 0 to have the necessary size returned in the required_size argument.
- required_size
- The size of buffer that is required to hold all of the results.
qdb
This function retrieves the declared column types for a prepared statement. The behavior of this function depends on how the arguments are set:
- If bufsize is 0 (zero) and buf is NULL, qdb_stmt_decltypes() returns the total number of columns, and populates the required_size argument.
- If a buffer is specified and bufsize is less than required_size, qdb_stmt_decltypes() returns only the number of valid declared column types.
- If a buffer is specified and bufsize is greater than or equal to required_size, qdb_stmt_decltypes() returns the total number of columns in the statement, and the declared column types are returned in the buffer.
- If a column is the result of an expression or subquery, an empty string is returned in the corresponding position in the buf argument.
When this function returns, the beginning of buf is an array of pointers to strings which are also stored in the buffer, as illustrated in the following example:
char **pp;
ssize_t required_size, bufsize = 0;
int cols, i;
if ((cols = qdb_stmt_decltypes(db, stmtid, NULL, 0, &required_size)) > 0) {
pp = malloc(required_size);
if (pp) {
bufsize = required_size;
cols = qdb_stmt_decltypes(db, stmtid, pp, bufsize, &required_size);
for (i=0; i<cols; i++)
printf("column %d: %s\n", i, pp[i]);
free(pp);
}
}
|
You can optimize the the use of qdb_stmt_decltypes() by providing a buffer that you estimate
should be large enough before calling qdb_stmt_decltypes() for the first time. On return, if bufsize is greater than or equal to required_size, all the data has been returned and you do not need to call this function again. This also allows re-use of a single, large enough buffer. |
- ≥ 0
- Depending on the arguments, either the number of columns in the statement, or the number of valid declared column types. See Description for more information.
- -1
- An error occurred (errno is set).
QNX Neutrino
Safety: | |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
qdb_statement(),
qdb_stmt_init()