📄 cursor.cpp
字号:
int getYear(const string &col) const */void OCICPP::Cursor::getYear(int col,int &year) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_DAT) throw OraError("OCICPPLIB: Trying to get Month from non-date column",OCICPPERROR); if(row[col]->isNull(curRow)) year=0; else ((OraDate *)row[col])->getYear(year,curRow);}/*! If used for a Date-Column named \a colName, this function returns the year from this date. \sa void getYear(int ,int &) const int getYear(int col) const int getYear(const string &col) const */void OCICPP::Cursor::getYear(const std::string &colName,int &val) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getYear(iter->second,val); } else { throw OraError(CELL_NOT_EXISTS); }}/*! \fn int OCICPP::Cursor::getYear(int col) const If used for a Date-Column \a col, this function reads the \a year from this date. \sa void getYear(int ,int &) const void getYear(const std::string &,int &) const int getYear(const string &col) const *//*! \fn int OCICPP::Cursor::getYear(const string &col) const If used for a Date-Column named \a colName, this function returns the year from this date. \sa void getYear(int ,int &) const void getYear(const std::string &,int &) const int getYear(const string &col) const *//* lob-related functions --------------------------------------------- *//*! Initializes \a lob with the content of the character large object (CLOB) in column \a col from the cursor's current position. \sa void getCLOB(const std::string &,Lob &) const */void OCICPP::Cursor::getCLOB(int col,Lob &lob) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_CLOB) throw OraError("OCICPPLIB: Trying to get CLOB from non-CLOB column",OCICPPERROR); ((OraLob *)row[col])->getCLOB(lob,curRow); /* It's because lob's operation needs Server Context as one of it arguments */ }/*! Initializes \a lob with the content of the character large object (CLOB) from the column named \a colName from the cursor's current position. \sa void getCLOB(int,Lob &) const */void OCICPP::Cursor::getCLOB(const std::string &colName,Lob &lob) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { DEBUG(DLEV_DEBUG,"Fetching CLOB\n"); getCLOB(iter->second,lob); } else { throw OraError(CELL_NOT_EXISTS); }}/*! Initializes \a lob with the content of the binary large object (BLOB) in column \a col from the cursor's current position. \sa void getBLOB(const std::string &,Lob &) const */void OCICPP::Cursor::getBLOB(const int col,Lob &lob) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_BLOB) throw OraError("OCICPPLIB: Trying to get BLOB from non-BLOB column",OCICPPERROR); ((OraLob *)row[col])->getBLOB(lob,curRow);}/*! Initializes \a lob with the content of the binary large object (BLOB) from the column named \a colName from the cursor's current position. \sa void getBLOB(const int ,Lob &) const */void OCICPP::Cursor::getBLOB(const std::string &colName,Lob &lob) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getBLOB(iter->second,lob); } else { throw OraError(CELL_NOT_EXISTS); }}/*! Initializes \a bfile with the content of an external binary large object (BFILE) from the column \a col from the cursor's current position. \sa void getFILE(const std::string &,BFile &) const */void OCICPP::Cursor::getFILE(const int col,BFile &bfile) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_FILE) throw OraError("OCICPPLIB: Trying to get BFILE from non-BFILE column",OCICPPERROR); ((OraBFile *)row[col])->getFILE(bfile,curRow);}/*! Initializes \a bfile with the content of an external binary large object (BFILE) from the column named \a colName from the cursor's current position. \sa void getFILE(const int,BFile &) const */void OCICPP::Cursor::getFILE(const std::string &colName,BFile &bfile) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getFILE(iter->second,bfile); } else { throw OraError(CELL_NOT_EXISTS); }}
/* RowID related functions ----------------------------------------*/void OCICPP::Cursor::getRowID(int col,RowID &rowid) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_RDD) throw OraError("OCICPPLIB: Trying to get RowID from non-RowID column",OCICPPERROR); rowid.init((OraRowID *)row[col]); }void OCICPP::Cursor::getRowID(const std::string &colName,RowID &rowid) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getRowID(iter->second,rowid); } else { throw OraError(CELL_NOT_EXISTS); }}/* REFCURSOR related functions -------------------------------------*/
/*!
Retreives a cursor produced as a refernce from an SQL statement.
A brief example showing how the interaction with this cursor behaves:
\code
OCICPP::Connection con;
OCICPP::Cursor cur, cur2;
void printCursor( OCICPP::Cursor & );
...
con.prepare(
"SELECT id, CURSOR( select * FROM TABLE( my_tab.ANN ) ) "
"FROM test my_tab", cur );
cur.execute();
while ( cur.fetch() )
{
printCursor( cur );
cur.getCursor( 1, cur2 );
cur2.execute();
while ( cur2.fetch() )
{
printCursor( cur2 );
}
}
\endcode
\sa void getCursor( const std::string &,Cursor & ) const
*/
void OCICPP::Cursor::getCursor(int col,Cursor &cur) const { if(!canFetch || col<0 || col>=nCols) throw OraError(CELL_NOT_EXISTS); if(row[col]->getType()!=SQLT_RSET) throw OraError("OCICPPLIB: Trying to get CURSOR from non-CURSOR column",OCICPPERROR); cur.drop(); cur.init(envhp,svchp,errhp,1,NTABLE); cur.stmthp=((OraRefCur *)row[col])->getStmt(curRow);}/*!
Retreives a cursor produced as a refernce from an SQL statement.
\sa void getCursor( int, Cursor & ) const
*/
void OCICPP::Cursor::getCursor(const std::string &colName,Cursor &cur) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getCursor(iter->second,cur); } else { throw OraError(CELL_NOT_EXISTS); }}/* ----------------------*//*! Returns the number of columns within this cursor. */int OCICPP::Cursor::getNCols() const { if(haveResultSet) return (int)nCols; throw OraError("OCICPPLIB: Can't return number of columns: No result set for this cursor",OCICPPERROR);} /*! Retreive the name of column \a col into \a ret_col . */void OCICPP::Cursor::getColName(int col,std::string &ret_col) const { if(!haveResultSet) throw OraError("OCICPPLIB: Cannot get column name: No result set for this cursor",OCICPPERROR); if(col<0 || col>=nCols) throw OraError("OCICPPLIB: Cannot get column name: column number is out of range",OCICPPERROR); row[col]->getAttrName(ret_col);}/*! Retrieve the size for the cursor's column indexed by \a col . The interpretation of the returned figure depends on the type of the column. For example, if a column of type \c CHAR has a size of 32, it max store 32 characters. \sa int getColSize(const string &) const */int OCICPP::Cursor::getColSize(int col) const { if(!haveResultSet) throw OraError("OCICPPLIB: Cannot get column name: No result set for this cursor",OCICPPERROR); if(col<0 || col>=nCols) throw OraError("OCICPPLIB: Cannot get column name: column number is out of range",OCICPPERROR); return row[col]->getSize();}/*! Retrieve the size for the cursor's column named \a colName . \sa int getColSize(int col) const */int OCICPP::Cursor::getColSize(const std::string &colName) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { return getColSize(iter->second); } else { throw OraError(CELL_NOT_EXISTS); } }/*! Returns the internal Oracle type for column \a col . \a col is counted starting from 0 for the first column selected within the current cursor. The possible return value may be \c SQLT_CHR, \c SQLT_NUM, \c SQLT_DAT and many more. (please refer to the Oracle OCI documentation for additional details) \sa int getColType(const std::string &colName) const */int OCICPP::Cursor::getColType(int col) const { if(!haveResultSet) throw OraError("OCICPPLIB: Cannot get column type: No result set for this cursor",OCICPPERROR); if(col<0 || col>=nCols) throw OraError("OCICPPLIB: Cannot get column type: column number is out of range",OCICPPERROR); return row[col]->getType();}/*! Returns the internal Oracle type for column named \a colName . \a col is counted starting from 0 for the first column selected within the current cursor. The possible return value may be \c SQLT_CHR, \c SQLT_NUM, \c SQLT_DAT and many more (please refer to the Oracle OCI documentation for additional details) \sa int getColType(int col) const */int OCICPP::Cursor::getColType(const std::string &colName) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { return getColType(iter->second); } else { throw OraError(CELL_NOT_EXISTS); }}/*! Store the description of the type of the data stored in column index by \a col into \a typeName . \sa void getColTypeName(const string &,string &) const */void OCICPP::Cursor::getColTypeName(int col,std::string &typeName) const { if(!haveResultSet) throw OraError("OCICPPLIB: Cannot get column type name: No result set for this cursor",OCICPPERROR); if(col<0 || col>=nCols) throw OraError("OCICPPLIB: Cannot get column type name: column number is out of range",OCICPPERROR); row[col]->getTypeName(typeName);}/*! Store the description of the type of the data stored in column named \a colName into \a typeName . \sa void getColTypeName(int,string &) const */void OCICPP::Cursor::getColTypeName(const std::string &colName,std::string &typeName) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { getColTypeName(iter->second,typeName); } else { throw OraError(CELL_NOT_EXISTS); }}/*! Returns \c TRUE if the value stored within column \a col is not set in the row the cursor is currently pointing to (equivalent to a NULL-value in SQL-Terms) \sa bool isNull(const string &) const */bool OCICPP::Cursor::isNull(int col) const { if(!haveResultSet) throw OraError("OCICPPLIB: No result set for this cursor",OCICPPERROR); if(col<0 || col>=nCols) throw OraError("OCICPPLIB: Column number is out of range",OCICPPERROR); return row[col]->isNull(curRow); }/*! Returns \c TRUE if the value stored within column named \a colName is not set in the row the cursor is currently pointing to (equivalent to a NULL-value in SQL-Terms) \sa bool isNull(int) const */bool OCICPP::Cursor::isNull(const std::string &colName) const { map<string,int>::const_iterator iter=cols_map.find(colName); if(iter!=cols_map.end()) { return isNull(iter->second); } else { throw OraError(CELL_NOT_EXISTS); }}/* Set's text which will be returned on request of null cell default "" (empty text) */ /*! Set's text which will be returned on request of null cell default "" (empty text)*/ void OCICPP::Cursor::setNullText(const std::string &nulltext) { this->nulltext.assign(nulltext);}void OCICPP::Cursor::newCellByType(OraType **cell,OCIStmt *stmt,int col) { /* Get type */ ub2 colType; OCIParam *paramd; CHECKERR(errhp,OCIParamGet(stmthp,OCI_HTYPE_STMT,errhp,(dvoid **) ¶md,col+1)); CHECKERR(errhp,OCIAttrGet((dvoid *) paramd,OCI_DTYPE_PARAM,(dvoid *) &colType,(ub4 *) 0,(ub4) OCI_ATTR_DATA_TYPE,errhp)); switch(colType) { /* String variables */ case SQLT_CHR: case SQLT_LNG: case SQLT_AFC: *cell=new OraString(envhp,errhp,paramd,colType,prefetchRows); break; /* Raw & Long Raw */ case SQLT_BIN: case SQLT_LBI: *cell=new OraRaw(envhp,errhp,paramd,colType,prefetchRows); break; /* MLSLABEL */ case SQLT_LAB: *cell=new OraLabel(envhp,errhp,paramd,colType,prefetchRows); break; /* Numbers */ case SQLT_NUM: *cell=new OraNumber(envhp,errhp,paramd,colType,prefetchRows); break; /* ROWID */ case SQLT_RID: case SQLT_RDD: *cell=new OraRowID(envhp,errhp,paramd,colType,prefetchRows); break; /* Date */ case SQLT_DAT: *cell=new OraDate(envhp,errhp,paramd,colType,prefetchRows); break; case SQLT_CLOB: case SQLT_BLOB: *cell=new OraLob(envhp,errhp,paramd,svchp,colType,prefetchRows); break; case SQLT_FILE: *cell=new OraBFile(envhp,errhp,paramd,svchp,colType,prefetchRows); break; /* REF CURSORS (nested tables) */ case SQLT_RSET: *cell=new OraRefCur(envhp,errhp,paramd,colType,prefetchRows); break; case SQLT_NTY: case SQLT_REF: default: *cell=new OraDummy(envhp,errhp,paramd,colType,prefetchRows); break; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -