Logo ROOT   6.12/06
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 
84 
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:
97 
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);
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;
147  TStreamerElement *GetElement() const;
148  Int_t GetElementNumber() const;
149  TClass *GetCustomClass() 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 
174 
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);
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,
192  kSqlElement = 10006,
193  kSqlValue = 10007,
194  kSqlArray = 10008,
195  kSqlObjectData = 10009,
198  };
199 
200  enum ESQLColumns {
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
void SetObjectData(TSQLObjectData *objdata)
set element to be used for object data
Describe Streamer information for one class version
Definition: TStreamerInfo.h:43
const char * GetValueType() const
return value type if structure is kSqlValue
TString fName
! name of the table column
Definition: TSQLStructure.h:44
const char * ConfigTable
static Int_t DefineElementColumnType(TStreamerElement *elem, TSQLFile *f)
defines which kind of column can be assigned for this element Possible cases kColSimple - basic data ...
An array of TObjects.
Definition: TObjArray.h:37
TSQLColumnData()
default constructor
Bool_t StoreTObject(TSqlRegistry *reg)
store data of TObject in special table workaround custom TObject streamer
const char * IdsTableIndex
TStreamerInfo * GetStreamerInfo() const
return TStreamerInfo* if type is kSqlStreamerInfo
long long Long64_t
Definition: RtypesCore.h:69
Long64_t FindMaxObjectId()
define maximum reference id, used for objects
static Bool_t IsNumericType(Int_t typ)
defines if value is numeric and not requires quotes when writing
short Version_t
Definition: RtypesCore.h:61
Version_t GetCustomClassVersion() const
return custom class version if strutures is kSqlCustomClass
void AddValue(const char *value, const char *tname=0)
Add child structure as value.
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
Bool_t GetClassInfo(TClass *&cl, Version_t &version)
provides class info if structure kSqlStreamerInfo or kSqlCustomClass
const char * cfg_UseTransactions
Int_t GetType() const
static TString MakeArrayIndex(TStreamerElement *elem, Int_t n)
produce string with complete index like [1][2][0]
Int_t GetElementNumber() const
returns number of TStremerElement in TStreamerInfo
const Int_t Ids_NullPtr
const char * CT_Value
Int_t GetNumColumns()
returns number of columns in provided set
const char * IndexSepar
TObjArray * fColInfos
! array with TSQLClassColumnInfo, used later for TSQLClassInfo
Definition: TSQLStructure.h:71
TClass * GetCustomClass() const
return element custom class if strutures is kSqlCustomClass
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
void SetVersion(const TClass *cl, Int_t version=-100)
set structure type as kSqlVersion
const char * cfg_LockingMode
TSQLStructure * GetChild(Int_t n) const
return child structure of index n
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
void SetObjectRef(Long64_t refid, const TClass *cl)
set structure type as kSqlObject
void SetValue(const char *value, const char *tname=0)
set structure type as kSqlValue
const char * DT_Create
const char * UShort
void SetParent(TSQLStructure *p)
const char * UInt
const char * IT_Type
Bool_t CheckNormalClassPair(TSQLStructure *vers, TSQLStructure *info)
check if pair of two element corresponds to start of object, stored in normal form ...
Int_t GetArrayIndex() const
const char * ParentSuffix
const char * cfg_UseIndexes
const char * GetValue() const
returns value for different structure kinds has different sense For kSqlVersion it version...
TObjArray * TakeColInfos()
take ownership over colinfos
void SetStreamerInfo(const TStreamerInfo *info)
set structure type as kSqlStreamerInfo
TSQLObjectData is used in TBufferSQL2 class in reading procedure.
void Add(TSQLStructure *child)
Add child structure.
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
static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TObject data in form, accepted by custom TObject streamer.
const char * True
void SetStreamerElement(const TStreamerElement *elem, Int_t number)
set structure type as kSqlElement
#define ClassDef(name, id)
Definition: Rtypes.h:320
const char * ObjectsTableIndex
Int_t NumChilds() const
number of child structures
TString fValue
! value of the table column
Definition: TSQLStructure.h:46
Bool_t RecognizeTString(const char *&value)
prove that structure contains TString data
const char * KT_Datetime
void ChildArrayIndex(Int_t index, Int_t cnt=1)
set array index for last child element if (cnt<=1) return;
This is hierarchical structure, which is created when data is written by TBufferSQL2.
Definition: TSQLStructure.h:94
const void * fPointer
const char * KT_Cycle
Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns)
tries to store element data in column
virtual void Print(Option_t *option="") const
print content of complete structure
TStreamerElement * GetElement() const
return TStremerElement* if type is kSqlElement
const char * cfg_TablesType
Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs)
tries to write array of objects as list of object references in streamer table, while objects itself ...
const char * ST_Value
const char * KT_Title
const char * UChar
const char * Float
Bool_t StoreTString(TSqlRegistry *reg)
store data of TString in special table it is required when TString stored as pointer and reference to...
const Int_t Ids_TSQLFile
Int_t LocateElementColumn(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data)
find column in TSQLObjectData object, which correspond to current element
const char * OT_Class
virtual ~TSQLStructure()
destructor
static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TString data in form, accepted by custom TString streamer.
TObjArray fChilds
TSQLObjectData * GetObjectData(Bool_t search=false)
searches for objects data
static TString DefineElementColumnName(TStreamerElement *elem, TSQLFile *f, Int_t indx=0)
returns name of the column in class table for that element
const char * KeysTableIndex
Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj=kTRUE)
convert object data to sql statements if normal (column-wise) representation is not possible...
void AddColumn(const char *name, Long64_t value)
Add INT column to list of columns.
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
void SetCustomClass(const TClass *cl, Version_t version)
set structure type as kSqlCustomClass
const char * IT_Info
const char * DT_Modified
void ChangeValueOnly(const char *value)
change value of this structure used as "workaround" to keep object id in kSqlElement node ...
TString DefineSQLName(const char *fullname)
produce suitable name for column, taking into account length limitation
const char * ObjectSuffix
const char * ULong
const char * LongStrPrefix
void SetArray(Int_t sz=-1)
Set structure as array element.
Bool_t HasSQLName(const char *sqlname)
checks if columns list already has that sql name
const char * Double
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
void AddObjectData(TSQLObjectData *objdata)
add element with pointer to object data
const char * KeysTable
TSQLTableData(TSQLFile *f=0, TSQLClassInfo *info=0)
normal constructor
const char * OT_Version
const char * TObjectUniqueId
const char * ObjectRef_Arr
virtual ~TSQLColumnData()
TSQLColumnData destructor.
const char * cfg_Version
void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob=kFALSE)
perform conversion of structure to sql statements first tries convert it to normal form if fails...
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t IsNumeric(Int_t n)
identifies if column has numeric value
void SetCustomElement(TStreamerElement *elem)
set structure type as kSqlCustomElement
const char * TObjectBits
Converts data to SQL statements or read data from SQL tables.
Definition: TBufferSQL2.h:29
TClass * GetObjectClass() const
return object class if type kSqlObject
const Int_t Ids_FirstObject
virtual const char * GetName() const
Returns name of object.
Definition: TSQLStructure.h:55
void SetObjectPointer(Long64_t ptrid)
set structure type as kSqlPointer
void AddVersion(const TClass *cl, Int_t version=-100)
add child as version
const char * BT_Field
TClass * GetVersionClass() const
return class for version tag if type is kSqlVersion
static const char * GetSimpleTypeName(Int_t typ)
provides name for basic types used as suffix for column name or field suffix in raw table ...
const char * RawSuffix
const Int_t Ids_StreamerInfos
const char * TObjectProcessId
const char * DT_UUID
const char * GetColumn(Int_t n)
return column value
const char * GetValue() const
Definition: TSQLStructure.h:57
const char * ObjectPtr
static void AddStrBrackets(TString &s, const char *quote)
adds quotes around string value and replaces some special symbols
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
Bool_t StoreClassInNormalForm(TSqlRegistry *reg)
produces data for complete class table where not possible, raw data for some elements are created ...
const char * PointerSuffix
const char * ObjectsTable
Long64_t DefineObjectId(Bool_t recursive=kTRUE)
defines current object id, to which this structure belong make life complicated, because some objects...
const char * BT_Value
Bool_t StoreObjectInNormalForm(TSqlRegistry *reg)
this function verify object child elements and calls transformation to class table ...
Bool_t ConvertToTables(TSQLFile *f, Long64_t keyid, TObjArray *cmds)
Convert structure to sql statements This function is called immidiately after TBufferSQL2 produces th...
TSQLStructure * fParent
Int_t GetRepeatCounter() const
TSQLFile * fFile
!
Definition: TSQLStructure.h:68
void PrintLevel(Int_t level) const
print content of current structure
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
virtual ~TSQLTableData()
destructor
void SetArrayIndex(Int_t indx, Int_t cnt=1)
set array index for this structure
const char * Short
const char * IT_SubID
const char * cfg_ModifyCounter
void SetClassStreamer(const TClass *cl)
set structure type as kSqlClassStreamer