⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 result.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        m_1stFetch = false;	m_CurrItem= 0;        return true;    }    STATUS s = dbnextrow(m_Cmd);    switch (s) {    case REG_ROW:    case NO_MORE_ROWS:        *m_ResStatus ^= 0x10;        break;    case FAIL:        throw CDB_ClientEx(eDB_Error, 270003, "CDBL_ComputeResult::Fetch",                           "error in fetching row");    case BUF_FULL:        throw CDB_ClientEx(eDB_Error, 270006, "CDBL_ComputeResult::Fetch",                           "buffer is full");    default:        break;    }    m_EOR = true;    m_CurrItem= -1;    return false;}int CDBL_ComputeResult::CurrentItemNo() const{    return m_CurrItem;}CDB_Object* CDBL_ComputeResult::GetItem(CDB_Object* item_buff){    if ((unsigned int) m_CurrItem >= m_NofCols) {        return 0;    }    CDB_Object* r = s_AltGetItem(m_Cmd, m_ComputeId, m_CurrItem + 1,                                 &m_ColFmt[m_CurrItem], item_buff);    ++m_CurrItem;    m_Offset = 0;    return r;}size_t CDBL_ComputeResult::ReadItem(void* buffer, size_t buffer_size,                                    bool* is_null){    if ((unsigned int) m_CurrItem >= m_NofCols) {        if (is_null)            *is_null = true;        return 0;    }    const BYTE* d_ptr = dbadata(m_Cmd, m_ComputeId, m_CurrItem + 1);    DBINT d_len = dbadlen(m_Cmd, m_ComputeId, m_CurrItem + 1);    if (d_ptr == 0 || d_len < 1) { // NULL value        ++m_CurrItem;        m_Offset = 0;        if (is_null)            *is_null = true;        return 0;    }    if (is_null)        *is_null = false;    if ((size_t) d_len - m_Offset < buffer_size)        buffer_size = (size_t) d_len - m_Offset;    memcpy(buffer, d_ptr + m_Offset, buffer_size);    m_Offset += buffer_size;    if (m_Offset >= (size_t) d_len) {        m_Offset = 0;        ++m_CurrItem;    }    return buffer_size;}I_ITDescriptor* CDBL_ComputeResult::GetImageOrTextDescriptor(){    return 0;}CDBL_ComputeResult::~CDBL_ComputeResult(){    if (m_ColFmt) {        delete[] m_ColFmt;        m_ColFmt = 0;    }    while (!m_EOR)        Fetch();}/////////////////////////////////////////////////////////////////////////////////  CTL_StatusResult:://CDBL_StatusResult::CDBL_StatusResult(DBPROCESS* cmd) :    m_Offset(0), m_1stFetch(true){    m_Val = dbretstatus(cmd);}EDB_ResType CDBL_StatusResult::ResultType() const{    return eDB_StatusResult;}unsigned int CDBL_StatusResult::NofItems() const{    return 1;}const char* CDBL_StatusResult::ItemName(unsigned int) const{    return 0;}size_t CDBL_StatusResult::ItemMaxSize(unsigned int) const{    return sizeof(DBINT);}EDB_Type CDBL_StatusResult::ItemDataType(unsigned int) const{    return eDB_Int;}bool CDBL_StatusResult::Fetch(){    if (m_1stFetch) {        m_1stFetch = false;        return true;    }    return false;}int CDBL_StatusResult::CurrentItemNo() const{    return m_1stFetch? -1 : 0;}CDB_Object* CDBL_StatusResult::GetItem(CDB_Object* item_buff){    if (!item_buff)        return new CDB_Int(m_Val);    if (item_buff->GetType() != eDB_Int) {        throw CDB_ClientEx(eDB_Error, 230020, "CDBL_StatusResult::GetItem",                           "wrong type of CDB_Object");    }    CDB_Int* i = (CDB_Int*) item_buff;    *i = m_Val;    return item_buff;}size_t CDBL_StatusResult::ReadItem(void* buffer, size_t buffer_size,                                   bool* is_null){    if (is_null)        *is_null = false;    if (sizeof(m_Val) <= m_Offset)        return 0;    size_t l = sizeof(int) - m_Offset;    char* p = (char*) &m_Val;    if (buffer_size > l)        buffer_size = l;    memcpy(buffer, p + m_Offset, buffer_size);    m_Offset += buffer_size;    return buffer_size;}I_ITDescriptor* CDBL_StatusResult::GetImageOrTextDescriptor(){    return 0;}bool CDBL_StatusResult::SkipItem(){    return false;}CDBL_StatusResult::~CDBL_StatusResult(){}/////////////////////////////////////////////////////////////////////////////////  CTL_CursorResult:://CDBL_CursorResult::CDBL_CursorResult(CDB_LangCmd* cmd) :    m_Cmd(cmd), m_Res(0){    try {        m_Cmd->Send();        while (m_Cmd->HasMoreResults()) {            m_Res = m_Cmd->Result();            if (m_Res && m_Res->ResultType() == eDB_RowResult) {                return;            }            if (m_Res) {                while (m_Res->Fetch())                    ;                delete m_Res;                m_Res = 0;            }        }    } catch (CDB_Exception& ) {        throw CDB_ClientEx(eDB_Error, 222010,                           "CDBL_CursorResult::CDBL_CursorResult",                           "failed to get the results");    }}EDB_ResType CDBL_CursorResult::ResultType() const{    return eDB_CursorResult;}unsigned int CDBL_CursorResult::NofItems() const{    return m_Res? m_Res->NofItems() : 0;}const char* CDBL_CursorResult::ItemName(unsigned int item_num) const{    return m_Res ? m_Res->ItemName(item_num) : 0;}size_t CDBL_CursorResult::ItemMaxSize(unsigned int item_num) const{    return m_Res ? m_Res->ItemMaxSize(item_num) : 0;}EDB_Type CDBL_CursorResult::ItemDataType(unsigned int item_num) const{    return m_Res ? m_Res->ItemDataType(item_num) : eDB_UnsupportedType;}bool CDBL_CursorResult::Fetch(){    if (!m_Res)        return false;    if (m_Res->Fetch())        return true;    try {        // finish this command        delete m_Res;        while (m_Cmd->HasMoreResults()) {            m_Res = m_Cmd->Result();            if (m_Res) {                while (m_Res->Fetch())                    ;                delete m_Res;                m_Res = 0;            }        }        // send the another "fetch cursor_name" command        m_Cmd->Send();        while (m_Cmd->HasMoreResults()) {            m_Res = m_Cmd->Result();            if (m_Res && m_Res->ResultType() == eDB_RowResult) {                return m_Res->Fetch();            }            if (m_Res) {                while (m_Res->Fetch())                    ;                delete m_Res;                m_Res = 0;            }        }    } catch (CDB_Exception& ) {        throw CDB_ClientEx(eDB_Error, 222011, "CDBL_CursorResult::Fetch",                           "Failed to fetch the results");    }    return false;}int CDBL_CursorResult::CurrentItemNo() const{    return m_Res ? m_Res->CurrentItemNo() : -1;}CDB_Object* CDBL_CursorResult::GetItem(CDB_Object* item_buff){    return m_Res ? m_Res->GetItem(item_buff) : 0;}size_t CDBL_CursorResult::ReadItem(void* buffer, size_t buffer_size,                                   bool* is_null){    if (m_Res) {        return m_Res->ReadItem(buffer, buffer_size, is_null);    }    if (is_null)        *is_null = true;    return 0;}I_ITDescriptor* CDBL_CursorResult::GetImageOrTextDescriptor(){    return m_Res ? m_Res->GetImageOrTextDescriptor() : 0;}bool CDBL_CursorResult::SkipItem(){    return m_Res ? m_Res->SkipItem() : false;}CDBL_CursorResult::~CDBL_CursorResult(){    if (m_Res)        delete m_Res;}/////////////////////////////////////////////////////////////////////////////////  CDBL_ITDescriptor:://CDBL_ITDescriptor::CDBL_ITDescriptor(DBPROCESS* dblink, int col_num){#ifdef MS_DBLIB_IN_USE /*Text,Image*/    const char* pColName = dbcolname(dblink,col_num);    if(pColName == NULL) {        throw CDB_ClientEx(eDB_Error, 280000,                           "CDBL_ITDescriptor::CDBL_ITDescriptor",                           "dbcolname() returns NULL");    }    // We have to use an offset in some undocumented structure    // (obtained with the help of a debugger).    // It may change in future MS dblib versions...    const char* pTabName = *(char**)(pColName+50);    m_ObjName += pTabName;    m_ObjName += ".";    m_ObjName += pColName;#else    DBCOLINFO* col_info = (DBCOLINFO*) dbcolname(dblink, col_num);    if (col_info == 0) {        throw CDB_ClientEx(eDB_Error, 280000,                           "CDBL_ITDescriptor::CDBL_ITDescriptor",                           "Can not get the DBCOLINFO*");    }    if (!x_MakeObjName(col_info)) {        m_ObjName = "";    }#endif    DBBINARY* p = dbtxptr(dblink, col_num);    if (p) {        memcpy(m_TxtPtr, p, DBTXPLEN);        m_TxtPtr_is_NULL = false;    } else        m_TxtPtr_is_NULL = true;    p = dbtxtimestamp(dblink, col_num);    if (p) {        memcpy(m_TimeStamp, p, DBTXTSLEN);        m_TimeStamp_is_NULL = false;    } else        m_TimeStamp_is_NULL = true;}CDBL_ITDescriptor::CDBL_ITDescriptor(DBPROCESS* dblink, const CDB_ITDescriptor& inp_d){    m_ObjName= inp_d.TableName();    m_ObjName+= ".";    m_ObjName+= inp_d.ColumnName();        DBBINARY* p = dbtxptr(dblink, 1);    if (p) {        memcpy(m_TxtPtr, p, DBTXPLEN);        m_TxtPtr_is_NULL = false;    } else        m_TxtPtr_is_NULL = true;    p = dbtxtimestamp(dblink, 1);    if (p) {        memcpy(m_TimeStamp, p, DBTXTSLEN);        m_TimeStamp_is_NULL = false;    } else        m_TimeStamp_is_NULL = true;}int CDBL_ITDescriptor::DescriptorType() const{#ifndef MS_DBLIB_IN_USE    return CDBL_ITDESCRIPTOR_TYPE_MAGNUM;#else	return CMSDBL_ITDESCRIPTOR_TYPE_MAGNUM;#endif}CDBL_ITDescriptor::~CDBL_ITDescriptor(){}#ifndef MS_DBLIB_IN_USEbool CDBL_ITDescriptor::x_MakeObjName(DBCOLINFO* col_info){    if (!col_info || !col_info->coltxobjname)        return false;    m_ObjName = col_info->coltxobjname;    // check if we do have ".colname" suffix already    char* p_dot = strrchr(col_info->coltxobjname, '.');    if (!p_dot || strcmp(p_dot + 1, col_info->colname) != 0) {        // we don't have a suffix. Add it now        m_ObjName += '.';        m_ObjName += col_info->colname;    }    return true;}#endifEND_NCBI_SCOPE/* * =========================================================================== * $Log: result.cpp,v $ * Revision 1000.2  2004/06/01 19:20:21  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.22 * * Revision 1.22  2004/05/18 18:30:36  gorelenk * PCH <ncbi_pch.hpp> moved to correct place . * * Revision 1.21  2004/05/17 21:12:41  gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.20  2004/04/08 19:05:51  gorelenk * Changed declalation of s_GenericGetItem (added 'const' to 'BYTE* d_ptr') * and fixed compilation errors on MSVC 7.10 . * * Revision 1.19  2003/04/29 21:16:21  soussov * new datatypes CDB_LongChar and CDB_LongBinary added * * Revision 1.18  2003/01/31 16:50:12  lavr * Remove unused variable "e" from catch() clause * * Revision 1.17  2003/01/06 16:40:49  soussov * sets m_CurrItem = -1 for all result types if no fetch was called * * Revision 1.16  2003/01/03 21:48:08  soussov * set m_CurrItem = -1 if fetch failes * * Revision 1.15  2002/07/18 14:59:10  soussov * fixes bug in blob result * * Revision 1.14  2002/07/02 16:05:50  soussov * splitting Sybase dblib and MS dblib * * Revision 1.13  2002/05/29 22:04:58  soussov * Makes BlobResult read ahead * * Revision 1.12  2002/03/26 15:37:52  soussov * new image/text operations added * * Revision 1.11  2002/02/06 22:27:54  soussov * fixes the arguments order in numeric assign * * Revision 1.10  2002/01/11 20:11:43  vakatov * Fixed CVS logs from prev. revision that messed up the compilation * * Revision 1.9  2002/01/10 22:05:52  sapojnik * MS-specific workarounds needed to use blobs via I_ITDescriptor * (see Text,Image) * * Revision 1.8  2002/01/08 18:10:18  sapojnik * Syabse to MSSQL name translations moved to interface_p.hpp * * Revision 1.7  2002/01/03 17:01:56  sapojnik * fixing CR/LF mixup * * Revision 1.6  2002/01/03 15:46:23  sapojnik * ported to MS SQL (about 12 'ifdef NCBI_OS_MSWIN' in 6 files) * * Revision 1.5  2001/11/06 17:59:58  lavr * Formatted uniformly as the rest of the library * * Revision 1.4  2001/10/24 16:38:42  lavr * Explicit casts (where necessary) to eliminate 64->32 bit compiler warnings * * Revision 1.3  2001/10/24 05:19:24  vakatov * Fixed return type for ItemMaxSize() * * Revision 1.2  2001/10/22 16:28:01  lavr * Default argument values removed * (mistakenly left while moving code from header files) * * Revision 1.1  2001/10/22 15:19:55  lavr * This is a major revamp (by Anton Lavrentiev, with help from Vladimir * Soussov and Denis Vakatov) of the DBAPI "driver" libs originally * written by Vladimir Soussov. The revamp follows the one of CTLib * driver, and it involved massive code shuffling and grooming, numerous * local API redesigns, adding comments and incorporating DBAPI to * the C++ Toolkit. * * =========================================================================== */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -