Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> OCIDefineByPos and ratrieving a DATE column
Gentlemen,
Here is another bug (in my code, I mean...) I can't get rid off. I try to read a DATA column with the following code :
int nCol = 0;
st = ::OCIParamGet( m_pStmt, OCI_HTYPE_STMT, m_pErr, &colDesc, nCol + 1
);
st = ::OCIAttrGet( colDesc, OCI_DTYPE_PARAM, &lst.size, 0,
OCI_ATTR_DATA_SIZE, m_pErr );
st = ::OCIAttrGet( colDesc, OCI_DTYPE_PARAM, &lst.type, 0,
OCI_ATTR_DATA_TYPE, m_pErr );
st = ::OCIAttrGet( colDesc, OCI_DTYPE_PARAM, &buf, &nameLg,
OCI_ATTR_NAME, m_pErr );
lst.colName.Format( "%.*s", nameLg, buf );
lst.size = 51;
// buffer for the DATE. Orale doc says that SQLT_DAT is char[ 7 ] but
that's obviously a joke...
lst.m_buf = new char[ lst.size ];
st = ::OCIDefineByPos( m_pStmt, &defH, m_pErr, nCol + 1,
lst.m_buf, lst.size, SQLT_STR, &lst.m_nullInd, 0, NULL,
OCI_DEFAULT );
//and fetch...
st = ::OCIStmtFetch2( m_pStmt, m_pErr, 1, OCI_FETCH_NEXT, 1,
OCI_DEFAULT );
cout << lst.colName.GetBuffer( 0 ) << " = " << (char*) lst.m_buf <<
endl;
The output gives me the YY/MM/DD date, but looses the timestamp (hours, minutes & so on).
NB : if the defining is made with :
the attribut lst.size ends with 8 inside (and not the initial 50).
What did I miss ???? Received on Wed Feb 22 2006 - 08:31:59 CST