Get the 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 );
qdb
This function gets the declared column types for the prepared statement referred to by stmtid. The behavior of this function depends on the argument settings:
When this function returns, the beginning of buf is an array of pointers to strings, which are also stored in the buffer. These buffer strings contain the individual declared column types. Note that if a column is the result of an expression or subquery, an empty string is written in the corresponding buffer position.
You must allocate (and manage) the memory in buf. If you need to know the buffer size required to store the results, call this function with bufsize set to 0. The function will write the necessary number of bytes in required_size. You can then use this value to allocate the required amount of memory and call the function again, passing in a pointer to the newly allocated buffer.
The following code sample demonstrates how you can call qdb_stmt_decltypes() once to determine the required buffer size and again to retrieve the declared column types:
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 use of qdb_stmt_decltypes() by providing a buffer that you estimate is large enough before you call this function for the first time. On return, if bufsize is greater than or equal to required_size, then all the data has been returned and you don't need to call the function again. This also lets you re-use a single, sufficiently large buffer.
QNX Neutrino
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |