string CVariant::GetString(void) const { string s(""); if( IsNull() ) { switch( GetType() ) { case eDB_TinyInt: case eDB_SmallInt: case eDB_Int: case eDB_BigInt: case eDB_Numeric: s = "0"; break; case eDB_Float: case eDB_Double: s = "0.0"; break; default: break; } } else { switch( GetType() ) { case eDB_Char: case eDB_VarChar: case eDB_LongChar: s = ((CDB_String*)GetData())->Value(); break; case eDB_Binary: { CDB_Binary *b = (CDB_Binary*)GetData(); s = string((char*)b->Value(), b->Size()); break; } case eDB_LongBinary: { CDB_LongBinary *vb = (CDB_LongBinary*)GetData(); s = string((char*)vb->Value(), vb->DataSize()); break; } case eDB_VarBinary: { CDB_VarBinary *vb = (CDB_VarBinary*)GetData(); s = string((char*)vb->Value(), vb->Size()); break; } case eDB_TinyInt: s = NStr::IntToString(GetByte()); break; case eDB_SmallInt: s = NStr::IntToString(GetInt2()); break; case eDB_Int: s = NStr::IntToString(GetInt4()); break; case eDB_BigInt: s = NStr::Int8ToString(GetInt8()); break; case eDB_Float: s = NStr::DoubleToString(GetFloat()); break; case eDB_Double: s = NStr::DoubleToString(GetDouble()); break; case eDB_Bit: s = NStr::BoolToString(GetBit()); break; case eDB_Numeric: s = ((CDB_Numeric*)GetData())->Value(); break; case eDB_DateTime: case eDB_SmallDateTime: s = GetCTime().AsString(); break; case eDB_Text: case eDB_Image: { CDB_Stream* stream = (CDB_Stream*)GetData(); char* buff[4096]; size_t read_bytes = 0; s.reserve(stream->Size()); while ((read_bytes = stream->Read(buff, sizeof(buff))) != 0) { s.append((const char*) buff, read_bytes); if (read_bytes < sizeof(buff)) { break; } } } break; default: x_Verify_AssignType(eDB_UnsupportedType, "string"); break; } } return s; }
bool CDBL_Connection::x_SendData(I_BlobDescriptor& descr_in, CDB_Stream& stream, bool log_it) { size_t size = stream.Size(); if (size < 1) return false; x_SetExtraMsg(descr_in, size); I_BlobDescriptor* p_desc= 0; // check what type of descriptor we've got if(descr_in.DescriptorType() != CDBL_BLOB_DESCRIPTOR_TYPE_MAGNUM){ // this is not a native descriptor p_desc = x_GetNativeBlobDescriptor (dynamic_cast<CDB_BlobDescriptor&>(descr_in)); if(p_desc == 0) return false; x_SetExtraMsg(*p_desc, size); } unique_ptr<I_BlobDescriptor> d_guard(p_desc); CDBL_BlobDescriptor& desc = p_desc ? dynamic_cast<CDBL_BlobDescriptor&>(*p_desc) : dynamic_cast<CDBL_BlobDescriptor&>(descr_in); char buff[1800]; // maximal page size if (size <= sizeof(buff)) { // we could write a blob in one chunk size_t s = stream.Read(buff, sizeof(buff)); if (Check(dbwritetext(GetDBLibConnection(), (char*) desc.m_ObjName.c_str(), desc.m_TxtPtr_is_NULL ? 0 : desc.m_TxtPtr, DBTXPLEN, desc.m_TimeStamp_is_NULL ? 0 : desc.m_TimeStamp, log_it ? TRUE : FALSE, (DBINT) s, (BYTE*) buff)) != SUCCEED) { DATABASE_DRIVER_ERROR( "dbwritetext failed." + GetDbgInfo(), 210030 ); } return true; } // write it in chunks if (Check(dbwritetext(GetDBLibConnection(), (char*) desc.m_ObjName.c_str(), desc.m_TxtPtr_is_NULL ? 0 : desc.m_TxtPtr, DBTXPLEN, desc.m_TimeStamp_is_NULL ? 0 : desc.m_TimeStamp, log_it ? TRUE : FALSE, (DBINT) size, 0)) != SUCCEED || Check(dbsqlok(GetDBLibConnection())) != SUCCEED || // dbresults(GetDBLibConnection()) == FAIL) { x_Results(GetDBLibConnection()) == FAIL) { DATABASE_DRIVER_ERROR( "dbwritetext/dbsqlok/dbresults failed." + GetDbgInfo(), 210031 ); } while (size > 0) { size_t s = stream.Read(buff, sizeof(buff)); if (s < 1) { Check(dbcancel(GetDBLibConnection())); DATABASE_DRIVER_ERROR("BLOB data corrupted." + GetDbgInfo(), 210032); } if (Check(dbmoretext(GetDBLibConnection(), (DBINT) s, (BYTE*) buff)) != SUCCEED) { Check(dbcancel(GetDBLibConnection())); DATABASE_DRIVER_ERROR( "dbmoretext failed." + GetDbgInfo(), 210033 ); } size -= s; } // if (dbsqlok(GetDBLibConnection()) != SUCCEED || dbresults(GetDBLibConnection()) == FAIL) { if (Check(dbsqlok(GetDBLibConnection())) != SUCCEED || x_Results(GetDBLibConnection()) == FAIL) { DATABASE_DRIVER_ERROR( "dbsqlok/dbresults failed." + GetDbgInfo(), 210034 ); } return true; }