Retrieving LOB Data - ODBC Driver for Teradata - 16.20

ODBC Driver for Teradata® User Guide

prodname
ODBC Driver for Teradata
vrm_release
16.20
category
User Guide
featnum
B035-2526-108K

LOB data should be retrieved using SQLGetData to be able to retrieve and process LOB data in parts. The following code fragment illustrates that. Note the loop to handle 2 BLOB column.

SQLINTEGER   id;
SQLCHAR      image[IMAGEPART_LEN ];
SQLINTEGER   cbid = 0;
SQLUINTEGER  cbimage = 0;
SQLRETURN    retcode;

retcode = SQLExecDirect(hstmt, (SQLCHAR*)"select id, image from blobtable", SQL_NTS);

while (retcode == SQL_SUCCESS ) {
    retcode = SQLFetch(hstmt);
    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){

        /* Get data for column 1 */
        SQLGetData(hstmt, 1, SQL_C_ULONG, &id, 0, &cbid);

        /* Get data for column 2 */
        while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO )
        {
            retcode= SQLGetData(hstmt, 2, SQL_C_CHAR, image, IMAGEPART_LEN,&cbimage);
            switch (retcode)
            {
            case SQL_SUCCESS_WITH_INFO:
            case SQL_SUCCESS:
                processimage(id, image);
                break;
            case SQL_NO_DATA:
                break;
            case SQL_ERROR:
            default:
                processerror(retcode);
                break;
            }
        }
    }