示例#1
0
CDB_SendDataCmd::CDB_SendDataCmd(impl::CSendDataCmd* c)
{
    CHECK_DRIVER_ERROR( !c, "No valid command provided", 200006 );

    m_CmdImpl = c;
    m_CmdImpl->AttachTo(this);
}
示例#2
0
CDB_Result::CDB_Result(impl::CResult* r) :
    m_ResImpl(r)
{
    CHECK_DRIVER_ERROR( !m_ResImpl, "No valid result provided", 200004 );

    m_ResImpl->AttachTo(this);
}
示例#3
0
CDB_BCPInCmd::CDB_BCPInCmd(impl::CBaseCmd* c)
{
    CHECK_DRIVER_ERROR( !c, "No valid command provided", 200007 );

    m_CmdImpl = c;
    m_CmdImpl->AttachTo(this);
}
示例#4
0
CDBL_ITDescriptor::CDBL_ITDescriptor(CDBL_Connection& conn,
                                     DBPROCESS* dblink,
                                     int col_num) :
CDBL_Result(conn, dblink)
{
    // !!! This is a hack !!!
    // dbcolname returns char*
    DBCOLINFO* col_info = (DBCOLINFO*) Check(dbcolname(GetCmd(), col_num));

    CHECK_DRIVER_ERROR(
        col_info == 0,
        "Cannot get the DBCOLINFO*." + GetDbgInfo(),
        280000 );

    if (!x_MakeObjName(col_info)) {
        m_ObjName.erase();
    }

    DBBINARY* p = Check(dbtxptr(GetCmd(), col_num));
    if (p) {
        memcpy(m_TxtPtr, p, DBTXPLEN);
        m_TxtPtr_is_NULL = false;
    } else
        m_TxtPtr_is_NULL = true;

    p = Check(dbtxtimestamp(GetCmd(), col_num));
    if (p) {
        memcpy(m_TimeStamp, p, DBTXTSLEN);
        m_TimeStamp_is_NULL = false;
    } else
        m_TimeStamp_is_NULL = true;
}
示例#5
0
size_t CDBL_SendDataCmd::SendChunk(const void* pChunk, size_t nof_bytes)
{
    CHECK_DRIVER_ERROR(
        !pChunk  ||  !nof_bytes,
        "Wrong (zero) arguments." + GetDbgInfo(),
        290000 );

    if (!GetBytes2Go())
        return 0;

    if (nof_bytes > GetBytes2Go())
        nof_bytes = GetBytes2Go();

    if (Check(dbmoretext(GetCmd(), (DBINT) nof_bytes, (BYTE*) pChunk)) != SUCCEED) {
        Check(dbcancel(GetCmd()));
        DATABASE_DRIVER_ERROR( "dbmoretext failed." + GetDbgInfo(), 290001 );
    }

    SetBytes2Go(GetBytes2Go() - nof_bytes);

    if (GetBytes2Go() <= 0) {
        //        if (dbsqlok(m_Cmd) != SUCCEED || dbresults(m_Cmd) == FAIL) {
        if (Check(dbsqlok(GetCmd())) != SUCCEED || GetConnection().x_Results(GetCmd()) == FAIL) {
            DATABASE_DRIVER_ERROR( "dbsqlok/results failed." + GetDbgInfo(), 290002 );
        }
    }

    return nof_bytes;
}
示例#6
0
CDB_Connection::CDB_Connection(impl::CConnection* c)
{
    CHECK_DRIVER_ERROR( !c, "No valid connection provided", 200001 );

    m_ConnImpl = c;
    m_ConnImpl->AttachTo(this);
    m_ConnImpl->SetResultProcessor(0); // to clean up the result processor if any
}
示例#7
0
void CDBHandlerStack::Push(CDB_UserHandler* h, EOwnership ownership)
{
    CHECK_DRIVER_ERROR(h == NULL, "An attempt to pass NULL instead of "
                       "a valid CDB_UserHandler object", 0);

    CRef<CUserHandlerWrapper>
        obj(new CUserHandlerWrapper(h, ownership == eNoOwnership));

    m_Stack.push_back(TContainer::value_type(obj));
}
示例#8
0
CDB_BCPInCmd* CDBL_Connection::BCPIn(const string& table_name)
{
    CHECK_DRIVER_ERROR( !IsBCPable(), "No bcp on this connection." + GetDbgInfo(), 210003 );

    string extra_msg = "BCP Table: " + table_name;
    SetExtraMsg(extra_msg);

    CDBL_BCPInCmd* bcmd = new CDBL_BCPInCmd(*this, GetDBLibConnection(), table_name);
    return Create_BCPInCmd(*bcmd);
}
示例#9
0
BEGIN_NCBI_SCOPE


////////////////////////////////////////////////////////////////////////////
//  CDBParamVariant::
//
inline
unsigned int ConvertI2UI(int value)
{
    CHECK_DRIVER_ERROR( (value < 0), "Negative parameter's position not allowed.", 200001 );

    return static_cast<unsigned int>(value);
}
示例#10
0
unsigned int 
CDB_Params::GetParamNum(unsigned int param_no, const string& param_name)
{
    if (param_no == CDB_Params::kNoParamNumber) {
        if (!param_name.empty()) {
            // try to find this name
            if (!GetParamNumInternal(param_name, param_no)) {
                // Parameter not found ...
		CHECK_DRIVER_ERROR(IsLocked(), "Parameters are locked. New bindins are not allowed.", 20001);
                m_Params.resize(m_Params.size() + 1);
                return m_Params.size() - 1;
            }
        }
    } else {
        if (param_no >= m_Params.size()) {
	    CHECK_DRIVER_ERROR(IsLocked(), "Parameters are locked. New bindins are not allowed.", 20001);
            m_Params.resize(param_no + 1);
        }
    }

    return param_no;
}
示例#11
0
CDB_SendDataCmd* CDBL_Connection::SendDataCmd(I_BlobDescriptor& descr_in,
                                              size_t data_size,
                                              bool log_it,
                                              bool /*dump_results*/)
{
    x_SetExtraMsg(descr_in, data_size);
    CHECK_DRIVER_ERROR( data_size < 1, "Wrong (zero) data size." + GetDbgInfo(), 210092 );

    I_BlobDescriptor* p_desc= 0;

    // check what type of descriptor we've got
    if(descr_in.DescriptorType() != CDBL_BLOB_DESCRIPTOR_TYPE_MAGNUM) {
        // this is not a native descriptor
        p_desc = x_GetNativeBlobDescriptor
            (dynamic_cast<CDB_BlobDescriptor&>(descr_in));
        if (p_desc == NULL) {
            return NULL;
        } else {
            x_SetExtraMsg(*p_desc, data_size);
        }
    }


    unique_ptr<I_BlobDescriptor> d_guard(p_desc);

    CDBL_BlobDescriptor& desc
        = p_desc ? dynamic_cast<CDBL_BlobDescriptor&>(*p_desc) :
        dynamic_cast<CDBL_BlobDescriptor&>(descr_in);

    if (Check(dbwritetext(GetDBLibConnection(),
                    (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) data_size, 0)) != SUCCEED ||
        Check(dbsqlok(GetDBLibConnection())) != SUCCEED ||
        //        dbresults(GetDBLibConnection()) == FAIL) {
        x_Results(GetDBLibConnection()) == FAIL) {
        DATABASE_DRIVER_ERROR( "dbwritetext/dbsqlok/dbresults failed." + GetDbgInfo(), 210093 );
    }

    CDBL_SendDataCmd* sd_cmd = new CDBL_SendDataCmd(*this, GetDBLibConnection(), data_size);
    return Create_SendDataCmd(*sd_cmd);
}
示例#12
0
void CDBHandlerStack::Pop(CDB_UserHandler* h, bool last)
{
    CHECK_DRIVER_ERROR(h == NULL, "An attempt to pass NULL instead of "
                       "a valid CDB_UserHandler object", 0);

    if ( last ) {
        TContainer::reverse_iterator rcit;

        rcit = find_if(m_Stack.rbegin(), m_Stack.rend(), CFunctor(h));

        if ( rcit != m_Stack.rend() ) {
            m_Stack.erase((--rcit.base()), m_Stack.end());
        }
    } else {
        TContainer::iterator cit;

        cit = find_if(m_Stack.begin(), m_Stack.end(), CFunctor(h));

        if ( cit != m_Stack.end() ) {
            m_Stack.erase(cit, m_Stack.end());
        }
    }
}
示例#13
0
I_ITDescriptor*
CTL_RowResult::GetImageOrTextDescriptor(int item_num)
{
    bool is_null = false;

    if ((unsigned int) item_num >= GetDefineParams().GetNum()  ||  item_num < 0) {
        return 0;
    }

    char dummy[4];
    CS_INT outlen = 0;

    switch (my_ct_get_data(x_GetSybaseCmd(), item_num + 1, dummy, 0, &outlen, is_null) ) {
    case CS_END_ITEM:
    case CS_END_DATA:
    case CS_SUCCEED:
        break;
    case CS_CANCELED:
        DATABASE_DRIVER_ERROR( "The command has been canceled." + GetDbgInfo(), 130004 );
    default:
        DATABASE_DRIVER_ERROR( "ct_get_data failed." + GetDbgInfo(), 130000 );
    }

    if (is_null)
        m_NullValue[item_num] = eIsNull;

    auto_ptr<CTL_ITDescriptor> desc(new CTL_ITDescriptor);

    bool rc = (Check(ct_data_info(x_GetSybaseCmd(),
                                  CS_GET,
                                  item_num + 1,
                                  &desc->m_Desc))
        != CS_SUCCEED);
    CHECK_DRIVER_ERROR( rc, "ct_data_info failed." + GetDbgInfo(), 130010 );

    return desc.release();
}
示例#14
0
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;
}
示例#15
0
CTL_RowResult::CTL_RowResult(CS_COMMAND* cmd, CTL_Connection& conn) :
    m_Connect(&conn),
    m_Cmd(cmd),
    m_CurrItem(-1),
    m_EOR(false),
    m_BindedCols(0)
{
    CheckIsDead();

    CS_INT outlen;

    CS_INT nof_cols;
    bool rc = (Check(ct_res_info(x_GetSybaseCmd(),
                                 CS_NUMDATA,
                                 &nof_cols,
                                 CS_UNUSED,
                                 &outlen))
               != CS_SUCCEED);
    CHECK_DRIVER_ERROR( rc, "ct_res_info(CS_NUMDATA) failed." + GetDbgInfo(), 130001 );

    CS_INT bind_len = 0;
    m_BindedCols = 0;
    bool buff_is_full = false;

    m_ColFmt = AutoArray<CS_DATAFMT>(nof_cols);
    m_NullValue = AutoArray<ENullValue>(nof_cols);

    for (unsigned int nof_item = 0;  nof_item < (unsigned int) nof_cols;  nof_item++) {
        rc = (Check(ct_describe(x_GetSybaseCmd(),
                                (CS_INT) nof_item + 1,
                                &m_ColFmt[nof_item]))
            != CS_SUCCEED);
        CHECK_DRIVER_ERROR( rc, "ct_describe failed." + GetDbgInfo(), 130002 );

        m_NullValue[nof_item] = eNullUnknown;

#ifdef FTDS_IN_USE
        // Seems like FreeTDS reports wrong maxlength in
        // ct_describe() - fix this when binding to a buffer.
        if (m_ColFmt[nof_item].datatype == CS_NUMERIC_TYPE
            || m_ColFmt[nof_item].datatype == CS_DECIMAL_TYPE
            ) {
            m_ColFmt[nof_item].maxlength = sizeof(CS_NUMERIC);
        }
#endif

        m_CachedRowInfo.Add(
                string(m_ColFmt[nof_item].name, m_ColFmt[nof_item].namelen),
                m_ColFmt[nof_item].maxlength,
                ConvDataType_Ctlib2DBAPI(m_ColFmt[nof_item])
                );

        if (!buff_is_full) {
            if (m_ColFmt[nof_item].maxlength > 2048
                ||  m_ColFmt[nof_item].datatype == CS_IMAGE_TYPE)
            {
                buff_is_full = true;
            } else {
                bind_len += m_ColFmt[nof_item].maxlength;
                if (bind_len <= 2048) {
                    m_BindedCols++;
                } else {
                    buff_is_full = true;
                }
            }
        }
    }



    if(m_BindedCols) {
        m_BindItem = AutoArray<CS_VOID*>(m_BindedCols);
        m_Copied = AutoArray<CS_INT>(m_BindedCols);
        m_Indicator = AutoArray<CS_SMALLINT>(m_BindedCols);

        for(int i= 0; i < m_BindedCols; i++) {
          m_BindItem[i] = (i ? ((unsigned char*)(m_BindItem[i-1])) + m_ColFmt[i-1].maxlength : m_BindBuff);
          rc = (Check(ct_bind(x_GetSybaseCmd(),
                              i+1,
                              &m_ColFmt[i],
                              m_BindItem[i],
                              &m_Copied[i],
                              &m_Indicator[i]) )
                    != CS_SUCCEED);

            CHECK_DRIVER_ERROR( rc, "ct_bind failed." + GetDbgInfo(), 130042 );
        }
    }
}