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

📄 bcp.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                0, &m_Bind[i].datalen,                                &m_Bind[i].indicator);            break;        }        case eDB_Image: {            CDB_Image& par = dynamic_cast<CDB_Image&> (param);            param_fmt.datatype  = CS_IMAGE_TYPE;            param_fmt.maxlength = (CS_INT) par.Size();            m_Bind[i].datalen   = (CS_INT) par.Size();            ret_code = blk_bind(m_Cmd, i + 1, &param_fmt,                                0, &m_Bind[i].datalen,                                &m_Bind[i].indicator);            break;        }        default: {            return false;        }        }        if (ret_code != CS_SUCCEED) {            return false;        }    }    return true;}bool CTL_BCPInCmd::SendRow(){    unsigned int i;    CS_INT       datalen = 0;    CS_SMALLINT  indicator = 0;    if ( !m_WasSent ) {        // we need to init the bcp        if (blk_init(m_Cmd, CS_BLK_IN, (CS_CHAR*) m_Query.c_str(), CS_NULLTERM)            != CS_SUCCEED) {            m_HasFailed = true;            throw CDB_ClientEx(eDB_Fatal, 123001, "CTL_BCPInCmd::SendRow",                               "blk_init failed");        }        m_WasSent = true;        // check what needs to be default        CS_DATAFMT fmt;        for (i = 0;  i < m_Params.NofParams();  i++) {            if (m_Params.GetParamStatus(i) != 0)                continue;            if (blk_describe(m_Cmd, i + 1, &fmt) != CS_SUCCEED) {                m_HasFailed = true;                throw CDB_ClientEx(eDB_Error, 123002, "CTL_BCPInCmd::SendRow",                                   "blk_describe failed (check the number of "                                   "columns in a table)");            }            if (blk_bind(m_Cmd, i + 1, &fmt, (void*) &m_Params,                         &datalen, &indicator) != CS_SUCCEED) {                m_HasFailed = true;                throw CDB_ClientEx(eDB_Error, 123003, "CTL_BCPInCmd::SendRow",                                   "blk_bind failed for default value");            }        }    }    if ( !x_AssignParams() ) {        m_HasFailed = true;        throw CDB_ClientEx(eDB_Error, 123004, "CTL_BCPInCmd::SendRow",                           "cannot assign the params");    }    switch ( blk_rowxfer(m_Cmd) ) {    case CS_BLK_HAS_TEXT:  {        char buff[2048];        size_t n;	        for (i = 0;  i < m_Params.NofParams();  i++) {            if (m_Params.GetParamStatus(i) == 0)                continue;            CDB_Object& param = *m_Params.GetParam(i);            if ((param.GetType() != eDB_Text) &&                (param.GetType() != eDB_Image)) {                continue;            } else {                CDB_Stream& par = dynamic_cast<CDB_Stream&> (param);                for (datalen = (CS_INT) par.Size();  datalen > 0;                     datalen -= (CS_INT) n) {                    n = par.Read(buff, 2048);                    if (blk_textxfer(m_Cmd, (CS_BYTE*) buff, (CS_INT) n, 0)                        == CS_FAIL) {                        m_HasFailed = true;                        throw CDB_ClientEx                            (eDB_Error, 123005, "CTL_BCPInCmd::SendRow",                             "blk_textxfer failed for the text/image field");                    }                }            }        }    }    case CS_SUCCEED:        return true;    default:        m_HasFailed = true;        throw CDB_ClientEx(eDB_Fatal, 123007,                           "CTL_BCPInCmd::SendRow", "blk_rowxfer failed");    }    return false;}bool CTL_BCPInCmd::Cancel(){    if(!m_WasSent) return false;    CS_INT outrow = 0;    switch( blk_done(m_Cmd, CS_BLK_CANCEL, &outrow) ) {    case CS_SUCCEED: m_WasSent= false; return true;    case CS_FAIL:        m_HasFailed = true;        throw CDB_ClientEx(eDB_Fatal, 123020,                           "CTL_BCPInCmd::Cancel", "blk_done failed");    default: m_WasSent = false; return false;    }}bool CTL_BCPInCmd::CompleteBatch(){    if(!m_WasSent) return false;    CS_INT outrow = 0;    switch( blk_done(m_Cmd, CS_BLK_BATCH, &outrow) ) {    case CS_SUCCEED: return (outrow > 0);    case CS_FAIL:        m_HasFailed = true;        throw CDB_ClientEx(eDB_Fatal, 123020,                           "CTL_BCPInCmd::CompleteBatch", "blk_done failed");    default: return false;    }}bool CTL_BCPInCmd::CompleteBCP(){    if(!m_WasSent) return false;    CS_INT outrow = 0;    switch( blk_done(m_Cmd, CS_BLK_ALL, &outrow) ) {    case CS_SUCCEED: m_WasSent= false; return (outrow > 0);    case CS_FAIL:        m_HasFailed = true;        throw CDB_ClientEx(eDB_Fatal, 123020,                           "CTL_BCPInCmd::CompleteBCP", "blk_done failed");    default: m_WasSent= false; return false;    }}void CTL_BCPInCmd::Release(){    m_BR = 0;    if (m_WasSent) {        try {            Cancel();        } catch (CDB_Exception& ) {}        m_WasSent = false;    }    m_Connect->DropCmd(*this);    delete this;}CTL_BCPInCmd::~CTL_BCPInCmd(){    if ( m_BR ) {        *m_BR = 0;    }    if ( m_WasSent ) {        try {            Cancel();        } catch (CDB_Exception& ) {}    }    delete[] m_Bind;    blk_drop(m_Cmd);}END_NCBI_SCOPE/* * =========================================================================== * $Log: bcp.cpp,v $ * Revision 1000.1  2004/06/01 19:19:32  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * * Revision 1.8  2004/05/17 21:12:02  gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.7  2003/01/31 16:49:38  lavr * Remove unused variable "e" from catch() clause * * Revision 1.6  2002/09/16 16:34:16  soussov * add try catch when canceling in Release method * * Revision 1.5  2002/09/16 15:13:12  soussov * throw exceptions in CompleteBCP, CompleteBatch, Cancel if blk_done fails * * Revision 1.4  2001/11/06 17:59:55  lavr * Formatted uniformly as the rest of the library * * Revision 1.3  2001/10/11 19:10:59  soussov * merges the text/image processing in CTL_BCPInCmd::SendRow()] * * Revision 1.2  2001/10/11 16:30:44  soussov * exclude ctlib dependencies from numeric conversion calls * * Revision 1.1  2001/09/21 23:40:02  vakatov * -----  Initial (draft) revision.  ----- * This is a major revamp (by Denis Vakatov, with help from Vladimir Soussov) * of the DBAPI "driver" libs originally written by Vladimir Soussov. * The revamp 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 + -