Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:22:01

0001 // $Id: TSQLTypes.h,v 1.1.1.1 2004/02/18 20:58:02 dave Exp $
0002 
0003 #ifndef RDBC_TSQLTypes_h
0004 #define RDBC_TSQLTypes_h
0005 
0006 //
0007 // TSQLTypes, TSQLDate, TSQLTime, TSQLTimestamp classes
0008 //
0009 
0010 #ifndef ROOT_TObject
0011 #include <TObject.h>
0012 #endif
0013 #ifndef ROOT_TString
0014 #include <TString.h>
0015 #endif
0016 #ifndef ROOT_TDatime
0017 #include <TDatime.h>
0018 #endif
0019 
0020 enum ESQLTypes { 
0021           kBIGINT = -5,
0022           kBINARY = -2,
0023           kBIT = -7,
0024           kCHAR = 1,
0025 #ifdef ODBC_VER_LESS_30 
0026           kDATE = 9,
0027           kTIME = 10,
0028           kTIMESTAMP = 11,
0029 #endif     
0030           kDATE = 91,
0031           kTIME = 92,
0032           kTIMESTAMP = 93,
0033           kSMALLINT = 5,
0034           kDECIMAL = 3,
0035           kDOUBLE = 8,
0036           kFLOAT = 6,
0037           kINTEGER = 4,
0038           kLONGVARBINARY = -4,
0039           kLONGVARCHAR = -1,
0040           kNUMERIC = 2,
0041           kREAL = 7,
0042           kTINYINT = -6,
0043           kVARBINARY = -3,
0044           kVARCHAR  = 12 
0045    };
0046 
0047 
0048 /////////////////////////////////////////////////////////////////////
0049 class TSQLDate: public TDatime
0050 {
0051 public:
0052 
0053    TSQLDate(Int_t year, Int_t month, Int_t day);
0054    TSQLDate():TDatime() {}
0055    TSQLDate(UInt_t t) { fDatime=t; } 
0056 //    TSQLDate(const TString& str);
0057    TSQLDate(const TSQLDate& d):TDatime(d) {}
0058    virtual ~TSQLDate() {}
0059     
0060     TSQLDate& operator=(const TSQLDate& d); 
0061 
0062 //    UInt_t GetTime() const { return Convert(); }
0063    Int_t GetYear() const { return  (fDatime>>26)+1995; }
0064    Int_t GetMonth() const { return (fDatime<<6)>>28; }
0065    Int_t GetDay() const { return (fDatime<<10)>>27; }
0066    void  SetYear(Int_t year);
0067    void  SetMonth(Int_t month);
0068    void  SetDay(Int_t day);
0069    TString ToString() const;
0070 
0071 ClassDef(TSQLDate,0) // allows to identify this as a SQL_DATE
0072 };
0073 
0074 /////////////////////////////////////////////////////////////////////
0075 class TSQLTime: public TDatime
0076 {
0077 public:
0078 
0079    TSQLTime(Int_t hour, Int_t minute, Int_t second);
0080    TSQLTime():TDatime() {}
0081    TSQLTime(UInt_t t) { fDatime=t; }
0082 //   TSQLTime(const TString& str);
0083    TSQLTime(const TSQLTime& t):TDatime(t) {}
0084    virtual ~TSQLTime() {}
0085 
0086    TSQLTime& operator=(const TSQLTime& d);
0087 
0088 //   UInt_t getTime() const { return Convert(); }    
0089    Int_t GetHour() const { return (fDatime<<15)>>27; }
0090    Int_t GetMinute() const { return (fDatime<<20)>>26; }
0091    Int_t GetSecond() const { return (fDatime<<26)>>26; }
0092    void  SetHour(Int_t h);
0093    void  SetMinute(Int_t m);
0094    void  SetSecond(Int_t s);
0095    TString ToString() const;
0096 
0097 ClassDef(TSQLTime,0) // allows to identify this as a SQL_TIME
0098 };
0099 
0100 /////////////////////////////////////////////////////////////////////
0101 class TSQLTimestamp: public TDatime
0102 {
0103 protected:
0104     Int_t fNanos; // nanoseconds
0105 
0106 public:
0107  
0108    TSQLTimestamp(Int_t year, Int_t month, Int_t day,
0109                  Int_t hour, Int_t minute, Int_t second, Int_t nanos =0) 
0110    { Set(year,month,day,hour,minute,second); SetNanos(nanos); }
0111    
0112    TSQLTimestamp():TDatime(),fNanos(0) {}
0113    TSQLTimestamp(UInt_t t):fNanos(0) { fDatime=t; }
0114 //   TSQLTimestamp(const TString& s);
0115    TSQLTimestamp(const TSQLTimestamp& t):TDatime(t),fNanos(0) {}
0116    virtual ~TSQLTimestamp() {}
0117    TSQLTimestamp& operator=(const TSQLTimestamp& d); 
0118 
0119 //   UInt_t GetTime() const { return Convert(); } 
0120    Int_t GetYear() const { return  (fDatime>>26)+1995; }
0121    Int_t GetMonth() const { return (fDatime<<6)>>28; }
0122    Int_t GetDay() const { return (fDatime<<10)>>27; }
0123    Int_t GetHour() const { return (fDatime<<15)>>27; }
0124    Int_t GetMinute() const { return (fDatime<<20)>>26; }
0125    Int_t GetSecond() const { return (fDatime<<26)>>26; }
0126    Int_t GetNanos() const { return fNanos; }  
0127    void  SetYear(Int_t year);
0128    void  SetMonth(Int_t month);
0129    void  SetDay(Int_t day);
0130    void  SetHour(Int_t h);
0131    void  SetMinute(Int_t m);
0132    void  SetSecond(Int_t s);
0133    void  SetNanos(Int_t nanos) { fNanos = nanos>0 ? nanos: 0; }
0134 //   Bool_t After(const TSQLTimestamp& t) const;
0135 //   Bool_t Before(const TSQLTimestamp& t) const;
0136 //   Bool_t Equals(const TSQLTimestamp& t) const;   
0137    TString ToString() const;
0138 
0139 ClassDef(TSQLTimestamp,0) // allows to identify this as a SQL_TIMESTAMP 
0140 };
0141 
0142 //___________________________________________________________________
0143 inline TSQLDate& TSQLDate::operator=(const TSQLDate& d) 
0144 {
0145    // Assignment operator
0146    
0147    fDatime = d.fDatime;
0148    return *this;
0149 }
0150 
0151 //___________________________________________________________________
0152 inline TSQLTime&  TSQLTime::operator=(const TSQLTime& d) 
0153 {
0154    // Assignment operator
0155    
0156    fDatime = d.fDatime;
0157    return *this;
0158 }
0159 
0160 //___________________________________________________________________
0161 inline TSQLTimestamp&  TSQLTimestamp::operator=(const TSQLTimestamp& d) 
0162 {
0163    // Assignment operator
0164    
0165    fDatime = d.fDatime;
0166    fNanos = d.fNanos; 
0167    return *this;
0168 }
0169 
0170 #endif //  RDBC_TSQLTypes_h