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

📄 connection.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    char buff[1800]; // maximal page size    if (size <= sizeof(buff)) { // we could write a blob in one chunk        size_t s = stream.Read(buff, sizeof(buff));        if (dbwritetext(m_Link, (char*) desc.m_ObjName.c_str(),                        desc.m_TxtPtr_is_NULL ? 0 : desc.m_TxtPtr,                        DBTXPLEN,                        desc.m_TimeStamp_is_NULL ? 0 : desc.m_TimeStamp,                        log_it ? TRUE : FALSE, (DBINT) s, (BYTE*) buff)            != SUCCEED) {            throw CDB_ClientEx(eDB_Error, 210030, "CDBL_Connection::SendData",                               "dbwritetext failed");        }        return true;    }    // write it in chunks    if (dbwritetext(m_Link, (char*) desc.m_ObjName.c_str(),                    desc.m_TxtPtr_is_NULL ? 0 : desc.m_TxtPtr,                    DBTXPLEN,                    desc.m_TimeStamp_is_NULL ? 0 : desc.m_TimeStamp,                    log_it ? TRUE : FALSE, (DBINT) size, 0) != SUCCEED ||        dbsqlok(m_Link) != SUCCEED ||        //        dbresults(m_Link) == FAIL) {        x_Results(m_Link) == FAIL) {        throw CDB_ClientEx(eDB_Error, 210031, "CDBL_Connection::SendData",                           "dbwritetext/dbsqlok/dbresults failed");    }    while (size > 0) {        size_t s = stream.Read(buff, sizeof(buff));        if (s < 1) {            dbcancel(m_Link);            throw CDB_ClientEx(eDB_Fatal, 210032, "CDBL_Connection::SendData",                               "Text/Image data corrupted");        }        if (dbmoretext(m_Link, (DBINT) s, (BYTE*) buff) != SUCCEED) {            dbcancel(m_Link);            throw CDB_ClientEx(eDB_Error, 210033, "CDBL_Connection::SendData",                               "dbmoretext failed");        }        size -= s;    }    //    if (dbsqlok(m_Link) != SUCCEED || dbresults(m_Link) == FAIL) {    if (dbsqlok(m_Link) != SUCCEED || x_Results(m_Link) == FAIL) {        throw CDB_ClientEx(eDB_Error, 210034, "CDBL_Connection::SendData",                           "dbsqlok/dbresults failed");    }    return true;}I_ITDescriptor* CDBL_Connection::x_GetNativeITDescriptor(const CDB_ITDescriptor& descr_in){    string q= "set rowcount 1\nupdate ";    q+= descr_in.TableName();    q+= " set ";    q+= descr_in.ColumnName();    q+= "=NULL where ";    q+= descr_in.SearchConditions();    q+= " \nselect ";    q+= descr_in.ColumnName();    q+= " from ";    q+= descr_in.TableName();    q+= " where ";    q+= descr_in.SearchConditions();    q+= " \nset rowcount 0";        CDB_LangCmd* lcmd= LangCmd(q, 0);    if(!lcmd->Send()) {	throw CDB_ClientEx(eDB_Error, 210035, "CDBL_Connection::x_GetNativeITDescriptor",			   "can not send the language command");    }    CDB_Result* res;    I_ITDescriptor* descr= 0;    bool i;    while(lcmd->HasMoreResults()) {	res= lcmd->Result();	if(res == 0) continue;	if((res->ResultType() == eDB_RowResult) && (descr == 0)) {	    EDB_Type tt= res->ItemDataType(0);	    if(tt == eDB_Text || tt == eDB_Image) {		while(res->Fetch()) {		    res->ReadItem(&i, 1);				    descr= new CDBL_ITDescriptor(m_Link, descr_in);		    // descr= res->GetImageOrTextDescriptor();		    if(descr) break;		}	    }	}	delete res;    }    delete lcmd;		    return descr;}RETCODE CDBL_Connection::x_Results(DBPROCESS* pLink){    unsigned int x_Status= 0x1;    CDB_Result* dbres;    I_Result* res= 0;    while ((x_Status & 0x1) != 0) {        if ((x_Status & 0x20) != 0) { // check for return parameters from exec            x_Status ^= 0x20;            int n;            if (m_ResProc && (n = dbnumrets(pLink)) > 0) {                res = new CDBL_ParamResult(pLink, n);                dbres= Create_Result(*res);                m_ResProc->ProcessResult(*dbres);                delete dbres;                delete res;            }            continue;        }        if ((x_Status & 0x40) != 0) { // check for ret status            x_Status ^= 0x40;            if (m_ResProc && dbhasretstat(pLink)) {                res = new CDBL_StatusResult(pLink);                dbres= Create_Result(*res);                m_ResProc->ProcessResult(*dbres);                delete dbres;                delete res;            }            continue;        }        if ((x_Status & 0x10) != 0) { // we do have a compute result            res = new CDBL_ComputeResult(pLink, &x_Status);            dbres= Create_Result(*res);            if(m_ResProc) {                m_ResProc->ProcessResult(*dbres);            }            else {                while(dbres->Fetch());            }            delete dbres;            delete res;        }        switch (dbresults(pLink)) {        case SUCCEED:            x_Status |= 0x60;            if (DBCMDROW(pLink) == SUCCEED) { // we could get rows in result                if(!m_ResProc) {                    while(1) {                        switch(dbnextrow(pLink)) {                        case NO_MORE_ROWS:                        case FAIL:                        case BUF_FULL: break;                        default: continue;                        }                        break;                    }                    continue;                }                            // This optimization is currently unavailable for MS dblib...#ifndef MS_DBLIB_IN_USE /*Text,Image*/                if (dbnumcols(pLink) == 1) {                    int ct = dbcoltype(pLink, 1);                    if ((ct == SYBTEXT) || (ct == SYBIMAGE)) {                        res = new CDBL_BlobResult(pLink);                    }                }#endif                if (!res)                    res = new CDBL_RowResult(pLink, &x_Status);                dbres= Create_Result(*res);                m_ResProc->ProcessResult(*dbres);                delete dbres;                delete res;            } else {                continue;            }        case NO_MORE_RESULTS:            x_Status = 2;            break;        default:            return FAIL;        }        break;    }    return SUCCEED;}/////////////////////////////////////////////////////////////////////////////////  CDBL_SendDataCmd:://CDBL_SendDataCmd::CDBL_SendDataCmd(CDBL_Connection* con, DBPROCESS* cmd,                                   size_t nof_bytes){    m_Connect  = con;    m_Cmd      = cmd;    m_Bytes2go = nof_bytes;}size_t CDBL_SendDataCmd::SendChunk(const void* pChunk, size_t nof_bytes){    if (!pChunk  ||  !nof_bytes) {        throw CDB_ClientEx(eDB_Fatal, 290000, "CDBL_SendDataCmd::SendChunk",                           "wrong (zero) arguments");    }    if (!m_Bytes2go)        return 0;    if (nof_bytes > m_Bytes2go)        nof_bytes = m_Bytes2go;    if (dbmoretext(m_Cmd, (DBINT) nof_bytes, (BYTE*) pChunk) != SUCCEED) {        dbcancel(m_Cmd);        throw CDB_ClientEx(eDB_Error, 290001, "CDBL_SendDataCmd::SendChunk",                           "dbmoretext failed");    }    m_Bytes2go -= nof_bytes;    if (m_Bytes2go <= 0) {        //        if (dbsqlok(m_Cmd) != SUCCEED || dbresults(m_Cmd) == FAIL) {        if (dbsqlok(m_Cmd) != SUCCEED || m_Connect->x_Results(m_Cmd) == FAIL) {            throw CDB_ClientEx(eDB_Error, 290002,                               "CDBL_SendDataCmd::SendChunk",                               "dbsqlok/results failed");        }    }    return nof_bytes;}void CDBL_SendDataCmd::Release(){    m_BR = 0;    if (m_Bytes2go > 0) {        dbcancel(m_Cmd);        m_Bytes2go = 0;    }    m_Connect->DropCmd(*this);    delete this;}CDBL_SendDataCmd::~CDBL_SendDataCmd(){    if (m_Bytes2go > 0)        dbcancel(m_Cmd);    if (m_BR)        *m_BR = 0;}END_NCBI_SCOPE/* * =========================================================================== * $Log: connection.cpp,v $ * Revision 1000.1  2004/06/01 19:20:09  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10  2004/05/18 18:30:36  gorelenk * PCH <ncbi_pch.hpp> moved to correct place . * * Revision 1.9  2004/05/17 21:12:41  gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.8  2003/06/05 16:01:13  soussov * adds code for DumpResults and for the dumped results processing * * Revision 1.7  2002/08/23 16:31:47  soussov * fixes bug in ~CDBL_Connection() * * Revision 1.6  2002/07/02 16:05:49  soussov * splitting Sybase dblib and MS dblib * * Revision 1.5  2002/03/26 15:37:52  soussov * new image/text operations added * * Revision 1.4  2002/01/08 18:10:18  sapojnik * Syabse to MSSQL name translations moved to interface_p.hpp * * Revision 1.3  2001/10/24 16:39:01  lavr * Explicit casts (where necessary) to eliminate 64->32 bit compiler warnings * * 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 + -