Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> OCIDefineByPos and ratrieving a DATE column

OCIDefineByPos and ratrieving a DATE column

From: Herode <cbrun_at_geomapgis.com>
Date: 22 Feb 2006 06:31:59 -0800
Message-ID: <1140618719.645814.81990@z14g2000cwz.googlegroups.com>


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 :



CString sz = "select create_time from road.lprofelev";
// prepare...
// execute...
// then define for output :

void* colDesc = NULL;
selectList lst;
OCIDefine* defH;
void* buf;
ub4 nameLg;

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 :



st = ::OCIDefineByPos( m_pStmt, &defH, m_pErr, nCol + 1, lst.m_buf, lst.size, SQLT_STR, &lst.m_nullInd, &lst.size, NULL, OCI_DEFAULT );

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US