00001
00002
00003
00004
00005
00006 #include <sstream>
00007
00008 #include "DatabaseInterface/DbiFieldType.h"
00009 #include "DatabaseInterface/DbiOutRowStream.h"
00010 #include "DatabaseInterface/DbiTableMetaData.h"
00011 #include "LeakChecker/Lea.h"
00012 #include "MessageService/MsgService.h"
00013 #include "Util/UtilString.h"
00014 #include "Validity/VldTimeStamp.h"
00015
00016 ClassImp(DbiOutRowStream)
00017
00018 #define OUT(t,v) \
00019 if ( ! StoreDefaultIfInvalid(t) ) { \
00020 ostringstream out; \
00021 out << setprecision(16)<< v; \
00022 Store(out.str()); \
00023 } \
00024
00025
00026
00027
00028
00029 #define OUT2(t,v) \
00030 const DbiFieldType& fType = this->ColFieldType(this->CurColNum()); \
00031 if ( fType.IsSigned() && fType.GetSize() != 8 ) { \
00032 Int_t v_signed = (Int_t) v; \
00033 if ( fType.GetType() == Dbi::kTiny && v & 0x80 ) v_signed |= 0xffffff00; \
00034 if ( fType.GetType() == Dbi::kShort && v & 0x8000 ) v_signed |= 0xffff0000; \
00035 OUT(Dbi::kInt,v_signed); } \
00036 else { \
00037 OUT(t,v); \
00038 } \
00039
00040
00041
00042
00043 CVSID("$Id: DbiOutRowStream.cxx,v 1.19 2006/08/08 10:51:32 west Exp $");
00044
00045
00046
00047
00048
00049
00050
00051
00052 DbiOutRowStream::DbiOutRowStream(const DbiTableMetaData* metaData) :
00053 DbiRowStream(metaData),
00054 fBadData(kFALSE)
00055 {
00056
00057
00058
00059
00060
00061
00062
00063 LEA_CTOR
00064
00065 MSG("Dbi", Msg::kVerbose) << "Creating DbiOutRowStream" << endl;
00066
00067 }
00068
00069
00070
00071
00072 DbiOutRowStream::~DbiOutRowStream() {
00073
00074
00075
00076
00077 LEA_DTOR
00078
00079 MSG("Dbi", Msg::kVerbose) << "Destroying DbiOutRowStream" << endl;
00080
00081 }
00082
00083
00084
00085 DbiOutRowStream& DbiOutRowStream::operator<<(Bool_t src) {
00086 OUT(Dbi::kBool,src); return *this;}
00087
00088 DbiOutRowStream& DbiOutRowStream::operator<<(Char_t src) {
00089 OUT(Dbi::kChar,src); return *this;}
00090
00091 DbiOutRowStream& DbiOutRowStream::operator<<(const Char_t* src) {
00092 OUT(Dbi::kString,src); return *this;}
00093
00094 DbiOutRowStream& DbiOutRowStream::operator<<(Short_t src) {
00095 OUT(Dbi::kShort,src); return *this;}
00096
00097 DbiOutRowStream& DbiOutRowStream::operator<<(UShort_t src) {
00098 OUT2(Dbi::kUShort,src); return *this;}
00099
00100 DbiOutRowStream& DbiOutRowStream::operator<<(Int_t src) {
00101 OUT(Dbi::kInt,src); return *this;}
00102
00103 DbiOutRowStream& DbiOutRowStream::operator<<(UInt_t src) {
00104 OUT2(Dbi::kUInt,src); return *this;}
00105
00106 DbiOutRowStream& DbiOutRowStream::operator<<(Float_t src) {
00107 OUT(Dbi::kFloat,src); return *this;}
00108
00109 DbiOutRowStream& DbiOutRowStream::operator<<(Double_t src) {
00110 OUT(Dbi::kDouble,src); return *this;}
00111
00112 DbiOutRowStream& DbiOutRowStream::operator<<(const string& src) {
00113 OUT(Dbi::kString,src); return *this;}
00114
00115 DbiOutRowStream& DbiOutRowStream::operator<<(const VldTimeStamp& src) {
00116 if ( ! StoreDefaultIfInvalid(Dbi::kDate) )
00117 Store(Dbi::MakeDateTimeString(src).c_str());
00118 return *this;
00119 }
00120
00121
00122
00123
00124
00125
00126 Bool_t DbiOutRowStream::StoreDefaultIfInvalid(Dbi::DataTypes type) {
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 DbiFieldType typeSupplied(type);
00151 DbiFieldType typeRequired(CurColFieldType());
00152 if ( typeSupplied.IsCompatible(typeRequired) ) return kFALSE;
00153
00154 string udef = typeRequired.UndefinedValue();
00155 MAXMSG("Dbi",Msg::kError,20)
00156 << "In table " << TableNameTc()
00157 << " column "<< CurColNum()
00158 << " (" << CurColName() << ")"
00159 << " of type " << typeRequired.AsString()
00160 << " is incompatible with user type " << typeSupplied.AsString()
00161 << ", value \"" << udef
00162 << "\" will be substituted." << endl;
00163 Store(udef.c_str());
00164 fBadData = kTRUE;
00165 return kTRUE;
00166
00167 }
00168
00169
00170 void DbiOutRowStream::Store(const string& str) {
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 UInt_t concept = CurColFieldType().GetConcept();
00197 string delim = "";
00198 if ( concept == Dbi::kString
00199 || concept == Dbi::kDate
00200 || concept == Dbi::kChar ) delim = "\'";
00201
00202 if ( CurColNum()> 1 ) fCSV += ',';
00203 fCSV += delim;
00204 if ( concept != Dbi::kString ) fCSV += str;
00205
00206 else {
00207 UtilString::MakePrintable(str.c_str(),fCSV);
00208 }
00209 fCSV += delim;
00210 IncrementCurCol();
00211 }
00212