bool CTL_BCPInCmd::Cancel() { #ifndef FTDS_IN_USE DATABASE_DRIVER_ERROR("Cancelling is not available in ctlib.", 125000); #endif if(WasSent()) { if (IsDead()) { SetWasSent(false); return true; } CS_INT outrow = 0; size_t was_timeout = GetConnection().PrepareToCancel(); try { bool result = (CheckSentSFB(blk_done(x_GetSybaseCmd(), CS_BLK_CANCEL, &outrow), "blk_done failed", 123020) == CS_SUCCEED); GetConnection().CancelFinished(was_timeout); return result; } catch (CDB_Exception&) { GetConnection().CancelFinished(was_timeout); throw; } } return true; }
bool CDBL_BCPInCmd::Send(void) { char param_buff[2048]; // maximal row size, assured of buffer overruns if (!x_AssignParams(param_buff)) { SetHasFailed(); DATABASE_DRIVER_ERROR( "Cannot assign params." + GetDbgInfo(), 223004 ); } SetWasSent(); if (Check(bcp_sendrow(GetCmd())) != SUCCEED) { SetHasFailed(); DATABASE_DRIVER_ERROR( "bcp_sendrow failed." + GetDbgInfo(), 223005 ); } if (m_HasTextImage) { // send text/image data char buff[1800]; // text/image page size for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().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 (Check(bcp_moretext(GetCmd(), (DBINT) l, (BYTE*) buff)) != SUCCEED) { SetHasFailed(); string error; if (param.GetType() == eDB_Text) { error = "bcp_moretext for text failed."; } else { error = "bcp_moretext for image failed."; } DATABASE_DRIVER_ERROR( error + GetDbgInfo(), 223006 ); } if (!l) break; s -= l; } while (s); } } ++m_RowCount; return true; }
bool CDBL_BCPInCmd::Cancel() { if (WasSent()) { DBINT outrow = Check(bcp_done(GetCmd())); SetWasSent(false); return outrow == 0; } return true; }
bool CODBC_BCPInCmd::Cancel() { if (WasSent()) { bcp_control(GetHandle(), BCPABORT, NULL); DBINT outrow = bcp_done(GetHandle()); SetWasSent(false); return outrow == 0; } return true; }
bool CDBL_BCPInCmd::EndBCP(void) { if(WasSent()) { DBINT outrow = Check(bcp_done(GetCmd())); if(outrow < 0) { SetHasFailed(); DATABASE_DRIVER_ERROR( "bcp_done failed." + GetDbgInfo(), 223020 ); } SetWasSent(false); return outrow > 0; } return false; }
bool CODBC_BCPInCmd::EndBCP(void) { if(WasSent()) { Int4 outrow = bcp_done(GetHandle()); if(outrow == -1) { SetHasFailed(); ReportErrors(); DATABASE_DRIVER_ERROR( "bcp_done failed." + GetDbgInfo(), 423007 ); return false; } SetWasSent(false); return true; } return false; }
bool CODBC_RPCCmd::Cancel() { if (WasSent()) { if (m_Res) { delete m_Res; m_Res = 0; } SetWasSent(false); if ( !Close() ) { return false; } ResetParams(); // GetQuery().erase(); } return true; }
bool CTL_BCPInCmd::Send(void) { unsigned int i; CS_INT datalen = 0; size_t len = 0; char buff[2048]; CheckIsDead(); if ( !WasSent() ) { // we need to init the bcp CheckSFB(blk_init(x_GetSybaseCmd(), CS_BLK_IN, (CS_CHAR*) GetQuery().data(), GetQuery().size()), "blk_init failed", 123001); SetWasSent(); // check what needs to be default CS_DATAFMT fmt; for (i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) != 0) { continue; } SetHasFailed((Check(blk_describe(x_GetSybaseCmd(), i + 1, &fmt)) != CS_SUCCEED)); CHECK_DRIVER_ERROR( HasFailed(), "blk_describe failed (check the number of " "columns in a table)." + GetDbgInfo(), 123002 ); } } SetHasFailed(!x_AssignParams()); CHECK_DRIVER_ERROR( HasFailed(), "Cannot assign the params." + GetDbgInfo(), 123004 ); switch ( Check(blk_rowxfer(x_GetSybaseCmd())) ) { case CS_BLK_HAS_TEXT: for (i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().GetParam(i); if (param.IsNULL()) { continue; } else if (param.GetType() == eDB_Text || param.GetType() == eDB_Image) { CDB_Stream& par = dynamic_cast<CDB_Stream&> (param); for (datalen = (CS_INT) par.Size(); datalen > 0; datalen -= (CS_INT) len) { len = par.Read(buff, sizeof(buff)); SetHasFailed((Check(blk_textxfer(x_GetSybaseCmd(), (CS_BYTE*) buff, (CS_INT) len, 0) ) == CS_FAIL)); CHECK_DRIVER_ERROR( HasFailed(), "blk_textxfer failed for the text/image field." + GetDbgInfo(), 123005 ); } } } case CS_SUCCEED: ++m_RowCount; return true; default: SetHasFailed(); CHECK_DRIVER_ERROR( HasFailed(), "blk_rowxfer failed." + GetDbgInfo(), 123007 ); } return false; }
bool CODBC_RPCCmd::Send() { Cancel(); SetHasFailed(false); m_HasStatus = false; // make a language command string main_exec_query("declare @STpROCrETURNsTATUS int;\nexec @STpROCrETURNsTATUS="); main_exec_query += GetQuery(); string param_result_query; CMemPot bindGuard; string q_str; if(GetBindParamsImpl().NofParams() > 0) { SQLLEN* indicator = (SQLLEN*) bindGuard.Alloc(GetBindParamsImpl().NofParams() * sizeof(SQLLEN)); if (!x_AssignParams(q_str, main_exec_query, param_result_query, bindGuard, indicator)) { ResetParams(); SetHasFailed(); string err_message = "Cannot assign params." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420003 ); } } if(NeedToRecompile()) main_exec_query += " with recompile"; q_str += main_exec_query + ";\nselect STpROCrETURNsTATUS=@STpROCrETURNsTATUS"; if(!param_result_query.empty()) { q_str += ";\nselect " + param_result_query; } switch(SQLExecDirect(GetHandle(), CODBCString(q_str, GetClientEncoding()), SQL_NTS)) { case SQL_SUCCESS: m_HasMoreResults = true; break; case SQL_NO_DATA: m_HasMoreResults = true; /* this is a bug in SQLExecDirect it returns SQL_NO_DATA if status result is the only result of RPC */ m_RowCount = 0; break; case SQL_ERROR: ReportErrors(); ResetParams(); SetHasFailed(); { string err_message = "SQLExecDirect failed." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420001 ); } case SQL_SUCCESS_WITH_INFO: ReportErrors(); m_HasMoreResults = true; break; case SQL_STILL_EXECUTING: ReportErrors(); ResetParams(); SetHasFailed(); { string err_message = "Some other query is executing on this connection." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420002 ); } case SQL_INVALID_HANDLE: SetHasFailed(); { string err_message = "The statement handler is invalid (memory corruption suspected)." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420004 ); } default: ReportErrors(); ResetParams(); SetHasFailed(); { string err_message = "Unexpected error." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420005 ); } } SetWasSent(); return true; }
CDB_Result* CODBC_RPCCmd::Result() { enum {eNameStrLen = 64}; if (m_Res) { delete m_Res; m_Res = 0; m_HasMoreResults = xCheck4MoreResults(); } if ( !WasSent() ) { string err_message = "A command has to be sent first." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 420010 ); } if(!m_HasMoreResults) { SetWasSent(false); return 0; } SQLSMALLINT nof_cols = 0; odbc::TChar buffer[eNameStrLen]; while(m_HasMoreResults) { CheckSIE(SQLNumResultCols(GetHandle(), &nof_cols), "SQLNumResultCols failed", 420011); if(nof_cols < 1) { // no data in this result set SQLLEN rc; CheckSIE(SQLRowCount(GetHandle(), &rc), "SQLRowCount failed", 420013); m_RowCount = rc; m_HasMoreResults = xCheck4MoreResults(); continue; } if(nof_cols == 1) { // it could be a status result SQLSMALLINT l; CheckSIE(SQLColAttribute(GetHandle(), 1, SQL_DESC_LABEL, buffer, sizeof(buffer), &l, 0), "SQLColAttribute failed", 420015); if(util::strcmp(buffer, _T_NCBI_ODBC("STpROCrETURNsTATUS")) == 0) { //this is a status result m_HasStatus = true; m_Res = new CODBC_StatusResult(*this); } } if(!m_Res) { if(m_HasStatus) { m_HasStatus = false; m_Res = new CODBC_ParamResult(*this, nof_cols); } else { m_Res = new CODBC_RowResult(*this, nof_cols, &m_RowCount); } } return Create_Result(*m_Res); } SetWasSent(false); return 0; }
bool CODBC_BCPInCmd::Send(void) { char param_buff[2048]; // maximal row size, assured of buffer overruns if (!x_AssignParams(param_buff)) { SetHasFailed(); string err_message = "Cannot assign params." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 423004 ); } SetWasSent(); if (bcp_sendrow(GetHandle()) != SUCCEED) { SetHasFailed(); ReportErrors(); string err_message = "bcp_sendrow failed." + GetDbgInfo(); DATABASE_DRIVER_ERROR( err_message, 423005 ); } if (m_HasTextImage) { // send text/image data char buff[1800]; // text/image page size for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); ++i) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().GetParam(i); if (param.GetType() != eDB_Image && (param.GetType() != eDB_Text || param.IsNULL())) continue; CDB_Stream& val = dynamic_cast<CDB_Stream&> (param); size_t left_bytes = val.Size(); size_t len = 0; size_t valid_len = 0; size_t invalid_len = 0; do { invalid_len = len - valid_len; if (valid_len < len) { memmove(buff, buff + valid_len, invalid_len); } len = val.Read(buff + invalid_len, sizeof(buff) - invalid_len); if (len > left_bytes) { len = left_bytes; } valid_len = CUtf8::GetValidBytesCount( CTempString(buff, len)); CODBCString odbc_str(buff, len); // !!! TODO: Decode to UCS2 if needed !!!! if (bcp_moretext(GetHandle(), (DBINT) valid_len, (LPCBYTE)static_cast<const char*>(odbc_str) ) != SUCCEED) { SetHasFailed(); ReportErrors(); string err_text; if (param.GetType() == eDB_Text) { err_text = "bcp_moretext for text failed."; } else { err_text = "bcp_moretext for image failed."; } err_text += GetDbgInfo(); DATABASE_DRIVER_ERROR( err_text, 423006 ); } if (!valid_len) { break; } left_bytes -= valid_len; } while (left_bytes); } } return true; }