📄 bcp.cpp
字号:
pb = (void*) (v + 1); } break; case eDB_Char: { CDB_Char& val = dynamic_cast<CDB_Char&> (param); r = bcp_colptr(m_Cmd, (BYTE*) val.Value(), i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : -1, i + 1) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_VarChar: { CDB_VarChar& val = dynamic_cast<CDB_VarChar&> (param); r = bcp_colptr(m_Cmd, (BYTE*) val.Value(), i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : -1, i + 1) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_Binary: { CDB_Binary& val = dynamic_cast<CDB_Binary&> (param); r = bcp_colptr(m_Cmd, (BYTE*) val.Value(), i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : (DBINT) val.Size(), i + 1) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_VarBinary: { CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param); r = bcp_colptr(m_Cmd, (BYTE*) val.Value(), i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : (DBINT) val.Size(), i + 1) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_Float: { CDB_Float& val = dynamic_cast<CDB_Float&> (param); //DBREAL v = (DBREAL) val.Value(); r = bcp_colptr(m_Cmd, (BYTE*) val.BindVal(), i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : -1, i + 1) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_Double: { CDB_Double& val = dynamic_cast<CDB_Double&> (param); //DBFLT8 v = (DBFLT8) val.Value(); r = bcp_bind(m_Cmd, (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBFLT8, i + 1); } break; case eDB_SmallDateTime: { CDB_SmallDateTime& val = dynamic_cast<CDB_SmallDateTime&> (param); DBDATETIME4* dt = (DBDATETIME4*) pb; DBDATETIME4_days(dt) = val.GetDays(); DBDATETIME4_mins(dt) = val.GetMinutes(); r = bcp_colptr(m_Cmd, (BYTE*) dt, i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : -1, i + 1) == SUCCEED ? SUCCEED : FAIL; pb = (void*) (dt + 1); } break; case eDB_DateTime: { CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param); DBDATETIME* dt = (DBDATETIME*) pb; dt->dtdays = val.GetDays(); dt->dttime = val.Get300Secs(); r = bcp_colptr(m_Cmd, (BYTE*) dt, i + 1) == SUCCEED && bcp_collen(m_Cmd, val.IsNULL() ? 0 : -1, i + 1) == SUCCEED ? SUCCEED : FAIL; pb = (void*) (dt + 1); } break; case eDB_Text: { CDB_Text& val = dynamic_cast<CDB_Text&> (param); r = bcp_collen(m_Cmd, (DBINT) val.Size(), i + 1); } break; case eDB_Image: { CDB_Image& val = dynamic_cast<CDB_Image&> (param); r = bcp_collen(m_Cmd, (DBINT) val.Size(), i + 1); } break; default: return false; } if (r != CS_SUCCEED) return false; } } return true;}bool CDBL_BCPInCmd::SendRow(){ char param_buff[2048]; // maximal row size, assured of buffer overruns if (!x_AssignParams(param_buff)) { m_HasFailed = true; throw CDB_ClientEx(eDB_Error, 223004, "CDBL_BCPInCmd::SendRow", "cannot assign params"); } if (bcp_sendrow(m_Cmd) != SUCCEED) { m_HasFailed = true; throw CDB_ClientEx(eDB_Error, 223005, "CDBL_BCPInCmd::SendRow", "bcp_sendrow failed"); } m_WasSent = true; if (m_HasTextImage) { // send text/image data char buff[1800]; // text/image page size for (unsigned int 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; CDB_Stream& val = dynamic_cast<CDB_Stream&> (param); size_t s = val.Size(); do { size_t l = val.Read(buff, sizeof(buff)); if (l > s) l = s; if (bcp_moretext(m_Cmd, (DBINT) l, (BYTE*) buff) != SUCCEED) { m_HasFailed = true; throw CDB_ClientEx(eDB_Error, 223006, "CDBL_BCPInCmd::SendRow", param.GetType() == eDB_Text ? "bcp_moretext for text failed" : "bcp_moretext for image failed"); } if (!l) break; s -= l; } while (s); } } return true;}bool CDBL_BCPInCmd::Cancel(){ if(m_WasSent) { DBINT outrow = bcp_done(m_Cmd); m_WasSent= false; return outrow == 0; } return true;}bool CDBL_BCPInCmd::CompleteBatch(){ if(m_WasSent) { CS_INT outrow = bcp_batch(m_Cmd); return outrow != -1; } return false;}bool CDBL_BCPInCmd::CompleteBCP(){ if(m_WasSent) { DBINT outrow = bcp_done(m_Cmd); m_WasSent= false; return outrow != -1; } return false;}void CDBL_BCPInCmd::Release(){ m_BR = 0; if (m_WasSent) { Cancel(); m_WasSent = false; } m_Connect->DropCmd(*this); delete this;}CDBL_BCPInCmd::~CDBL_BCPInCmd(){ if (m_BR) *m_BR = 0; if (m_WasSent) Cancel();}END_NCBI_SCOPE/* * =========================================================================== * $Log: bcp.cpp,v $ * Revision 1000.1 2004/06/01 19:20:00 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 2002/07/02 16:05:49 soussov * splitting Sybase dblib and MS dblib * * Revision 1.7 2002/03/04 19:07:21 soussov * fixed bug in m_WasSent flag setting * * Revision 1.6 2002/01/08 18:10:18 sapojnik * Syabse to MSSQL name translations moved to interface_p.hpp * * Revision 1.5 2002/01/03 17:01:56 sapojnik * fixing CR/LF mixup * * Revision 1.4 2002/01/03 15:46:23 sapojnik * ported to MS SQL (about 12 'ifdef NCBI_OS_MSWIN' in 6 files) * * Revision 1.3 2001/10/24 16:38:53 lavr * Explicit casts (where necessary) to eliminate 64->32 bit compiler warnings * * Revision 1.2 2001/10/22 18:38:49 soussov * sending NULL instead of emty string fixed * * 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 + -