17.20 - Retrieving LOB Data - ODBC Driver for Teradata

ODBC Driver for Teradata® User Guide

Product
ODBC Driver for Teradata
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2022-06-21
dita:mapPath
uqj1639470627591.ditamap
dita:ditavalPath
nkw1500504256726.ditaval

LOB data should be retrieved using SQLGetData 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;
            }
        }
    }