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