コード例 #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;
}
コード例 #2
0
ファイル: blk_in2.c プロジェクト: DavidRueter/freetds
static CS_RETCODE
hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
{
	CS_DATAFMT meta = { "" };
	CS_INT length = 5;
	CS_INT row = 0;

	if (CS_SUCCEED != ct_cancel(con, NULL, CS_CANCEL_ALL))
		return CS_FAIL;
	if (CS_SUCCEED != blk_init(blk, CS_BLK_IN, table, CS_NULLTERM))
		return CS_FAIL;

	meta.count = 1;
	meta.datatype = CS_CHAR_TYPE;
	meta.format = CS_FMT_PADBLANK;
	meta.maxlength = 5;

	if (CS_SUCCEED != blk_bind(blk, (int) 1, &meta, data, &length, NULL))
		return CS_FAIL;
	if (CS_SUCCEED != blk_rowxfer(blk))
		return CS_FAIL;
	if (CS_SUCCEED != blk_done(blk, CS_BLK_ALL, &row))
		return CS_FAIL;

	return CS_SUCCEED;
}
コード例 #3
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;
}
コード例 #4
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;
    }
}
コード例 #5
0
/**
*   @brief bulk copy data from TBL_NumberPrefix
*/
int CSybClient::bulkCopyOut_NumberPrefix(int connId, char* tablename)
{
    CS_CONNECTION *connection = getConnection(connId);
    if(NULL == connection || NULL == tablename) return -1;

    CLEAR_ALL_MESSAGE(connection);

    int copiedRowCnt = 0;
    CS_RETCODE retcode;

    #define MAX_ROWS_ONETIME 1024
	CS_BLKDESC	*blkdesc;
    CS_DATAFMT	datafmt;	    /* hold the variable descriptions */
    CS_CHAR     areaCode_fieldBuf[MAX_ROWS_ONETIME][16];
	CS_CHAR 	prefix_fieldBuf[MAX_ROWS_ONETIME][32];	/* point to the data for transfer */
    CS_DATETIME updateTime_fieldBuf[MAX_ROWS_ONETIME];
    CS_TINYINT  sarNumber_fieldBuf[MAX_ROWS_ONETIME];
    CS_TINYINT  exchangeHouse_fieldBuf[MAX_ROWS_ONETIME];
    //
    CS_SMALLINT areaCode_indBuf[MAX_ROWS_ONETIME];
    CS_SMALLINT prefix_indBuf[MAX_ROWS_ONETIME];
    CS_SMALLINT updateTime_indBuf[MAX_ROWS_ONETIME];
    CS_SMALLINT sarNumber_indBuf[MAX_ROWS_ONETIME];
    CS_SMALLINT exchangeHouse_indBuf[MAX_ROWS_ONETIME];
    //
	CS_INT      areaCode_bufLen[MAX_ROWS_ONETIME];
    CS_INT      prefix_bufLen[MAX_ROWS_ONETIME];
    CS_INT      updateTime_bufLen[MAX_ROWS_ONETIME];
    CS_INT      sarNumber_bufLen[MAX_ROWS_ONETIME];
    CS_INT      exchangeHouse_bufLen[MAX_ROWS_ONETIME];
    //
	CS_INT		numrows = MAX_ROWS_ONETIME;
    //
    #define FIELD_AreaCode      1
    #define FIELD_Prefix        2
    #define FIELD_UpdateTime    3
    #define FIELD_SARNumber     5
    #define FIELD_ExchangeHouse 6

	/*
	** Ready to start the bulk copy in now that all the connections
	** have been made and have a table name.
	**
	** Start by getting the bulk descriptor and starting the initialization
	*/
	if ( (retcode = blk_alloc(connection, EX_BULK_VERSION, &blkdesc)) != CS_SUCCEED)
	{
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
		return -1;
	}

	if (blk_init(blkdesc, CS_BLK_OUT, tablename, CS_NULLTERM) == CS_FAIL)
	{
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
	}

	/*
	** Now to bind the variables to the columns and transfer the data
	*/
	datafmt.datatype = CS_CHAR_TYPE;
    datafmt.format   = CS_FMT_NULLTERM;
    datafmt.maxlength= 16;
	datafmt.count    = MAX_ROWS_ONETIME;
    datafmt.locale   = 0;//
    if (blk_bind(blkdesc, FIELD_AreaCode, &datafmt, areaCode_fieldBuf, areaCode_bufLen, areaCode_indBuf) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }
    //
	datafmt.datatype = CS_CHAR_TYPE;
    datafmt.format   = CS_FMT_NULLTERM;
    datafmt.maxlength= 32;
    if (blk_bind(blkdesc, FIELD_Prefix, &datafmt, prefix_fieldBuf, prefix_bufLen, prefix_indBuf) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }
    //
	datafmt.datatype = CS_DATETIME_TYPE;
    datafmt.format   = CS_FMT_UNUSED;
    datafmt.maxlength= CS_SIZEOF(CS_DATETIME);
    if (blk_bind(blkdesc, FIELD_UpdateTime, &datafmt, updateTime_fieldBuf, updateTime_bufLen, updateTime_indBuf) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }
    //
	datafmt.datatype = CS_TINYINT_TYPE;
    datafmt.format   = CS_FMT_UNUSED;
    datafmt.maxlength= CS_SIZEOF(CS_TINYINT);
    if (blk_bind(blkdesc, FIELD_SARNumber, &datafmt, sarNumber_fieldBuf, sarNumber_bufLen, sarNumber_indBuf) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }
    //
    if (blk_bind(blkdesc, FIELD_ExchangeHouse, &datafmt, exchangeHouse_fieldBuf, exchangeHouse_bufLen, exchangeHouse_indBuf) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    //if (blk_rowxfer_mult(blkdesc, &numrows) == CS_FAIL)
	while( (retcode = blk_rowxfer_mult(blkdesc, &numrows)) == CS_SUCCEED ||
           retcode == CS_ROW_FAIL)
    {
        copiedRowCnt += numrows;
        //
        for(int ii = 0; ii < numrows; ++ii)
        {
            //
            stNumPrefix prefix;
            prefix.prefixLen = strlen(prefix_fieldBuf[ii]);
            memcpy(prefix.szPrefix, prefix_fieldBuf[ii], prefix.prefixLen);
            prefix.areaCodeLen = strlen(areaCode_fieldBuf[ii]);
            memcpy(prefix.szAreaCode, areaCode_fieldBuf[ii], prefix.areaCodeLen);
            prefix.adminCenterId = sarNumber_fieldBuf[ii];
            prefix.switchCenterId = exchangeHouse_fieldBuf[ii];
            m_pParentThread->addNumPrefix(prefix);
        }
    }
    //
    if(retcode != CS_END_DATA)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        retcode = CS_FAIL;
    }

	/*
	** ALL the rows sent so clear up
	*/
    CS_INT blktype = copiedRowCnt > 0 ? CS_BLK_ALL : CS_BLK_CANCEL;
	if ( (retcode = blk_done(blkdesc, blktype, &numrows)) == CS_FAIL)
	{
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
	}
	if ( (retcode = blk_drop(blkdesc)) == CS_FAIL)
	{
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
	}

    return retcode == CS_SUCCEED ? copiedRowCnt : -1;
}
コード例 #6
0
/**
*   @brief bulk copy data from TBL_ImsiMsisdn
*/
int CSybClient::bulkCopyOut_ImsiMsisdn(int connId, char* tablename)
{
    CS_CONNECTION *connection = getConnection(connId);
    if(NULL == connection || NULL == tablename) return -1;

    CLEAR_ALL_MESSAGE(connection);

    int copiedRowCnt = 0;
    CS_RETCODE retcode;

    #define MAX_ROWS_ONETIME 1024
    #define FIELD_IMSI 1
    #define FIELD_MSISDN  2

    CS_BLKDESC  *blkdesc;
    CS_DATAFMT  datafmt;                    /* hold the variable descriptions */
    CS_CHAR  msisdn_fieldbuf[MAX_ROWS_ONETIME][32];   /* point to the data for transfer */
    CS_SMALLINT msisdn_fieldind[MAX_ROWS_ONETIME];
    CS_INT      msisdn_fieldlen[MAX_ROWS_ONETIME];
    //
    CS_CHAR  imsi_fieldbuf[MAX_ROWS_ONETIME][16];
    CS_SMALLINT imsi_fieldind[MAX_ROWS_ONETIME];
    CS_INT   imsi_fieldlen[MAX_ROWS_ONETIME];
    //
    CS_INT      numrows = MAX_ROWS_ONETIME;


    /*
    ** Ready to start the bulk copy in now that all the connections
    ** have been made and have a table name.
    **
    ** Start by getting the bulk descriptor and starting the initialization
    */
    if ( (retcode = blk_alloc(connection, EX_BULK_VERSION, &blkdesc)) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        return -1;
    }

    if (blk_init(blkdesc, CS_BLK_OUT, tablename, CS_NULLTERM) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    /*
    ** Now to bind the variables to the columns and transfer the data
    */

    datafmt.datatype = CS_CHAR_TYPE;
    datafmt.format   = CS_FMT_NULLTERM;
    datafmt.maxlength= 16;
    datafmt.count    = MAX_ROWS_ONETIME;
    datafmt.locale   = 0;//
    if (blk_bind(blkdesc, FIELD_IMSI, &datafmt, imsi_fieldbuf, imsi_fieldlen, imsi_fieldind) != CS_SUCCEED) // bind IMSI field
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }
    //
    datafmt.maxlength= 32;
    //
    if (blk_bind(blkdesc, FIELD_MSISDN, &datafmt, msisdn_fieldbuf, msisdn_fieldlen, msisdn_fieldind) != CS_SUCCEED) // bind MSISDN field
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    while( (retcode = blk_rowxfer_mult(blkdesc, &numrows)) == CS_SUCCEED ||
           retcode == CS_ROW_FAIL)
    {
        copiedRowCnt += numrows;
        for(int ii = 0; ii < numrows; ++ii)
        {
            stIMSI imsi;
            stMSISDN msisdn;
            imsi.m_ucIMSILen = strlen(imsi_fieldbuf[ii]);
            memcpy(imsi.m_szIMSI, imsi_fieldbuf[ii], imsi.m_ucIMSILen);
            msisdn.ucLen = strlen(msisdn_fieldbuf[ii]);
            memcpy(msisdn.ucMSISDN, msisdn_fieldbuf[ii], msisdn.ucLen);
            m_pParentThread->addIMSI2MSISDN(msisdn, imsi);
        }
    }
    //
    if(retcode != CS_END_DATA)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        retcode = CS_FAIL;
    }

    /*
    ** ALL the rows sent so clear up
    */
    CS_INT blktype = copiedRowCnt > 0 ? CS_BLK_ALL : CS_BLK_CANCEL;
    if ( (retcode = blk_done(blkdesc, blktype, &numrows)) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
    }
    if ( (retcode = blk_drop(blkdesc)) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
    }

    return retcode == CS_SUCCEED ? copiedRowCnt : -1;
}
コード例 #7
0
/**
*   @brief bulk copy data from TBL_PrePaidArrears
*/
int CSybClient::bulkCopyOut_PrePaidArrears(int connId, char* tablename)
{
    CS_CONNECTION *connection = getConnection(connId);
    if(NULL == connection || NULL == tablename) return -1;

    CLEAR_ALL_MESSAGE(connection);

    int copiedRowCnt = 0;
    CS_RETCODE retcode;

    #define MAX_ROWS_ONETIME 1024
    #define FIELD_Msisdn     1
    #define FIELD_UpdateTime 2

    CS_BLKDESC  *blkdesc;
    CS_DATAFMT  datafmt;                    /* hold the variable descriptions */
    CS_CHAR     Msisdn_fieldbuf[MAX_ROWS_ONETIME][32];   /* point to the data for transfer */
    CS_DATETIME UpdateTime_fieldbuf[MAX_ROWS_ONETIME];
    CS_SMALLINT Msisdn_fieldind[MAX_ROWS_ONETIME];
    CS_SMALLINT UpdateTime_fieldind[MAX_ROWS_ONETIME];
    CS_INT      Msisdn_fieldlen[MAX_ROWS_ONETIME];
    CS_INT      UpdateTime_fieldlen[MAX_ROWS_ONETIME];
    CS_INT      numrows = MAX_ROWS_ONETIME;


    /*
    ** Ready to start the bulk copy in now that all the connections
    ** have been made and have a table name.
    **
    ** Start by getting the bulk descriptor and starting the initialization
    */
    if ( (retcode = blk_alloc(connection, EX_BULK_VERSION, &blkdesc)) != CS_SUCCEED)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        return -1;
    }

    if (blk_init(blkdesc, CS_BLK_OUT, tablename, CS_NULLTERM) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    /*
    ** Now to bind the variables to the columns and transfer the data
    */
    datafmt.datatype = CS_CHAR_TYPE;
    datafmt.format   = CS_FMT_NULLTERM;
    datafmt.maxlength= 32;
    datafmt.count    = MAX_ROWS_ONETIME;
    datafmt.locale   = 0;//
    if (blk_bind(blkdesc, FIELD_Msisdn, &datafmt, Msisdn_fieldbuf, Msisdn_fieldlen, Msisdn_fieldind) != CS_SUCCEED) // bind OriginalNumber field
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    //
    datafmt.datatype = CS_DATETIME_TYPE;
    datafmt.format   = CS_FMT_UNUSED;
    datafmt.maxlength= CS_SIZEOF(CS_DATETIME);
    datafmt.count    = MAX_ROWS_ONETIME;
    if (blk_bind(blkdesc, FIELD_UpdateTime, &datafmt, UpdateTime_fieldbuf, UpdateTime_fieldlen, UpdateTime_fieldind) != CS_SUCCEED) // bind ChangedNumber field
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        blk_drop(blkdesc);
        return -1;
    }

    //
    CS_DATEREC userdatetime;
    //
    while( (retcode = blk_rowxfer_mult(blkdesc, &numrows)) == CS_SUCCEED ||
           retcode == CS_ROW_FAIL)
    {
        copiedRowCnt += numrows;
        for(int ii = 0; ii < numrows; ++ii)
        {
            stNumKey num;
            num.numLen = strlen(Msisdn_fieldbuf[ii]);
            memcpy(num.num, Msisdn_fieldbuf[ii], num.numLen);
            m_pParentThread->addPrePaidNum(num);
        }
    }
    //
    if(retcode != CS_END_DATA)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
        retcode = CS_FAIL;
    }

    /*
    ** ALL the rows sent so clear up
    */
    CS_INT blktype = copiedRowCnt > 0 ? CS_BLK_ALL : CS_BLK_CANCEL;
    if ( (retcode = blk_done(blkdesc, blktype, &numrows)) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
    }
    if ( (retcode = blk_drop(blkdesc)) == CS_FAIL)
    {
        DIAG_CLIENT_MESSAGE(connection);
        DIAG_SERVER_MESSAGE(connection);
    }

    return retcode == CS_SUCCEED ? copiedRowCnt : -1;
}