예제 #1
0
bool CAuthor::x_GetLabelV2(string* label, TLabelFlags flags, CTempString name,
                           CTempString initials, CTempString suffix)
{
    if (name.empty()) {
        return false;
    }

    if (name.size() <= 6  &&  (SWNC(name, "et al")  ||  SWNC(name, "et,al"))) {
        name = "et al.";
        if (NStr::EndsWith(*label, " and ")) {
            label->replace(label->size() - 5, NPOS, ", ");
        }
    }

    SIZE_TYPE pos = label->size();
    *label += name;
    if (HasText(initials)) {
        *label += ',';
        *label += initials;
    }
    if (HasText(suffix)) {
        *label += ' ';
        *label += suffix;
    }

    if ((flags & fLabel_FlatEMBL) != 0) {
        NStr::ReplaceInPlace(*label, ",", " ", pos);
    }

    return true;
}
예제 #2
0
CBlastDbBlob::CBlastDbBlob(CTempString data, bool copy)
    : m_Owner(copy), m_ReadOffset(0), m_WriteOffset(0)
{
    if (m_Owner) {
        m_DataHere.assign(data.data(), data.data() + data.size());
    } else {
        m_DataRef = data;
    }
}
예제 #3
0
void CVDBCursor::SetParam(const char* name, const CTempString& value) const
{
    if ( rc_t rc = VCursorParamsSet
         ((struct VCursorParams *)GetPointer(),
          name, "%.*s", value.size(), value.data()) ) {
        NCBI_THROW2_FMT(CSraException, eNotFound,
                        "Cannot set VDB cursor param: "<<*this<<": "<<name,
                        rc);
    }
}
예제 #4
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
}
예제 #5
0
파일: util.cpp 프로젝트: DmitrySigaev/ncbi
///
/// This is the normative copy of the function
///
double ComputeNormalizedEntropy(const CTempString& sequence,
                               size_t word_size)
{
    typedef map<CTempString, double> TCounts;
    TCounts counts;
    double total = sequence.size() - word_size;
    for (size_t i = word_size;  i < sequence.size();  ++i) {
        CTempString t(sequence, i - word_size, word_size);
        TCounts::iterator it =
            counts.insert(TCounts::value_type(t, 0)).first;
        it->second += 1;
    }

    NON_CONST_ITERATE (TCounts, it, counts) {
        it->second /= total;
    }

    double entropy = 0;
    ITERATE (TCounts, it, counts) {
        entropy += it->second * log(it->second);
    }
예제 #6
0
inline
TSqlString x_MakeTSqlString(const CTempString& s, EEncoding enc)
{
#if defined(UNICODE)  ||  defined(_UNICODE)  ||  defined(UCS2)
    return CUtf8::AsBasicString<TSqlChar>(CUtf8::AsUTF8(s, enc));
#else
    if (enc == eEncoding_Unknown  ||  enc == eEncoding_UTF8) {
        return CUtf8::AsSingleByteString(CUtf8::AsUTF8(s, enc),
                                         eEncoding_ISO8859_1);
    } else {
        return CSqlString(s.data(), s.size());
    }
#endif
}
예제 #7
0
const char * CBlastDbBlob::x_ReadRaw(int size, int * offsetp) const
{
    _ASSERT(offsetp);
    _ASSERT(size >= 0);
    
    CTempString s = Str();
    
    int begin = *offsetp;
    int end = begin + size;
    
    if (begin > end || end > (int)s.size()) {
        NCBI_THROW(CSeqDBException,
                   eFileErr,
                   "CBlastDbBlob::x_ReadRaw: hit end of data");
    }
    
    *offsetp = end;
    return s.data() + begin;
}
예제 #8
0
CTempString CBlastDbBlob::x_ReadString(EStringFormat fmt, int * offsetp) const
{
    int sz = 0;
    
    if (fmt == eSize4) {
        sz = x_ReadIntFixed<int,4>(offsetp);
    } else if (fmt == eSizeVar) {
        sz = x_ReadVarInt(offsetp);
    }
    
    const char * datap = "";
    
    if (fmt == eNUL) {
        CTempString ts = Str();
        int zoffset = -1;
        
        for(size_t i = *offsetp; i < ts.size(); i++) {
            if (ts[i] == (char)0) {
                zoffset = i;
                break;
            }
        }
        
        if (zoffset == -1) {
            NCBI_THROW(CSeqDBException,
                       eFileErr,
                       "CBlastDbBlob::ReadString: Unterminated string.");
        }
        
        datap = ts.data() + *offsetp;
        sz = zoffset - *offsetp;
        *offsetp = zoffset+1;
    } else {
        datap = x_ReadRaw(sz, offsetp);
    }
    
    return CTempString(datap, sz);
}
예제 #9
0
Int8 CBlastDbBlob::x_ReadVarInt(int * offsetp) const
{
    CTempString all = Str();
    Int8 rv(0);
    
    for(size_t i = *offsetp; i < all.size(); i++) {
        int ch = all[i];
        
        if (ch & 0x80) {
            // middle
            rv = (rv << 7) | (ch & 0x7F);
        } else {
            // end
            rv = (rv << 6) | (ch & 0x3F);
            *offsetp = i+1;
            
            return (ch & 0x40) ? -rv : rv;
        }
    }
    
    NCBI_THROW(CSeqDBException,
               eFileErr,
               "CBlastDbBlob::ReadVarInt: eof while reading integer.");
}
예제 #10
0
 void Reset(const CTempString& line)
 {
     const char* line_buf = line.data();
     Reset(line_buf, line_buf + line.size());
 }
예제 #11
0
bool CODBC_BCPInCmd::x_AssignParams(void* pb)
{
    RETCODE r;

    if (!m_WasBound) {
        for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); ++i) {
            if (GetBindParamsImpl().GetParamStatus(i) == 0) {
                r = bcp_bind(GetHandle(), (BYTE*) pb, 0, SQL_VARLEN_DATA, 0, 0, 0, i + 1);
            }
            else {
                CDB_Object& param = *GetBindParamsImpl().GetParam(i);

                EDB_Type data_type = param.GetType();
                r = bcp_bind(GetHandle(),
                             static_cast<LPCBYTE>(const_cast<void*>(x_GetDataPtr(data_type, pb))),
                             0,
                             static_cast<DBINT>(x_GetBCPDataSize(data_type)),
                             static_cast<LPCBYTE>(x_GetDataTerminator(data_type)),
                             static_cast<INT>(x_GetDataTermSize(data_type)),
                             x_GetBCPDataType(data_type),
                             i + 1);

                m_HasTextImage = m_HasTextImage || (data_type == eDB_Image || data_type == eDB_Text);
            }

            if (r != SUCCEED) {
                ReportErrors();
                return false;
            }
        }

    GetBindParamsImpl().LockBinding();
        m_WasBound = true;
    }

    for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) {
        if (GetBindParamsImpl().GetParamStatus(i) == 0) {
            r = bcp_collen(GetHandle(), SQL_NULL_DATA, i + 1);
        }
        else {
            CDB_Object& param = *GetBindParamsImpl().GetParam(i);

            switch ( param.GetType() ) {
            case eDB_Bit:
                DATABASE_DRIVER_ERROR("Bit data type is not supported", 10005);
                break;
            case eDB_Int: {
                CDB_Int& val = dynamic_cast<CDB_Int&> (param);
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),  val.IsNULL() ? SQL_NULL_DATA : sizeof(Int4), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_SmallInt: {
                CDB_SmallInt& val = dynamic_cast<CDB_SmallInt&> (param);
                // DBSMALLINT v = (DBSMALLINT) val.Value();
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),  val.IsNULL() ? SQL_NULL_DATA : sizeof(Int2), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_TinyInt: {
                CDB_TinyInt& val = dynamic_cast<CDB_TinyInt&> (param);
                // DBTINYINT v = (DBTINYINT) val.Value();
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(), val.IsNULL() ? SQL_NULL_DATA : sizeof(Uint1), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_BigInt: {
                CDB_BigInt& val = dynamic_cast<CDB_BigInt&> (param);
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),  val.IsNULL() ? SQL_NULL_DATA : sizeof(Int8), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_Char:
            case eDB_VarChar:
            case eDB_LongChar: {
                CDB_String& val = dynamic_cast<CDB_String&> (param);
                CTempString data;

                if (val.IsNULL()) {
                    data.assign(static_cast<char*>(pb), 0);
                } else {
                    if (IsMultibyteClientEncoding()) {
                        const wstring& ws = val.AsWString(GetClientEncoding());
                        // hack
                        data.assign((const char*)(ws.data()),
                                    ws.size() * sizeof(wchar_t));
                    } else {
                        data = val.Value();
                    }
                }

                DBINT length;
                INT   dummy; // Can't just supply NULL
                if (val.IsNULL()) {
                    length = SQL_NULL_DATA;
                } else if (bcp_getcolfmt(GetHandle(), i + 1, BCP_FMT_DATA_LEN,
                                         &length, sizeof(length), &dummy)
                           == FAIL  ||  length < 0) {
                    length = SQL_VARLEN_DATA; // Be conservative.
                } else if (static_cast<SIZE_TYPE>(length) > data.size()) {
                    // Retain automatic truncation, which blindly supplying
                    // data.size() could lose.
                    length = data.size();
                }

                r = bcp_colptr(GetHandle(),
                               (BYTE*) data.data(),
                               i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),
                               length,
                               i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_Binary: {
                CDB_Binary& val = dynamic_cast<CDB_Binary&> (param);
                r = bcp_colptr(GetHandle(), (!val.IsNULL())? ((BYTE*) val.Value()) : (BYTE*)pb, i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),
                               val.IsNULL() ? SQL_NULL_DATA : (Int4) val.Size(), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_VarBinary: {
                CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param);
                r = bcp_colptr(GetHandle(), (!val.IsNULL())? ((BYTE*) val.Value()) : (BYTE*)pb, i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),
                               val.IsNULL() ? SQL_NULL_DATA : (Int4) val.Size(), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_LongBinary: {
                CDB_LongBinary& val = dynamic_cast<CDB_LongBinary&> (param);
                r = bcp_colptr(GetHandle(), (!val.IsNULL())? ((BYTE*) val.Value()) : (BYTE*)pb, i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),
                               val.IsNULL() ? SQL_NULL_DATA : (Int4) val.DataSize(), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_Float: {
                CDB_Float& val = dynamic_cast<CDB_Float&> (param);
                //DBREAL v = (DBREAL) val.Value();
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),  val.IsNULL() ? SQL_NULL_DATA : sizeof(float), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_Double: {
                CDB_Double& val = dynamic_cast<CDB_Double&> (param);
                //DBFLT8 v = (DBFLT8) val.Value();
                r = bcp_colptr(GetHandle(), (BYTE*) val.BindVal(), i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(),  val.IsNULL() ? SQL_NULL_DATA : sizeof(double), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
            }
            break;
            case eDB_SmallDateTime: {
                CDB_SmallDateTime& val =
                    dynamic_cast<CDB_SmallDateTime&> (param);
                DBDATETIM4* dt = (DBDATETIM4*) pb;
                DBDATETIME4_days(dt)     = val.GetDays();
                DBDATETIME4_mins(dt)     = val.GetMinutes();
                r = bcp_colptr(GetHandle(), (BYTE*) dt, i + 1)
                    == SUCCEED &&
                    bcp_collen(GetHandle(), val.IsNULL() ? SQL_NULL_DATA : sizeof(DBDATETIM4), i + 1)
                    == SUCCEED ? SUCCEED : FAIL;
                pb = (void*) (dt + 1);
            }
            break;
            case eDB_DateTime: {
                CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param);
                DBDATETIME* dt = (DBDATETIME*) pb;
                if (val.IsNULL()) {
                    r = bcp_colptr(GetHandle(), (BYTE*) dt, i + 1)
                        == SUCCEED &&
                        bcp_collen(GetHandle(), SQL_NULL_DATA, i + 1)
                        == SUCCEED ? SUCCEED : FAIL;
                }
                else {
                    dt->dtdays     = val.GetDays();
                    dt->dttime     = val.Get300Secs();
                    r = bcp_colptr(GetHandle(), (BYTE*) dt, i + 1)
                        == SUCCEED &&
                        bcp_collen(GetHandle(), sizeof(DBDATETIME), i + 1)
                        == SUCCEED ? SUCCEED : FAIL;
                }
                pb = (void*) (dt + 1);
            }
            break;
            case eDB_Text: {
                CDB_Text& val = dynamic_cast<CDB_Text&> (param);
                if (val.IsNULL()) {
                    r = bcp_colptr(GetHandle(), (BYTE*) pb, i + 1)
                        == SUCCEED &&
                        bcp_collen(GetHandle(),  SQL_NULL_DATA, i + 1)
                        == SUCCEED ? SUCCEED : FAIL;
                }
                else {
                    r = bcp_bind(GetHandle(), (BYTE*) NULL, 0, (DBINT) val.Size(),
                                 static_cast<LPCBYTE>(x_GetDataTerminator(eDB_Text)),
                                 static_cast<INT>(x_GetDataTermSize(eDB_Text)),
                                 x_GetBCPDataType(eDB_Text),
                                 i + 1);
                }
            }
            break;
            case eDB_Image: {
                CDB_Image& val = dynamic_cast<CDB_Image&> (param);
                // Null images doesn't work in odbc
                // (at least in those tests that exists in dbapi_unit_test)
                r = bcp_collen(GetHandle(),  (DBINT) val.Size(), i + 1);
            }
            break;
            default:
                return false;
            }
        }

        if (r != SUCCEED) {
            ReportErrors();
            return false;
        }
    }

    return true;
}