Logo ROOT   6.12/07
Reference Guide
TSQLStructure.h
Go to the documentation of this file.
1 // @(#)root/sql:$Id$
2 // Author: Sergey Linev 20/11/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TSQLStructure
13 #define ROOT_TSQLStructure
14 
15 #include "TNamed.h"
16 
17 #include "TObjArray.h"
18 
19 #include "TAttAxis.h"
20 
21 #ifdef Bool
22 #undef Bool
23 #endif
24 #ifdef True
25 #undef True
26 #endif
27 #ifdef False
28 #undef False
29 #endif
30 
31 class TStreamerInfo;
32 class TStreamerInfo;
33 class TStreamerElement;
34 class TSQLFile;
35 class TSqlRegistry;
36 class TSqlRawBuffer;
37 class TSQLObjectData;
38 class TSQLClassInfo;
39 class TBufferSQL2;
40 
41 class TSQLColumnData : public TObject {
42 
43 protected:
44  TString fName; ///<! name of the table column
45  TString fType; ///<! type of the table column
46  TString fValue; ///<! value of the table column
47  Bool_t fNumeric; ///<! for numeric quotes (double quotes) are not required
48 public:
50  TSQLColumnData(const char *name, const char *sqltype, const char *value, Bool_t numeric);
51 
52  TSQLColumnData(const char *name, Long64_t value);
53  virtual ~TSQLColumnData();
54 
55  virtual const char *GetName() const { return fName.Data(); }
56  const char *GetType() const { return fType.Data(); }
57  const char *GetValue() const { return fValue.Data(); }
58  Bool_t IsNumeric() const { return fNumeric; }
59 
60  ClassDef(TSQLColumnData, 1); // Single SQL column data.
61 };
62 
63 //______________________________________________________________________
64 
65 class TSQLTableData : public TObject {
66 
67 protected:
68  TSQLFile *fFile; ///<!
70  TObjArray fColumns; ///<! collection of columns
71  TObjArray *fColInfos; ///<! array with TSQLClassColumnInfo, used later for TSQLClassInfo
72 
73  TString DefineSQLName(const char *fullname);
74  Bool_t HasSQLName(const char *sqlname);
75 
76 public:
77  TSQLTableData(TSQLFile *f = 0, TSQLClassInfo *info = 0);
78  virtual ~TSQLTableData();
79 
80  void AddColumn(const char *name, Long64_t value);
81  void AddColumn(const char *name, const char *sqltype, const char *value, Bool_t numeric);
82 
83  TObjArray *TakeColInfos();
84 
85  Int_t GetNumColumns();
86  const char *GetColumn(Int_t n);
88 
89  ClassDef(TSQLTableData, 1); // Collection of columns data for single SQL table
90 };
91 
92 //______________________________________________________________________
93 
94 class TSQLStructure : public TObject {
95 protected:
96  Bool_t CheckNormalClassPair(TSQLStructure *vers, TSQLStructure *info);
97 
98  Long64_t FindMaxObjectId();
99  void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob = kFALSE);
100  Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj = kTRUE);
101  Bool_t StoreObjectInNormalForm(TSqlRegistry *reg);
102  Bool_t StoreClassInNormalForm(TSqlRegistry *reg);
103  Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns);
104  Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs);
105 
106  Bool_t StoreTObject(TSqlRegistry *reg);
107  Bool_t StoreTString(TSqlRegistry *reg);
108  Bool_t RecognizeTString(const char *&value);
109 
112  const void *fPointer; //!
117 
118 public:
119  TSQLStructure();
120  virtual ~TSQLStructure();
121 
122  TSQLStructure *GetParent() const { return fParent; }
123  void SetParent(TSQLStructure *p) { fParent = p; }
124  Int_t NumChilds() const;
125  TSQLStructure *GetChild(Int_t n) const;
126 
127  void SetType(Int_t typ) { fType = typ; }
128  Int_t GetType() const { return fType; }
129 
130  // this part requried for writing to SQL tables
131  void SetObjectRef(Long64_t refid, const TClass *cl);
132  void SetObjectPointer(Long64_t ptrid);
133  void SetVersion(const TClass *cl, Int_t version = -100);
134  void SetClassStreamer(const TClass *cl);
135  void SetStreamerInfo(const TStreamerInfo *info);
136  void SetStreamerElement(const TStreamerElement *elem, Int_t number);
137  void SetCustomClass(const TClass *cl, Version_t version);
138  void SetCustomElement(TStreamerElement *elem);
139  void SetValue(const char *value, const char *tname = 0);
140  void SetArrayIndex(Int_t indx, Int_t cnt = 1);
141  void SetArray(Int_t sz = -1);
142  void ChangeValueOnly(const char *value);
143 
144  TClass *GetObjectClass() const;
145  TClass *GetVersionClass() const;
146  TStreamerInfo *GetStreamerInfo() const;
147  TStreamerElement *GetElement() const;
148  Int_t GetElementNumber() const;
149  TClass *GetCustomClass() const;
150  Version_t GetCustomClassVersion() const;
151  Bool_t GetClassInfo(TClass *&cl, Version_t &version);
152  const char *GetValueType() const;
153  const char *GetValue() const;
154  Int_t GetArrayIndex() const { return fArrayIndex; }
155  Int_t GetRepeatCounter() const { return fRepeatCnt; }
156 
157  void Add(TSQLStructure *child);
158  void AddVersion(const TClass *cl, Int_t version = -100);
159  void AddValue(const char *value, const char *tname = 0);
160  void ChildArrayIndex(Int_t index, Int_t cnt = 1);
161 
162  // this is part specially for reading of sql tables
163 
164  Long64_t DefineObjectId(Bool_t recursive = kTRUE);
165 
166  void SetObjectData(TSQLObjectData *objdata);
167  void AddObjectData(TSQLObjectData *objdata);
168  TSQLObjectData *GetObjectData(Bool_t search = false);
169 
170  virtual void Print(Option_t *option = "") const;
171  void PrintLevel(Int_t level) const;
172 
173  Bool_t ConvertToTables(TSQLFile *f, Long64_t keyid, TObjArray *cmds);
174 
175  Int_t LocateElementColumn(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data);
176 
177  static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
178  static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
179  static Bool_t IsNumericType(Int_t typ);
180  static const char *GetSimpleTypeName(Int_t typ);
181  static TString MakeArrayIndex(TStreamerElement *elem, Int_t n);
182  static Int_t DefineElementColumnType(TStreamerElement *elem, TSQLFile *f);
183  static TString DefineElementColumnName(TStreamerElement *elem, TSQLFile *f, Int_t indx = 0);
184  static void AddStrBrackets(TString &s, const char *quote);
185 
186  enum ESQLTypes {
187  kSqlObject = 10001,
188  kSqlPointer = 10002,
189  kSqlVersion = 10003,
190  kSqlStreamerInfo = 10004,
191  kSqlClassStreamer = 10005,
192  kSqlElement = 10006,
193  kSqlValue = 10007,
194  kSqlArray = 10008,
195  kSqlObjectData = 10009,
196  kSqlCustomClass = 10010,
197  kSqlCustomElement = 10011
198  };
199 
200  enum ESQLColumns {
201  kColUnknown = 0,
202  kColSimple = 1,
203  kColSimpleArray = 2,
204  kColParent = 3,
205  kColObject = 4,
206  kColObjectArray = 5,
207  kColNormObject = 6,
208  kColNormObjectArray = 7,
209  kColObjectPtr = 8,
210  kColTString = 9,
211  kColRawData = 10
212  };
213 
214  enum ESQLIdType { kIdTable = 0, kIdRawTable = 1, kIdColumn = 2 };
215 
216  ClassDef(TSQLStructure, 1); // Table/structure description used internally by TBufferSQL.
217 };
218 
219 // text constants, used in SQL I/O
220 
221 namespace sqlio {
222 
223 extern Long64_t atol64(const char *value);
224 
225 extern const Int_t Ids_NullPtr;
226 extern const Int_t Ids_RootDir;
227 extern const Int_t Ids_TSQLFile;
228 extern const Int_t Ids_StreamerInfos;
229 extern const Int_t Ids_FirstKey;
230 extern const Int_t Ids_FirstObject;
231 
232 extern const char *ObjectRef;
233 extern const char *ObjectRef_Arr;
234 extern const char *ObjectPtr;
235 extern const char *ObjectInst;
236 extern const char *Version;
237 extern const char *TObjectUniqueId;
238 extern const char *TObjectBits;
239 extern const char *TObjectProcessId;
240 extern const char *TStringValue;
241 extern const char *IndexSepar;
242 extern const char *RawSuffix;
243 extern const char *ParentSuffix;
244 extern const char *ObjectSuffix;
245 extern const char *PointerSuffix;
246 extern const char *StrSuffix;
247 extern const char *LongStrPrefix;
248 
249 extern const char *Array;
250 extern const char *Bool;
251 extern const char *Char;
252 extern const char *Short;
253 extern const char *Int;
254 extern const char *Long;
255 extern const char *Long64;
256 extern const char *Float;
257 extern const char *Double;
258 extern const char *UChar;
259 extern const char *UShort;
260 extern const char *UInt;
261 extern const char *ULong;
262 extern const char *ULong64;
263 extern const char *CharStar;
264 extern const char *True;
265 extern const char *False;
266 
267 extern const char *KeysTable;
268 extern const char *KeysTableIndex;
269 extern const char *KT_Name;
270 extern const char *KT_Title;
271 extern const char *KT_Datetime;
272 extern const char *KT_Cycle;
273 extern const char *KT_Class;
274 
275 extern const char *DT_Create;
276 extern const char *DT_Modified;
277 extern const char *DT_UUID;
278 
279 extern const char *ObjectsTable;
280 extern const char *ObjectsTableIndex;
281 extern const char *OT_Class;
282 extern const char *OT_Version;
283 
284 extern const char *IdsTable;
285 extern const char *IdsTableIndex;
286 extern const char *IT_TableID;
287 extern const char *IT_SubID;
288 extern const char *IT_Type;
289 extern const char *IT_FullName;
290 extern const char *IT_SQLName;
291 extern const char *IT_Info;
292 
293 extern const char *BT_Field;
294 extern const char *BT_Value;
295 
296 extern const char *StringsTable;
297 extern const char *ST_Value;
298 
299 extern const char *ConfigTable;
300 extern const char *CT_Field;
301 extern const char *CT_Value;
302 
303 extern const char *cfg_Version;
304 extern const char *cfg_UseSufixes;
305 extern const char *cfg_ArrayLimit;
306 extern const char *cfg_TablesType;
307 extern const char *cfg_UseTransactions;
308 extern const char *cfg_UseIndexes;
309 extern const char *cfg_LockingMode;
310 extern const char *cfg_ModifyCounter;
311 }
312 
313 #endif
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
TString fName
! name of the table column
Definition: TSQLStructure.h:44
const char * ConfigTable
An array of TObjects.
Definition: TObjArray.h:37
TSQLColumnData()
default constructor
const char * IdsTableIndex
long long Long64_t
Definition: RtypesCore.h:69
short Version_t
Definition: RtypesCore.h:61
const char * Int
const char Option_t
Definition: RtypesCore.h:62
Bool_t fNumeric
! for numeric quotes (double quotes) are not required
Definition: TSQLStructure.h:47
RooCmdArg PrintLevel(Int_t code)
const char * cfg_UseTransactions
Int_t GetType() const
const Int_t Ids_NullPtr
const char * CT_Value
const char * IndexSepar
TObjArray * fColInfos
! array with TSQLClassColumnInfo, used later for TSQLClassInfo
Definition: TSQLStructure.h:71
Contains information about tables specific to one class and version.
Definition: TSQLClassInfo.h:42
const char * IT_SQLName
const char * Long
Basic string class.
Definition: TString.h:125
const char * cfg_LockingMode
int Int_t
Definition: RtypesCore.h:41
const char * ObjectInst
bool Bool_t
Definition: RtypesCore.h:59
const char * IdsTable
const char * Char
const char * Version
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
const char * DT_Create
const char * UShort
void SetParent(TSQLStructure *p)
const char * UInt
const char * IT_Type
Int_t GetArrayIndex() const
const char * ParentSuffix
const char * cfg_UseIndexes
TSQLObjectData is used in TBufferSQL2 class in reading procedure.
const char * StringsTable
Long64_t atol64(const char *value)
const char * TStringValue
const char * StrSuffix
const char * IT_FullName
TSQLClassInfo * fInfo
!
Definition: TSQLStructure.h:69
const char * True
#define ClassDef(name, id)
Definition: Rtypes.h:320
const char * ObjectsTableIndex
TString fValue
! value of the table column
Definition: TSQLStructure.h:46
const char * KT_Datetime
This is hierarchical structure, which is created when data is written by TBufferSQL2.
Definition: TSQLStructure.h:94
const void * fPointer
const char * KT_Cycle
const char * cfg_TablesType
const char * ST_Value
const char * KT_Title
const char * UChar
const char * Float
const Int_t Ids_TSQLFile
const char * OT_Class
TObjArray fChilds
const char * KeysTableIndex
const char * KT_Class
const char * GetType() const
Definition: TSQLStructure.h:56
Access an SQL db via the TFile interface.
Definition: TSQLFile.h:30
const char * Array
const char * IT_Info
const char * DT_Modified
const char * ObjectSuffix
const char * ULong
const char * LongStrPrefix
const char * Double
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
const char * KeysTable
const char * OT_Version
const char * TObjectUniqueId
const char * ObjectRef_Arr
virtual ~TSQLColumnData()
TSQLColumnData destructor.
const char * cfg_Version
const Bool_t kFALSE
Definition: RtypesCore.h:88
const char * TObjectBits
Converts data to SQL statements or read data from SQL tables.
Definition: TBufferSQL2.h:29
const Int_t Ids_FirstObject
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
Definition: THist.hxx:308
virtual const char * GetName() const
Returns name of object.
Definition: TSQLStructure.h:55
const char * BT_Field
const char * RawSuffix
const Int_t Ids_StreamerInfos
const char * TObjectProcessId
const char * DT_UUID
const char * GetValue() const
Definition: TSQLStructure.h:57
const char * ObjectPtr
static constexpr double s
const char * KT_Name
void SetType(Int_t typ)
const char * ULong64
const char * CT_Field
const char * cfg_ArrayLimit
const Int_t Ids_FirstKey
const char * CharStar
const char * Bool
Mother of all ROOT objects.
Definition: TObject.h:37
TString fType
! type of the table column
Definition: TSQLStructure.h:45
Bool_t IsNumeric() const
Definition: TSQLStructure.h:58
const Int_t Ids_RootDir
const char * PointerSuffix
const char * ObjectsTable
const char * BT_Value
TSQLStructure * fParent
Int_t GetRepeatCounter() const
TSQLFile * fFile
!
Definition: TSQLStructure.h:68
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char * ObjectRef
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
const char * cnt
Definition: TXMLSetup.cxx:74
const char * Long64
TSQLStructure * GetParent() const
const char * IT_TableID
const char * False
TObjArray fColumns
! collection of columns
Definition: TSQLStructure.h:70
const char * cfg_UseSufixes
const char * Data() const
Definition: TString.h:345
const char * Short
const char * IT_SubID
const char * cfg_ModifyCounter