Finding the actual data size with OCI

From: Massis Isagholian <massis_at_socal.rr.com>
Date: Mon, 8 Oct 2001 18:03:50 -0700
Message-ID: <Q4sw7.1$Xb2.20201_at_nnrp2.sbc.net>



I'm trying to convert an application that uses Oracle 7 OCI to Oracle 8 OCI. I have 2 questions.

In Oracle 7 OCI, I used the odescr() function to query the attributes of my single row select-list. I used odescr() to query column name, data type, column size, etc. I'm now trying to do the same with Oracle 8 OCI.

Q1) I'm using OCIParamGet(), & OCIAttrGet() but I'm unable to retrieve the column name (OCI_ATTR_NAME) attribute. Is there something wrong the sample code below?

Q2) Prior executing a fetch statement, I need to allocate just enough memory for the returned data. What mechanism can you use to determine the actual size of each column that will be returned by the next fetch statement?

Thanks in advance for your help.
 Massis

  • sample code

 for (i = 1; i <= nParamCnt; i++)
 {
  if (OCIParamGet ((dvoid *) phStmt, OCI_HTYPE_STMT, phErr,    (dvoid **) &phStmtParam, i))
  {
   ErrHandler((dvoid *) phErr, OCI_HTYPE_ERROR);    return OCI_ERROR;
  }

  nBufSize = sizeof(szColName);

  if (OCIAttrGet ((dvoid *) phStmtParam,

      (ub4) OCI_DTYPE_PARAM,
      (dvoid *) txtColName,
      (ub4 *) &nBufSize,
      (ub4) OCI_ATTR_NAME,
      phErr))

   ErrHandler((dvoid *) phErr, OCI_HTYPE_ERROR);

  txtColName[nBufSize] = 0;

  if (OCIAttrGet ((dvoid *) phStmtParam, (ub4) OCI_DTYPE_PARAM,

(ub2 *) &nDataType, (ub4 *) 0,
(ub4) OCI_ATTR_DATA_TYPE, phErr))
ErrHandler((dvoid *) phErr, OCI_HTYPE_ERROR); if (OCIAttrGet ((dvoid *) phStmtParam, (ub4) OCI_DTYPE_PARAM,
(ub2 *) &nDataSize, (ub4 *) 0,
(ub4) OCI_ATTR_DATA_SIZE, phErr))

   ErrHandler((dvoid *) phErr, OCI_HTYPE_ERROR);

  printf("colName=%s, size=%d, type=%d\n",    txtColName, nDataSize, nDataType);
 } Received on Tue Oct 09 2001 - 03:03:50 CEST

Original text of this message