예제 #1
0
bool CDBL_ComputeResult::Fetch()
{
    if (m_1stFetch) { // we didn't get the items yet;
        m_1stFetch = false;
        m_CurrItem= 0;
        return true;
    }

    STATUS s = Check(dbnextrow(GetCmd()));

    switch (s) {
    case REG_ROW:
    case NO_MORE_ROWS:
        *m_ResStatus ^= 0x10;
        break;
    case FAIL:
        DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 270003 );
    case BUF_FULL:
        DATABASE_DRIVER_ERROR( "Buffer is full." + GetDbgInfo(), 270006 );
    default:
        break;
    }

    m_EOR = true;
    m_CurrItem= -1;
    return false;
}
예제 #2
0
bool CODBC_RowResult::Fetch()
{
    m_CurrItem = -1;
    m_LastReadData.resize(0);
    m_HasMoreData = false;
    if (!m_EOR) {
        switch (SQLFetch(GetHandle())) {
        case SQL_SUCCESS_WITH_INFO:
            ReportErrors();
        case SQL_SUCCESS:
            m_CurrItem = 0;
            m_HasMoreData = true;
            if ( m_RowCountPtr != NULL ) {
                ++(*m_RowCountPtr);
            }
            return true;
        case SQL_NO_DATA:
            m_EOR = true;
            break;
        case SQL_ERROR:
            ReportErrors();
            {
                string err_message = "SQLFetch failed." + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430003 );
            }
        default:
            {
                string err_message = "SQLFetch failed (memory corruption suspected)." + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430004 );
            }
        }
    }
    return false;
}
예제 #3
0
CDBL_ComputeResult::CDBL_ComputeResult(CDBL_Connection& conn,
                                       DBPROCESS* cmd,
                                       unsigned int* res_stat) :
    CDBL_ResultBase(conn, cmd, res_stat)
{
    m_ComputeId = DBROWTYPE(cmd);
    if (m_ComputeId == REG_ROW || m_ComputeId == NO_MORE_ROWS) {
        DATABASE_DRIVER_ERROR( "No compute row found." + GetDbgInfo(), 270000 );
    }

    unsigned int col_num = Check(dbnumalts(cmd, m_ComputeId));

    if (col_num < 1) {
        DATABASE_DRIVER_ERROR( "Compute id is invalid." + GetDbgInfo(), 270001 );
    }

    m_CmdNum = DBCURCMD(cmd);
    m_ColFmt = new SDBL_ColDescr[col_num];
    for (unsigned int n = 0; n < col_num; n++) {
        m_ColFmt[n].max_length = Check(dbaltlen(GetCmd(), m_ComputeId, n+1));
        m_ColFmt[n].data_type = AltGetDataType(m_ComputeId, n + 1);
        int op = Check(dbaltop(GetCmd(), m_ComputeId, n + 1));
        const char* s = op != -1 ? Check(dbprtype(op)) : "Unknown";
        m_ColFmt[n].col_name = s ? s : "";

        m_CachedRowInfo.Add(
            s ? s : "",
            Check(dbaltlen(GetCmd(), m_ComputeId, n+1)),
            AltGetDataType(m_ComputeId, n + 1)
            );
    }

    m_1stFetch = true;
}
예제 #4
0
bool CDBL_BlobResult::Fetch()
{
    if (m_EOR)
        return false;

    STATUS s;
    if (m_CurrItem == 0) {
        while ((s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff)))) > 0) {
            ;
        }
        switch (s) {
        case 0:
            break;
        case NO_MORE_ROWS:
            m_EOR = true;
            return false;
        default:
            DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 280003 );
        }
    }
    else {
        m_CurrItem = 0;
    }

    s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff)));
    if (s == NO_MORE_ROWS)
        return false;
    if (s < 0) {
        DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 280003 );
    }
    m_BytesInBuffer= s;
    m_ReadedBytes= 0;
    return true;
}
예제 #5
0
bool CTL_RowResult::Fetch()
{
    SetCurrentItemNum(-1);
    if ( m_EOR ) {
        return false;
    }

    // Reset NullValue flags ...
    for (unsigned int nof_items = 0;  nof_items < GetDefineParams().GetNum();  ++nof_items) {
        m_NullValue[nof_items] = eNullUnknown;
    }

    CheckIsDead();

    switch ( Check(ct_fetch(x_GetSybaseCmd(), CS_UNUSED, CS_UNUSED, CS_UNUSED, 0)) ) {
    case CS_SUCCEED:
        SetCurrentItemNum(0);
        return true;
    case CS_END_DATA:
        m_EOR = true;
        return false;
    case CS_ROW_FAIL:
        DATABASE_DRIVER_ERROR( "Error while fetching the row." + GetDbgInfo(), 130003 );
    case CS_FAIL:
        DATABASE_DRIVER_ERROR("ct_fetch has failed. "
                              "You need to cancel the command." +
                              GetDbgInfo(),
                              130006 );
    case CS_CANCELED:
        DATABASE_DRIVER_ERROR( "The command has been canceled." + GetDbgInfo(), 130004 );
    default:
        DATABASE_DRIVER_ERROR( "The connection is busy." + GetDbgInfo(), 130005 );
    }
}
예제 #6
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;
}
예제 #7
0
bool CODBC_RPCCmd::xCheck4MoreResults()
{
//     int rc = CheckSIE(SQLMoreResults(GetHandle()),
//              "SQLMoreResults failed", 420015);
//
//     return (rc == SQL_SUCCESS_WITH_INFO || rc == SQL_SUCCESS);

    switch(SQLMoreResults(GetHandle())) {
    case SQL_SUCCESS_WITH_INFO: ReportErrors();
    case SQL_SUCCESS:           return true;
    case SQL_NO_DATA:           return false;
    case SQL_ERROR:
        ReportErrors();
        {
            string err_message = "SQLMoreResults failed." + GetDbgInfo();
            DATABASE_DRIVER_ERROR( err_message, 420014 );
        }
    default:
        {
            string err_message = "SQLMoreResults failed (memory corruption suspected)." +
                GetDbgInfo();
            DATABASE_DRIVER_ERROR( err_message, 420015 );
        }
    }
}
예제 #8
0
CODBC_RowResult::CODBC_RowResult(
    CStatementBase& stmt,
    SQLSMALLINT nof_cols,
    SQLLEN* row_count
    )
    : m_Stmt(stmt)
    , m_CurrItem(-1)
    , m_EOR(false)
    , m_RowCountPtr( row_count )
    , m_HasMoreData(false)
{
    odbc::TSqlChar column_name_buff[eODBC_Column_Name_Size];

    if(m_RowCountPtr) *m_RowCountPtr = 0;

    SQLSMALLINT actual_name_size;
    SQLSMALLINT nullable;

    m_ColFmt = new SODBC_ColDescr[nof_cols];
    for (unsigned int n = 0; n < (unsigned int)nof_cols; ++n) {
        // SQLDescribeCol takes a pointer to a buffer.
        switch(SQLDescribeCol(GetHandle(),
                              n + 1,
                              column_name_buff,
                              eODBC_Column_Name_Size * sizeof(odbc::TSqlChar),
                              &actual_name_size,
                              &m_ColFmt[n].DataType,
                              &m_ColFmt[n].ColumnSize,
                              &m_ColFmt[n].DecimalDigits,
                              &nullable)) {
        case SQL_SUCCESS_WITH_INFO:
            ReportErrors();
        case SQL_SUCCESS:
            m_ColFmt[n].ColumnName =
                CODBCString(column_name_buff,
                            actual_name_size).ConvertTo(GetClientEncoding());
            break;
        case SQL_ERROR:
            ReportErrors();
            {
                string err_message = "SQLDescribeCol failed." + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 420020 );
            }
        default:
            {
                string err_message = "SQLDescribeCol failed (memory corruption suspected)." + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 420021 );
            }
        }

        m_CachedRowInfo.Add(
            m_ColFmt[n].ColumnName,
            m_ColFmt[n].ColumnSize,
            s_GetDataType(m_ColFmt[n].DataType,
                          m_ColFmt[n].DecimalDigits,
                          m_ColFmt[n].ColumnSize)
            );
    }
}
예제 #9
0
CDB_Object* CDBL_BlobResult::GetItem(CDB_Object* item_buff, I_Result::EGetItem policy)
{
    if (m_CurrItem)
        return 0;

    EDB_Type b_type = item_buff ? item_buff->GetType() : eDB_UnsupportedType;

    if (item_buff && b_type != eDB_Text && b_type != eDB_Image) {
        DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 230020 );
    }

    CDB_Stream* val = NULL;

    if (item_buff) {
            val = static_cast<CDB_Stream*>(item_buff);

            if (policy == I_Result::eAssignLOB) {
                    // Explicitly truncate previous value ...
                    val->Truncate();
            }
    } else if (m_ColFmt.data_type == eDB_Text) {
            val = new CDB_Text;
    } else {
            val = new CDB_Image;
    }

    _ASSERT(val);


    // check if we do have something in buffer
    if(m_ReadedBytes < m_BytesInBuffer) {
        val->Append(m_Buff + m_ReadedBytes, m_BytesInBuffer - m_ReadedBytes);
        m_ReadedBytes= m_BytesInBuffer;
    }

    if(m_BytesInBuffer == 0) {
        return item_buff;
    }


    STATUS s;
    while ((s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff)))) > 0) {
        val->Append(m_Buff, (size_t(s) < sizeof(m_Buff))? size_t(s) : sizeof(m_Buff));
    }

    switch (s) {
    case NO_MORE_ROWS:
        m_EOR = true;
    case 0:
        m_CurrItem = 1;
        break;
    default:
        DATABASE_DRIVER_ERROR( "dbreadtext failed." + GetDbgInfo(), 280003 );
    }

    return item_buff;
}
예제 #10
0
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;
}
예제 #11
0
bool CODBC_RowResult::CheckSIENoD_Binary(CDB_Stream* val)
{
    SQLLEN f = 0;
    char buffer[8*1024];

    switch(SQLGetData(GetHandle(), m_CurrItem+1, SQL_C_BINARY, buffer, sizeof(buffer), &f)) {
    case SQL_SUCCESS_WITH_INFO:
        if(f == SQL_NO_TOTAL || f > SQLLEN(sizeof(buffer))) f = sizeof(buffer);
        else ReportErrors();
    case SQL_SUCCESS:
        if(f > 0) {
            if(f > SQLLEN(sizeof(buffer))) f = sizeof(buffer);
            val->Append(buffer, f);
        }
        return true;
    case SQL_NO_DATA:
        break;
    case SQL_ERROR:
        ReportErrors();
    default:
        {
            DATABASE_DRIVER_ERROR(
                string("SQLGetData failed while retrieving BLOB into C") +
                CDB_Object::GetTypeName(val->GetType()) + '.',
                430022);
        }
    }

    return false;
}
예제 #12
0
BEGIN_NCBI_SCOPE

#define DBDATETIME4_days(x) ((x)->numdays)
#define DBDATETIME4_mins(x) ((x)->nummins)
#define DBNUMERIC_val(x) ((x)->val)
#define SQL_VARLEN_DATA (-10)

/////////////////////////////////////////////////////////////////////////////
//
//  CODBC_BCPInCmd::
//

CODBC_BCPInCmd::CODBC_BCPInCmd(CODBC_Connection& conn,
                               SQLHDBC           cmd,
                               const string&     table_name) :
    CStatementBase(conn, table_name),
    m_Cmd(cmd),
    m_HasTextImage(false),
    m_WasBound(false)
{
    string extra_msg = "Table Name: " + table_name;
    SetDbgInfo( extra_msg );

    if (bcp_init(cmd,
                 CODBCString(table_name, GetClientEncoding()).AsCWString(),
                 0, 0, DB_IN) != SUCCEED) {
        ReportErrors();
        string err_message = "bcp_init failed." + GetDbgInfo();
        DATABASE_DRIVER_ERROR( err_message, 423001 );
    }

    ++m_RowCount;
}
예제 #13
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;
}
예제 #14
0
int CODBC_RowResult::xGetData(SQLSMALLINT target_type, SQLPOINTER buffer,
                              SQLINTEGER buffer_size)
{
    SQLLEN f;

    switch(SQLGetData(GetHandle(), m_CurrItem+1, target_type, buffer, buffer_size, &f)) {
    case SQL_SUCCESS_WITH_INFO:
        switch(f) {
        case SQL_NO_TOTAL:
            return buffer_size;
        case SQL_NULL_DATA:
            return 0;
        default:
            if(f < 0)
                ReportErrors();
            return (int)f;
        }
    case SQL_SUCCESS:
        if(target_type == SQL_C_CHAR) buffer_size--;
        return (f > buffer_size)? buffer_size : (int)f;
    case SQL_NO_DATA:
        return 0;
    case SQL_ERROR:
        ReportErrors();
    default:
        {
            string err_message = "SQLGetData failed." + GetDbgInfo();
            DATABASE_DRIVER_ERROR( err_message, 430027 );
        }
    }
}
예제 #15
0
void CTL_BCPInCmd::AddHint(CDB_BCPInCmd::EBCP_Hints hint, unsigned int value)
{
#ifdef FTDS_IN_USE
    string str_hint;
    bool need_value = false;
    switch (hint) {
    case CDB_BCPInCmd::eRowsPerBatch:
        str_hint = "ROWS_PER_BATCH";
        need_value = true;
        break;
    case CDB_BCPInCmd::eKilobytesPerBatch:
        str_hint = "KILOBYTES_PER_BATCH";
        need_value = true;
        break;
    case CDB_BCPInCmd::eTabLock:
        str_hint = "TABLOCK";
        break;
    case CDB_BCPInCmd::eCheckConstraints:
        str_hint = "CHECK_CONSTRAINTS";
        break;
    case CDB_BCPInCmd::eFireTriggers:
        str_hint = "FIRE_TRIGGERS";
        break;
    default:
        DATABASE_DRIVER_ERROR("Wrong hint type in AddHint." + GetDbgInfo(), 123015);
    }
    if (need_value) {
        if (value == 0) {
            DATABASE_DRIVER_ERROR("Value in AddHint should not be 0."
                                  + GetDbgInfo(), 123016);
        }
        str_hint += "=";
        str_hint += NStr::IntToString(value);
    }
    else if (value != 0) {
        DATABASE_DRIVER_ERROR("Cannot set value for a given hint type ("
                              + NStr::IntToString(hint) + ")."
                              + GetDbgInfo(), 123016);
    }
    m_Hints[hint] = str_hint;

    x_BlkSetHints();
#else
    _ASSERT(false);
#endif
}
예제 #16
0
inline
void
CheckNULL(const CDB_Object& value)
{
    if (value.IsNULL()) {
        DATABASE_DRIVER_ERROR("Trying to access a NULL value.", 101100);
    }
}
예제 #17
0
const string& 
CDBBindedParams::GetName(
        const CDBParamVariant& param, 
        CDBParamVariant::ENameFormat format) const
{
    DATABASE_DRIVER_ERROR( "Methods GetName is not implemented yet.", 122002 );

    return kEmptyStr;
}
예제 #18
0
inline
void
CheckType(const CDB_Object& value, EDB_Type type1, EDB_Type type2)
{
    EDB_Type cur_type = value.GetType();

    if (!(cur_type == type1 || cur_type == type2)) {
        DATABASE_DRIVER_ERROR("Invalid type conversion.", 101100);
    }
}
예제 #19
0
void CTL_BCPInCmd::SetHints(CTempString hints)
{
#ifdef FTDS_IN_USE
    m_Hints.clear();
    if (Check(blk_sethints(x_GetSybaseCmd(), (CS_CHAR*)hints.data(), CS_INT(hints.size()))) == CS_FAIL) {
        DATABASE_DRIVER_ERROR("blk_sethints failed." + GetDbgInfo(), 123018);
    }
#else
    _ASSERT(false);
#endif
}
예제 #20
0
static
void
ReportTypeConvError(EDB_Type from_type, const char* to_type)
{
    string err_str("Cannot convert type " );
    err_str += CDB_Object::GetTypeName(from_type);
    err_str += " to type ";
    err_str += to_type;
    
    DATABASE_DRIVER_ERROR(err_str, 101100);
}
예제 #21
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;
}
예제 #22
0
unsigned int 
CDB_Params::GetParamNum(const string& param_name) const
{
    unsigned int param_no = 0;

    if (!GetParamNumInternal(param_name, param_no)) {
        // Parameter not found ...
        DATABASE_DRIVER_ERROR("Invalid parameter's name: " + param_name, 122510 );
    }

    return param_no;
}
예제 #23
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;
}
예제 #24
0
CDB_Object* CDBL_StatusResult::GetItem(CDB_Object* item_buff, I_Result::EGetItem /*policy*/)
{
    if (!item_buff)
        return new CDB_Int(m_Val);

    if (item_buff->GetType() != eDB_Int) {
        DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 230020 );
    }

    CDB_Int* i = (CDB_Int*) item_buff;
    *i = m_Val;
    return item_buff;
}
예제 #25
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;
}
예제 #26
0
void CTL_BCPInCmd::x_BlkSetHints(void)
{
#ifdef FTDS_IN_USE
    string hints;
    ITERATE(THintsMap, it, m_Hints) {
        if (!hints.empty())
            hints += ",";
        hints += it->second; 
    }
    if (Check(blk_sethints(x_GetSybaseCmd(), (CS_CHAR*)hints.data(), CS_INT(hints.size()))) == CS_FAIL) {
        DATABASE_DRIVER_ERROR("blk_sethints failed." + GetDbgInfo(), 123019);
    }
#endif
}
예제 #27
0
bool CTL_CursorResult::SkipItem()
{
    if (GetCurrentItemNum() < (int) GetDefineParams().GetNum()) {
        IncCurrentItemNum();
        char dummy[4];
        bool is_null = false;

        switch ( my_ct_get_data(x_GetSybaseCmd(), GetCurrentItemNum(), dummy, 0, 0, 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 );
        }

        return true;
    }

    return false;
}
예제 #28
0
// Aux. for CDBL_ParamResult::GetItem()
// CDB_Image and CDB_Text are not handled by this function ...
CDB_Object* CDBL_Result::RetGetItem(int item_no,
                                    SDBL_ColDescr* fmt,
                                    CDB_Object* item_buff)
{
    EDB_Type b_type = item_buff ? item_buff->GetType() : eDB_UnsupportedType;
    const BYTE* d_ptr = Check(dbretdata(GetCmd(), item_no));
    DBINT d_len = Check(dbretlen (GetCmd(), item_no));
    CDB_Object* val = s_GenericGetItem(fmt->data_type, item_buff,
                                       b_type, d_ptr, d_len);
    if (!val) {
        DATABASE_DRIVER_ERROR( "Unexpected result type." + GetDbgInfo(), 230004 );
    }
    return val;
}
예제 #29
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();
}
예제 #30
0
I_BlobDescriptor*
CDBL_Connection::x_GetNativeBlobDescriptor(const CDB_BlobDescriptor& descr_in)
{
    string q, tpsql = "TEXTPTR(" + descr_in.ColumnName() + ')';
    
    q  = "update " + descr_in.TableName() + " set " + descr_in.ColumnName();
    q += " = NULL where ";
    q += '(' + descr_in.SearchConditions() + ')';
    q += " and (" + tpsql + " is null";
    q += " or RIGHT(" + tpsql + ", 8) = 0x0000000000000000)\n";
    q += "select top 1 ";
    q += descr_in.ColumnName();
    q += ", TEXTPTR(" + descr_in.ColumnName() + ")";
    q += " from ";
    q += descr_in.TableName();
    q += " where ";
    q += descr_in.SearchConditions();

    CDB_LangCmd* lcmd= LangCmd(q);
    if(!lcmd->Send()) {
        DATABASE_DRIVER_ERROR( "Cannot send the language command." + GetDbgInfo(), 210035 );
    }

    I_BlobDescriptor* descr = NULL;
    bool i;

    while(lcmd->HasMoreResults()) {
        unique_ptr<CDB_Result> res( lcmd->Result() );
        if(res.get() == 0) continue;
        if((res->ResultType() == eDB_RowResult) && (descr == 0)) {
            EDB_Type tt= res->ItemDataType(0);
            if (CDB_Object::IsBlobType(tt)) {
                while(res->Fetch()) {
                    res->ReadItem(&i, 1);

                    descr = new CDBL_BlobDescriptor
                        (*this, GetDBLibConnection(), descr_in);
                    // descr = res->GetBlobDescriptor();
                    if(descr) {
                        break;
                    }
                }
            }
        }
    }
    delete lcmd;

    return descr;
}