Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TSQLStructure.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/sql:$Id$
0002 // Author: Sergey Linev  20/11/2005
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TSQLStructure
0013 #define ROOT_TSQLStructure
0014 
0015 #include "TObjArray.h"
0016 
0017 #ifdef Bool
0018 #undef Bool
0019 #endif
0020 #ifdef True
0021 #undef True
0022 #endif
0023 #ifdef False
0024 #undef False
0025 #endif
0026 
0027 class TStreamerInfo;
0028 class TStreamerInfo;
0029 class TStreamerElement;
0030 class TSQLFile;
0031 class TSqlRegistry;
0032 class TSqlRawBuffer;
0033 class TSQLObjectData;
0034 class TSQLClassInfo;
0035 class TBufferSQL2;
0036 
0037 class TSQLColumnData final : public TObject {
0038 
0039 protected:
0040    TString fName;           ///<!  name of the table column
0041    TString fType;           ///<!  type of the table column
0042    TString fValue;          ///<!  value of the table column
0043    Bool_t fNumeric{kFALSE}; ///<!  for numeric quotes (double quotes) are not required
0044 public:
0045    TSQLColumnData(const char *name, const char *sqltype, const char *value, Bool_t numeric);
0046 
0047    TSQLColumnData(const char *name, Long64_t value);
0048 
0049    const char *GetName() const final { return fName.Data(); }
0050    const char *GetType() const { return fType.Data(); }
0051    const char *GetValue() const { return fValue.Data(); }
0052    Bool_t IsNumeric() const { return fNumeric; }
0053 
0054    ClassDefOverride(TSQLColumnData, 1); // Single SQL column data.
0055 };
0056 
0057 //______________________________________________________________________
0058 
0059 class TSQLTableData : public TObject {
0060 
0061 protected:
0062    TSQLFile *fFile{nullptr};      ///<!
0063    TSQLClassInfo *fInfo{nullptr}; ///<!
0064    TObjArray fColumns;            ///<! collection of columns
0065    TObjArray *fColInfos{nullptr}; ///<! array with TSQLClassColumnInfo, used later for TSQLClassInfo
0066 
0067    TString DefineSQLName(const char *fullname);
0068    Bool_t HasSQLName(const char *sqlname);
0069 
0070 public:
0071    TSQLTableData(TSQLFile *f = nullptr, TSQLClassInfo *info = nullptr);
0072    ~TSQLTableData() override;
0073 
0074    void AddColumn(const char *name, Long64_t value);
0075    void AddColumn(const char *name, const char *sqltype, const char *value, Bool_t numeric);
0076 
0077    TObjArray *TakeColInfos();
0078 
0079    Int_t GetNumColumns();
0080    const char *GetColumn(Int_t n);
0081    Bool_t IsNumeric(Int_t n);
0082 
0083    ClassDefOverride(TSQLTableData, 1); // Collection of columns data for single SQL table
0084 };
0085 
0086 //______________________________________________________________________
0087 
0088 class TSQLStructure : public TObject {
0089 protected:
0090    Bool_t CheckNormalClassPair(TSQLStructure *vers, TSQLStructure *info);
0091 
0092    Long64_t FindMaxObjectId();
0093    void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob = kFALSE);
0094    Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj = kTRUE);
0095    Bool_t StoreObjectInNormalForm(TSqlRegistry *reg);
0096    Bool_t StoreClassInNormalForm(TSqlRegistry *reg);
0097    Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns);
0098    Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs);
0099 
0100    Bool_t StoreTObject(TSqlRegistry *reg);
0101    Bool_t StoreTString(TSqlRegistry *reg);
0102    Bool_t RecognizeTString(const char *&value);
0103 
0104    TSQLStructure *fParent{nullptr}; //!
0105    Int_t fType{0};                  //!
0106    const void *fPointer{nullptr};   //!
0107    TString fValue;                  //!
0108    Int_t fArrayIndex{-1};           //!
0109    Int_t fRepeatCnt{0};             //!
0110    TObjArray fChilds;               //!
0111 
0112 public:
0113    TSQLStructure() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
0114    ~TSQLStructure() override;
0115 
0116    TSQLStructure *GetParent() const { return fParent; }
0117    void SetParent(TSQLStructure *p) { fParent = p; }
0118    Int_t NumChilds() const;
0119    TSQLStructure *GetChild(Int_t n) const;
0120 
0121    void SetType(Int_t typ) { fType = typ; }
0122    Int_t GetType() const { return fType; }
0123 
0124    // this part requried for writing to SQL tables
0125    void SetObjectRef(Long64_t refid, const TClass *cl);
0126    void SetObjectPointer(Long64_t ptrid);
0127    void SetVersion(const TClass *cl, Int_t version = -100);
0128    void SetClassStreamer(const TClass *cl);
0129    void SetStreamerInfo(const TStreamerInfo *info);
0130    void SetStreamerElement(const TStreamerElement *elem, Int_t number);
0131    void SetCustomClass(const TClass *cl, Version_t version);
0132    void SetCustomElement(TStreamerElement *elem);
0133    void SetValue(const char *value, const char *tname = nullptr);
0134    void SetArrayIndex(Int_t indx, Int_t cnt = 1);
0135    void SetArray(Int_t sz = -1);
0136    void ChangeValueOnly(const char *value);
0137 
0138    TClass *GetObjectClass() const;
0139    TClass *GetVersionClass() const;
0140    TStreamerInfo *GetStreamerInfo() const;
0141    TStreamerElement *GetElement() const;
0142    Int_t GetElementNumber() const;
0143    TClass *GetCustomClass() const;
0144    Version_t GetCustomClassVersion() const;
0145    Bool_t GetClassInfo(TClass *&cl, Version_t &version);
0146    const char *GetValueType() const;
0147    const char *GetValue() const;
0148    Int_t GetArrayIndex() const { return fArrayIndex; }
0149    Int_t GetRepeatCounter() const { return fRepeatCnt; }
0150 
0151    void Add(TSQLStructure *child);
0152    void AddVersion(const TClass *cl, Int_t version = -100);
0153    void AddValue(const char *value, const char *tname = nullptr);
0154    void ChildArrayIndex(Int_t index, Int_t cnt = 1);
0155 
0156    // this is part specially for reading of sql tables
0157 
0158    Long64_t DefineObjectId(Bool_t recursive = kTRUE);
0159 
0160    void SetObjectData(TSQLObjectData *objdata);
0161    void AddObjectData(TSQLObjectData *objdata);
0162    TSQLObjectData *GetObjectData(Bool_t search = false);
0163 
0164    void Print(Option_t *option = "") const override;
0165    void PrintLevel(Int_t level) const;
0166 
0167    Bool_t ConvertToTables(TSQLFile *f, Long64_t keyid, TObjArray *cmds);
0168 
0169    Int_t LocateElementColumn(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data);
0170 
0171    static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
0172    static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
0173    static Bool_t IsNumericType(Int_t typ);
0174    static const char *GetSimpleTypeName(Int_t typ);
0175    static TString MakeArrayIndex(TStreamerElement *elem, Int_t n);
0176    static Int_t DefineElementColumnType(TStreamerElement *elem, TSQLFile *f);
0177    static TString DefineElementColumnName(TStreamerElement *elem, TSQLFile *f, Int_t indx = 0);
0178    static void AddStrBrackets(TString &s, const char *quote);
0179 
0180    enum ESQLTypes {
0181       kSqlObject = 10001,
0182       kSqlPointer = 10002,
0183       kSqlVersion = 10003,
0184       kSqlStreamerInfo = 10004,
0185       kSqlClassStreamer = 10005,
0186       kSqlElement = 10006,
0187       kSqlValue = 10007,
0188       kSqlArray = 10008,
0189       kSqlObjectData = 10009,
0190       kSqlCustomClass = 10010,
0191       kSqlCustomElement = 10011
0192    };
0193 
0194    enum ESQLColumns {
0195       kColUnknown = 0,
0196       kColSimple = 1,
0197       kColSimpleArray = 2,
0198       kColParent = 3,
0199       kColObject = 4,
0200       kColObjectArray = 5,
0201       kColNormObject = 6,
0202       kColNormObjectArray = 7,
0203       kColObjectPtr = 8,
0204       kColTString = 9,
0205       kColRawData = 10
0206    };
0207 
0208    enum ESQLIdType { kIdTable = 0, kIdRawTable = 1, kIdColumn = 2 };
0209 
0210    ClassDefOverride(TSQLStructure, 1); // Table/structure description used internally by TBufferSQL.
0211 };
0212 
0213 // text constants, used in SQL I/O
0214 
0215 namespace sqlio {
0216 
0217 extern Long64_t atol64(const char *value);
0218 
0219 extern const Int_t Ids_NullPtr;
0220 extern const Int_t Ids_RootDir;
0221 extern const Int_t Ids_TSQLFile;
0222 extern const Int_t Ids_StreamerInfos;
0223 extern const Int_t Ids_FirstKey;
0224 extern const Int_t Ids_FirstObject;
0225 
0226 extern const char *ObjectRef;
0227 extern const char *ObjectRef_Arr;
0228 extern const char *ObjectPtr;
0229 extern const char *ObjectInst;
0230 extern const char *Version;
0231 extern const char *TObjectUniqueId;
0232 extern const char *TObjectBits;
0233 extern const char *TObjectProcessId;
0234 extern const char *TStringValue;
0235 extern const char *IndexSepar;
0236 extern const char *RawSuffix;
0237 extern const char *ParentSuffix;
0238 extern const char *ObjectSuffix;
0239 extern const char *PointerSuffix;
0240 extern const char *StrSuffix;
0241 extern const char *LongStrPrefix;
0242 
0243 extern const char *Array;
0244 extern const char *Bool;
0245 extern const char *Char;
0246 extern const char *Short;
0247 extern const char *Int;
0248 extern const char *Long;
0249 extern const char *Long64;
0250 extern const char *Float;
0251 extern const char *Double;
0252 extern const char *UChar;
0253 extern const char *UShort;
0254 extern const char *UInt;
0255 extern const char *ULong;
0256 extern const char *ULong64;
0257 extern const char *CharStar;
0258 extern const char *True;
0259 extern const char *False;
0260 
0261 extern const char *KeysTable;
0262 extern const char *KeysTableIndex;
0263 extern const char *KT_Name;
0264 extern const char *KT_Title;
0265 extern const char *KT_Datetime;
0266 extern const char *KT_Cycle;
0267 extern const char *KT_Class;
0268 
0269 extern const char *DT_Create;
0270 extern const char *DT_Modified;
0271 extern const char *DT_UUID;
0272 
0273 extern const char *ObjectsTable;
0274 extern const char *ObjectsTableIndex;
0275 extern const char *OT_Class;
0276 extern const char *OT_Version;
0277 
0278 extern const char *IdsTable;
0279 extern const char *IdsTableIndex;
0280 extern const char *IT_TableID;
0281 extern const char *IT_SubID;
0282 extern const char *IT_Type;
0283 extern const char *IT_FullName;
0284 extern const char *IT_SQLName;
0285 extern const char *IT_Info;
0286 
0287 extern const char *BT_Field;
0288 extern const char *BT_Value;
0289 
0290 extern const char *StringsTable;
0291 extern const char *ST_Value;
0292 
0293 extern const char *ConfigTable;
0294 extern const char *CT_Field;
0295 extern const char *CT_Value;
0296 
0297 extern const char *cfg_Version;
0298 extern const char *cfg_UseSufixes;
0299 extern const char *cfg_ArrayLimit;
0300 extern const char *cfg_TablesType;
0301 extern const char *cfg_UseTransactions;
0302 extern const char *cfg_UseIndexes;
0303 extern const char *cfg_LockingMode;
0304 extern const char *cfg_ModifyCounter;
0305 }
0306 
0307 #endif