c++oracleoracle12cocci

Oracle OCCI setDataBuffer causing ORA-01406: fetched column value was truncated


I am using setDataBuffer to retrieve the rows returned from a stored procedure through a cursor as setPrefetchRowCount does not seem to work in this case. Using setDataBuffer works well when the buffer is greater than the total number of returned rows. In my case I tested the buffer can host 5000 rows and the number of returned rows are 538. When I reduce the buffer to a length of 100 (max_numrows=100 below) it works the first three calls to next(max_numrows) and gives exactly the same result as when the buffer is large. However, at the fourth call I get the exception ORA-01406: fetched column value was truncated. What is going on and how can I solve the problem?

static const size_t max_numrows=5000;
char var_buf[max_numrows][7];
char sym_buf[max_numrows][9];
rs->setDataBuffer(1,var_buf,oracle::occi::OCCI_SQLT_STR,sizeof(var_buf[0]),(ub2*)0);
rs->setDataBuffer(2,sym_buf,oracle::occi::OCCI_SQLT_STR,sizeof(sym_buf[0]),(ub2*)0);
sym.resize(var.size());
size_t fetch_count=0;
while(rs->next(max_numrows)==ResultSet::DATA_AVAILABLE)
{
    for(size_t i=0;i<rs->getNumArrayRows();++i)
    {
        var[fetch_count*max_numrows+i]=var_buf[i];
        sym[fetch_count*max_numrows+i]=sym_buf[i];
    }
    ++fetch_count;
}

Database

enter image description here


Solution

  • this is not about rows, but about column width. Some value fetched from database has more than 7 resp. 9 bytes.