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