qdb_stmt_decltypes()

Retrieve the 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
A 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.

Returns:

Return values greater than zero indicate either the number of columns in the statement or the number of valid declared column types, depending on the arguments. See Description for more information.

The function returns -1 when an error occurred (errno is set).

Examples:

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,
                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 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, then 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.

Classification:

QNX Neutrino

Safety:  
Interrupt handler No
Signal handler No
Thread Yes