qdb_stmt_decltypes()

Get 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 by qdb_stmt_init().
buf
A pointer to a buffer for storing the column types.
bufsize
The actual buffer size, in bytes.
required_size
The required buffer size, in bytes, for storing all declared column types. The function always fills in this field, even if you provide a sufficiently large buffer.

Library:

qdb

Description:

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.

Returns:

>=0
Success. The returned value is either the number of columns in the statement or the number of valid declared column types, depending on the arguments.
-1
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,
                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.

Classification:

QNX Neutrino

Safety:  
Interrupt handler No
Signal handler No
Thread Yes