📄 connection.cpp
字号:
// this is not a native descriptor p_desc= x_GetNativeITDescriptor (dynamic_cast<CDB_ITDescriptor&> (descr_in)); if(p_desc == 0) return false; } C_ITDescriptorGuard d_guard(p_desc); CS_COMMAND* cmd; switch ( ct_cmd_alloc(m_Link, &cmd) ) { case CS_SUCCEED: break; case CS_FAIL: throw CDB_ClientEx(eDB_Fatal, 110001, "CTL_Connection::SendData", "ct_cmd_alloc failed"); case CS_BUSY: throw CDB_ClientEx(eDB_Fatal, 110002, "CTL_Connection::SendData", "the connection is busy"); } if (ct_command(cmd, CS_SEND_DATA_CMD, 0, CS_UNUSED, CS_COLUMN_DATA) != CS_SUCCEED) { ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110031, "CTL_Connection::SendData", "ct_command failed"); } CTL_ITDescriptor& desc = p_desc ? dynamic_cast<CTL_ITDescriptor&> (*p_desc) : dynamic_cast<CTL_ITDescriptor&> (descr_in); // desc->m_Desc.datatype = CS_TEXT_TYPE; desc.m_Desc.total_txtlen = size; desc.m_Desc.log_on_update = log_it ? CS_TRUE : CS_FALSE; if (ct_data_info(cmd, CS_SET, CS_UNUSED, &desc.m_Desc) != CS_SUCCEED) { ct_cancel(0, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return false; } while (size > 0) { char buff[1800]; CS_INT n_read = (CS_INT) img.Read(buff, sizeof(buff)); if ( !n_read ) { ct_cancel(0, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110032, "CTL_Connection::SendData", "Text/Image data corrupted"); } if (ct_send_data(cmd, buff, n_read) != CS_SUCCEED) { ct_cancel(0, cmd, CS_CANCEL_CURRENT); ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110033, "CTL_Connection::SendData", "ct_send_data failed"); } size -= n_read; } if (ct_send(cmd) != CS_SUCCEED) { ct_cancel(0, cmd, CS_CANCEL_CURRENT); ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110034, "CTL_Connection::SendData", "ct_send failed"); } for (;;) { CS_INT res_type; switch ( ct_results(cmd, &res_type) ) { case CS_SUCCEED: { if(m_ResProc) { I_Result* res= 0; switch (res_type) { case CS_ROW_RESULT: res = new CTL_RowResult(cmd); break; case CS_PARAM_RESULT: res = new CTL_ParamResult(cmd); break; case CS_COMPUTE_RESULT: res = new CTL_ComputeResult(cmd); break; case CS_STATUS_RESULT: res = new CTL_StatusResult(cmd); break; } if(res) { CDB_Result* dbres= Create_Result(*res); m_ResProc->ProcessResult(*dbres); delete dbres; delete res; continue; } } switch (res_type) { case CS_COMPUTE_RESULT: case CS_CURSOR_RESULT: case CS_PARAM_RESULT: case CS_ROW_RESULT: case CS_STATUS_RESULT: { CS_RETCODE ret_code; while ((ret_code = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, 0)) == CS_SUCCEED) { continue; } if (ret_code != CS_END_DATA) { ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110036, "CTL_Connection::SendData", "ct_fetch failed"); } break; } case CS_CMD_FAIL: ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Error, 110037, "CTL_Connection::SendData", "command failed"); default: break; } continue; } case CS_END_RESULTS: { ct_cmd_drop(cmd); return true; } default: { if (ct_cancel(0, cmd, CS_CANCEL_ALL) != CS_SUCCEED) { // we need to close this connection ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Fatal, 110033, "CTL_Connection::SendData", "Unrecoverable crash of ct_result. " "Connection must be closed"); } ct_cmd_drop(cmd); throw CDB_ClientEx(eDB_Error, 110034, "CTL_Connection::SendData", "ct_result failed"); } } }}I_ITDescriptor* CTL_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, 110035, "CTL_Connection::SendData", "can not send the language command"); } CDB_Result* res; I_ITDescriptor* descr= 0; while(lcmd->HasMoreResults()) { res= lcmd->Result(); if(res == 0) continue; if((res->ResultType() == eDB_RowResult) && (descr == 0)) { while(res->Fetch()) { //res->ReadItem(&i, 0); descr= res->GetImageOrTextDescriptor(); if(descr) break; } } delete res; } delete lcmd; return descr;}///////////////////////////////////////////////////////////////////////////////// CTL_SendDataCmd:://CTL_SendDataCmd::CTL_SendDataCmd(CTL_Connection* con, CS_COMMAND* cmd, size_t nof_bytes){ m_Connect = con; m_Cmd = cmd; m_Bytes2go = nof_bytes;}size_t CTL_SendDataCmd::SendChunk(const void* pChunk, size_t nof_bytes){ if (!pChunk || !nof_bytes) { throw CDB_ClientEx(eDB_Fatal, 190000, "CTL_SendDataCmd::SendChunk", "wrong (zero) arguments"); } if ( !m_Bytes2go ) return 0; if (nof_bytes > m_Bytes2go) nof_bytes = m_Bytes2go; if (ct_send_data(m_Cmd, (void*) pChunk, (CS_INT) nof_bytes) != CS_SUCCEED){ throw CDB_ClientEx(eDB_Fatal, 190001, "CTL_SendDataCmd::SendChunk", "ct_send_data failed"); } m_Bytes2go -= nof_bytes; if ( m_Bytes2go ) return nof_bytes; if (ct_send(m_Cmd) != CS_SUCCEED) { ct_cancel(0, m_Cmd, CS_CANCEL_CURRENT); throw CDB_ClientEx(eDB_Fatal, 190004, "CTL_SendDataCmd::SendChunk", "ct_send failed"); } for (;;) { CS_INT res_type; switch ( ct_results(m_Cmd, &res_type) ) { case CS_SUCCEED: { if(m_Connect->m_ResProc) { I_Result* res= 0; switch (res_type) { case CS_ROW_RESULT: res = new CTL_RowResult(m_Cmd); break; case CS_PARAM_RESULT: res = new CTL_ParamResult(m_Cmd); break; case CS_COMPUTE_RESULT: res = new CTL_ComputeResult(m_Cmd); break; case CS_STATUS_RESULT: res = new CTL_StatusResult(m_Cmd); break; } if(res) { CDB_Result* dbres= Create_Result(*res); m_Connect->m_ResProc->ProcessResult(*dbres); delete dbres; delete res; continue; } } switch ( res_type ) { case CS_COMPUTE_RESULT: case CS_CURSOR_RESULT: case CS_PARAM_RESULT: case CS_ROW_RESULT: case CS_STATUS_RESULT: { CS_RETCODE ret_code; while ((ret_code = ct_fetch(m_Cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, 0)) == CS_SUCCEED); if (ret_code != CS_END_DATA) { throw CDB_ClientEx(eDB_Fatal, 190006, "CTL_SendDataCmd::SendChunk", "ct_fetch failed"); } break; } case CS_CMD_FAIL: { ct_cancel(NULL, m_Cmd, CS_CANCEL_ALL); throw CDB_ClientEx(eDB_Error, 190007, "CTL_SendDataCmd::SendChunk", "command failed"); } default: { break; } } continue; } case CS_END_RESULTS: { return nof_bytes; } default: { if (ct_cancel(0, m_Cmd, CS_CANCEL_ALL) != CS_SUCCEED) { throw CDB_ClientEx(eDB_Fatal, 190002, "CTL_SendDataCmd::SendChunk", "Unrecoverable crash of ct_result. " "Connection must be closed"); } throw CDB_ClientEx(eDB_Error, 190003, "CTL_SendDataCmd::SendChunk", "ct_result failed"); } } }}void CTL_SendDataCmd::Release(){ m_BR = 0; if ( m_Bytes2go ) { ct_cancel(0, m_Cmd, CS_CANCEL_ALL); m_Bytes2go = 0; } m_Connect->DropCmd(*this); delete this;}CTL_SendDataCmd::~CTL_SendDataCmd(){ if ( m_Bytes2go ) ct_cancel(0, m_Cmd, CS_CANCEL_ALL); if ( m_BR ) *m_BR = 0; ct_cmd_drop(m_Cmd);}END_NCBI_SCOPE/* * =========================================================================== * $Log: connection.cpp,v $ * Revision 1000.1 2004/06/01 19:19:34 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.17 * * Revision 1.17 2004/05/17 21:12:03 gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.16 2003/09/23 19:38:22 soussov * cancels send_data cmd if it failes while processing results * * Revision 1.15 2003/07/08 18:51:38 soussov * fixed bug in constructor * * Revision 1.14 2003/06/05 16:00:31 soussov * adds code for DumpResults and for the dumped results processing * * Revision 1.13 2003/02/05 14:56:22 dicuccio * Fixed uninitialized read reported by valgrind. * * Revision 1.12 2003/01/31 16:49:38 lavr * Remove unused variable "e" from catch() clause * * Revision 1.11 2002/12/16 16:17:25 soussov * ct_con_props returns an outlen == strlen(x)+1. Adaptin to this feature * * Revision 1.10 2002/09/16 15:10:23 soussov * add try catch when canceling active commands in Refresh method * * Revision 1.9 2002/03/27 05:01:58 vakatov * Minor formal fixes * * Revision 1.8 2002/03/26 15:34:37 soussov * new image/text operations added * * Revision 1.7 2002/02/01 21:49:37 soussov * ct_cmd_drop for the CTL_Connection::SendData added * * Revision 1.6 2001/11/06 17:59:55 lavr * Formatted uniformly as the rest of the library * * Revision 1.5 2001/10/12 21:21:00 lavr * Faster checks against zero for unsigned ints * * Revision 1.4 2001/09/27 20:08:33 vakatov * Added "DB_" (or "I_") prefix where it was missing * * Revision 1.3 2001/09/27 15:42:09 soussov * CTL_Connection::Release() added * * Revision 1.2 2001/09/25 15:05:43 soussov * fixed typo in CTL_SendDataCmd::SendChunk * * 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 + -