bool g_FixMisplacedPID(CJsonNode& stat_info, CTempString& executable_path, const char* pid_key) { SIZE_TYPE misplaced_pid = NStr::Find(executable_path, "; PID: "); if (misplaced_pid == NPOS) return false; SIZE_TYPE pos = misplaced_pid + sizeof("; PID: ") - 1; stat_info.SetInteger(pid_key, NStr::StringToInt8( CTempString(executable_path.data() + pos, executable_path.length() - pos))); executable_path.erase(misplaced_pid); return true; }
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 }
string CDBParamVariant::MakePlainName(const CTempString& name) { // Do not make copy of name to process it ... CTempString plain_name; CTempString::const_iterator begin_str = NULL, c = name.data(); for (; c != NULL && c != name.end(); ++c) { char ch = *c; if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') { if (begin_str == NULL) { // Remove whitespaces ... continue; } else { // Look forward for non-space characters. bool space_chars_only = true; for (const char* tc = c; tc != NULL && *tc != '\0'; ++tc) { char tch = *tc; if (tch == ' ' || tch == '\t' || tch == '\n' || tch == '\r') { continue; } else { space_chars_only = false; break; } } if (space_chars_only) { // Remove trailing whitespace ... break; } } } // Check for leading symbol ... if (begin_str == NULL) { begin_str = c; if (ch == ':' || ch == '@' || ch == '$' || ch == '%') { // Skip leading symbol ... ++begin_str; } } } if (begin_str != NULL) { plain_name.assign(begin_str, c - begin_str); } return plain_name; }
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; }
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); }
BEGIN_NCBI_SCOPE static void NormalizeStatKeyName(CTempString& key) { char* begin = const_cast<char*>(key.data()); char* end = begin + key.length(); while (begin < end && !isalnum(*begin)) ++begin; while (begin < end && !isalnum(end[-1])) --end; if (begin == end) { key = "_"; return; } key.assign(begin, end - begin); for (; begin < end; ++begin) *begin = isalnum(*begin) ? tolower(*begin) : '_'; }
void Reset(const CTempString& line) { const char* line_buf = line.data(); Reset(line_buf, line_buf + line.size()); }
inline CLightString::CLightString(const CTempString& str) : m_String(str.data()), m_Length(str.length()) { }
CRef<CSeq_entry> CShortReadFastaInputSource::x_ReadFastqOneSeq(CRef<ILineReader> line_reader) { CTempString line; CTempString id; CRef<CSeq_entry> retval; // first read defline ++(*line_reader); line = **line_reader; // skip empty lines while (!line_reader->AtEOF() && line.empty()) { ++(*line_reader); line = **line_reader; } if (line[0] != '@') { NCBI_THROW(CInputException, eInvalidInput, (string)"FASTQ parse error:" " defline expected at line: " + NStr::IntToString(line_reader->GetLineNumber())); } id = x_ParseDefline(line); CRef<CSeq_id> seqid(new CSeq_id); seqid->Set(CSeq_id::e_Local, id); // read sequence ++(*line_reader); line = **line_reader; // skip empty lines while (!line_reader->AtEOF() && line.empty()) { ++(*line_reader); line = **line_reader; } // set up sequence if (line.length() > 0) { CRef<CSeq_entry> seq_entry(new CSeq_entry); CBioseq& bioseq = seq_entry->SetSeq(); bioseq.SetInst().SetMol(CSeq_inst::eMol_na); bioseq.SetInst().SetRepr(CSeq_inst::eRepr_raw); bioseq.SetId().clear(); bioseq.SetId().push_back(seqid); bioseq.SetInst().SetLength(line.length()); bioseq.SetInst().SetSeq_data().SetIupacna(CIUPACna(line.data())); bioseq.SetDescr(); m_BasesAdded += line.length(); retval = seq_entry; } // read and skip second defline ++(*line_reader); line = **line_reader; // skip empty lines while (!line_reader->AtEOF() && line.empty()) { ++(*line_reader); line = **line_reader; } if (line[0] != '+') { NCBI_THROW(CInputException, eInvalidInput, (string)"FASTQ parse error:" " defline expected at line: " + NStr::IntToString(line_reader->GetLineNumber())); } // read and skip quality scores ++(*line_reader); line = **line_reader; // skip empty lines while (!line_reader->AtEOF() && line.empty()) { ++(*line_reader); line = **line_reader; } return retval; }
CTempString CDBParamVariant::MakeName(const CTempString& name, CDBParamVariant::ENameFormat& format) { // Do not make copy of name to process it ... CTempString new_name; CTempString::const_iterator begin_str = NULL, c = name.data(); format = ePlainName; for (; c != NULL && c != name.end(); ++c) { char ch = *c; if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') { if (begin_str == NULL) { // Remove whitespace ... continue; } else { // Look forward for non-space characters. bool space_chars_only = true; for (const char* tc = c; tc != NULL && *tc != '\0'; ++tc) { char tch = *tc; if (tch == ' ' || tch == '\t' || tch == '\n' || tch == '\r') { continue; } else { space_chars_only = false; break; } } if (space_chars_only) { // Remove trailing whitespace ... break; } } } // Check for leading symbol ... if (begin_str == NULL) { begin_str = c; switch (ch) { case '?' : format = eQMarkName; break; case ':' : if (*(c + 1)) { if (isdigit(*(c + 1))) { format = eNumericName; } else { format = eNamedName; } } else { DATABASE_DRIVER_ERROR("Invalid parameter format.", 1); } break; case '@' : format = eSQLServerName; break; case '%' : format = eFormatName; break; case '$' : // !!!! format = eFormatName; break; } } } if (begin_str != NULL) { new_name.assign(begin_str, c - begin_str); } return new_name; }
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; }