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