Esempio n. 1
0
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;
}
Esempio n. 2
0
bool CDBL_BCPInCmd::Cancel()
{
    if (WasSent()) {
        DBINT outrow = Check(bcp_done(GetCmd()));
        SetWasSent(false);
        return outrow == 0;
    }

    return true;
}
Esempio n. 3
0
bool CODBC_BCPInCmd::Cancel()
{
    if (WasSent()) {
        bcp_control(GetHandle(), BCPABORT, NULL);
        DBINT outrow = bcp_done(GetHandle());
        SetWasSent(false);
        return outrow == 0;
    }

    return true;
}
Esempio n. 4
0
bool CDBL_BCPInCmd::CommitBCPTrans(void)
{
    if(WasSent()) {
        DBINT outrow = Check(bcp_batch(GetCmd()));
        if(outrow < 0) {
            SetHasFailed();
            DATABASE_DRIVER_ERROR( "bcp_batch failed." + GetDbgInfo(), 223020 );
        }
        return outrow > 0;
    }
    return false;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
bool CODBC_BCPInCmd::CommitBCPTrans(void)
{
    if(WasSent()) {
        Int4 outrow = bcp_batch(GetHandle());
        if(outrow == -1) {
            SetHasFailed();
            ReportErrors();
            DATABASE_DRIVER_ERROR( "bcp_batch failed." + GetDbgInfo(), 423006 );
            return false;
        }
        return true;
    }
    return false;
}
Esempio n. 7
0
bool CTL_BCPInCmd::EndBCP(void)
{
    if(!WasSent()) return false;

    CheckIsDead();

    CS_INT outrow = 0;

    if (CheckSentSFB(blk_done(x_GetSybaseCmd(), CS_BLK_ALL, &outrow),
                     "blk_done failed", 123020) == CS_SUCCEED) {
        return (outrow > 0);
    }

    return false;
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
bool CTL_BCPInCmd::CommitBCPTrans(void)
{
    if(!WasSent()) return false;

    CheckIsDead();

    CS_INT outrow = 0;

    switch( Check(blk_done(x_GetSybaseCmd(), CS_BLK_BATCH, &outrow)) ) {
    case CS_SUCCEED:
        return (outrow > 0);
    case CS_FAIL:
        SetHasFailed();
        DATABASE_DRIVER_ERROR( "blk_done failed." + GetDbgInfo(), 123020 );
    default:
        return false;
    }
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
void
CTL_BCPInCmd::Close(void)
{
    if (x_GetSybaseCmd()) {
        // ????
        DetachInterface();

        try {

#ifdef FTDS_IN_USE
            SetDead(!Cancel());
#else
            if (WasSent()) {
                SetDead(!EndBCP());
            }
#endif

        } catch (...) {
            SetDead();
            throw;
        }
    }
}
Esempio n. 12
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;
}
Esempio n. 13
0
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;
}