qdb_stmt_decltypes()

Retrieve declared column types for a prepared statement

Synopsis:

#include <qdb/qdb.h>

int qdb_stmt_decltypes(qdb_hdl_t *db, 
                       int stmtid, 
                       char **buf, 
                       ssize_t bufsize, 
                       ssize_t *required_size);

Arguments:

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.

Library:

qdb

Description:

This function retrieves the declared column types for a prepared statement. The behavior of this function depends on how the arguments are set:

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);
   }
}

Note: 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.

Returns:

≥ 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).

Classification:

QNX Neutrino

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

qdb_statement(), qdb_stmt_init()