Home » Developer & Programmer » Precompilers, OCI & OCCI » OCIDefineByPos && Retrieving a DATE column...
OCIDefineByPos && Retrieving a DATE column... [message #159971] Wed, 22 February 2006 08:27
Herode
Messages: 12
Registered: February 2006
Location: Isère (France, 38)
Junior Member
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 ????
Previous Topic: How to compile multiple Pro*C programs in single C++ file
Next Topic: OCIStmtExecute blocks on an update query
Goto Forum:
  


Current Time: Fri Mar 29 03:09:09 CDT 2024